【A】

A. Brain's Photos
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.

As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).

Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour!

As soon as Brain is a photographer not programmer now, he asks you to help him determine for asingle photo whether it is colored or black-and-white.

Photo can be represented as a matrix sized n × m, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only6 colors:

  • 'C' (cyan)
  • 'M' (magenta)
  • 'Y' (yellow)
  • 'W' (white)
  • 'G' (grey)
  • 'B' (black)

The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored.

Input

The first line of the input contains two integers n andm (1 ≤ n, m ≤ 100) — the number of photo pixel matrix rows and columns respectively.

Then n lines describing matrix rows follow. Each of them containsm space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'.

Output

Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.

Examples
Input
2 2
C M
Y Y
Output
#Color
Input
3 2
W W
W W
B B
Output
#Black&White
Input
1 1
W
Output
#Black&White
【解题方法】判断一下是否有‘Y’,'M','C'即可。

【AC 代码】

#include <bits/stdc++.h>
using namespace std;
char s[5];
int main()
{
    int n,m;
    cin>>n>>m;
    bool flag=true;
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            scanf("%s",s);
            if(s[0]=='Y'||s[0]=='M'||s[0]=='C') flag=false;
        }
    }
    if(!flag) puts("#Color");
    else puts("#Black&White");
}


【B】
B. Bakery
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Masha wants to open her own bakery and bake muffins in one of the n cities numbered from 1 to n. There are m bidirectional roads, each of whose connects some pair of cities.

To bake muffins in her bakery, Masha needs to establish flour supply from some storage. There are onlyk storages, located in different cities numbereda1, a2, ..., ak.

Unforunately the law of the country Masha lives in prohibits opening bakery in any of the cities which has storage located in it. She can open it only in one of anothern - k cities, and, of course, flour delivery should be paid — for every kilometer of path between storage and bakery Masha should pay1 ruble.

Formally, Masha will pay x roubles, if she will open the bakery in some cityb (ai ≠ b for every1 ≤ i ≤ k) and choose a storage in some citys (s = aj for some1 ≤ j ≤ k) and b and s are connected by some path of roads of summary lengthx (if there are more than one path, Masha is able to choose which of them should be used).

Masha is very thrifty and rational. She is interested in a city, where she can open her bakery (and choose one ofk storages and one of the paths between city with bakery and city with storage) and pay minimum possible amount of rubles for flour delivery. Please help Masha find this amount.

Input

The first line of the input contains three integers n,m and k (1 ≤ n, m ≤ 105,0 ≤ k ≤ n) — the number of cities in country Masha lives in, the number of roads between them and the number of flour storages respectively.

Then m lines follow. Each of them contains three integersu, v andl (1 ≤ u, v ≤ n,1 ≤ l ≤ 109,u ≠ v) meaning that there is a road between citiesu and v of length ofl kilometers .

If k > 0, then the last line of the input containsk distinct integers a1, a2, ..., ak (1 ≤ ai ≤ n) — the number of cities having flour storage located in. If k = 0 then this lineis not presented in the input.

Output

Print the minimum possible amount of rubles Masha should pay for flour delivery in the only line.

If the bakery can not be opened (while satisfying conditions) in any of the n cities, print  - 1 in the only line.

Examples
Input
5 4 2
1 2 5
1 2 3
2 3 4
1 4 10
1 5
Output
3
Input
3 1 1
1 2 3
3
Output
-1
Note

Image illustrates the first sample case. Cities with storage located in and the road representing the answer are darkened.

【解题方法】题读清楚之后,就知道是在每个没有面粉店的城市选择一个最近的可以运送面粉的城市的距离,随便搞搞就好了。

【AC 代码】

#include<bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn =2e5+7;
int head[maxn],tot,vis[maxn];

struct node
{
    int nxt,ed,len;
}E[2*maxn];
void add(int x,int y,int len)
{
    E[tot].ed=y;
    E[tot].nxt=head[x];
    E[tot].len=len;
    head[x]=tot++;
}
int solve(int x)
{
    int ans=inf;
    for(int i=head[x];~i;i=E[i].nxt){
        int ed=E[i].ed;
        if(vis[ed]==0){
            ans=min(ans,E[i].len);
        }
    }
    return ans;
}
int a[maxn];
int main()
{
    int n,m,k;
    int u,v,w;
    scanf("%d%d%d",&n,&m,&k);
    memset(head,-1,sizeof(head));
    for(int i=0;i<m;i++){
        scanf("%d%d%d",&u,&v,&w);
        add(u,v,w);
        add(v,u,w);
    }
    int ans=inf;
    for(int i=0;i<k;i++){
        scanf("%d",&a[i]);
        vis[a[i]]=1;
    }
    for(int i=0;i<k;i++){
        ans=min(ans,solve(a[i]));
    }
    if(ans==inf) ans=-1;
    cout<<ans<<endl;
}

【C】
C. Pythagorean Triples
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples.

For example, triples (3, 4, 5), (5, 12, 13) and (6, 8, 10) are Pythagorean triples.

Here Katya wondered if she can specify the length of some side of right triangle and find any Pythagorean triple corresponding to such length? Note that the side which length is specified can be a cathetus as well as hypotenuse.

Katya had no problems with completing this task. Will you do the same?

Input

The only line of the input contains single integer n (1 ≤ n ≤ 109) — the length of some side of a right triangle.

Output

Print two integers m and k (1 ≤ m, k ≤ 1018), such thatn, m andk form a Pythagorean triple, in the only line.

In case if there is no any Pythagorean triple containing integer n, print  - 1 in the only line. If there are many answers, print any of them.

Examples
Input
3
Output
4 5
Input
6
Output
8 10
Input
1
Output
-1
Input
17
Output
144 145
Input
67
Output
2244 2245
【解题方法】比赛时候,我看着样例直接猜了结论。后来才知道这题是有套路的,一种就是我猜的那种,偶数的话应该后面两个数差2,奇数差1,然后解个方程就好啦。
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,a,b;
    cin>>n;
    if(n%2==0){
        a=(n*n-4)/4;
        if(a<=0){
            puts("-1");
        }else{
            printf("%lld %lld\n",a,a+2);
        }
    }else{
        a=(n*n-1)/2;
        if(a<=0) puts("-1");
        else printf("%lld %lld\n",a,a+1);
    }
}

【D】
D. Persistent Bookcase
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

Recently in school Alina has learned what are the persistent data structures: they are data structures that always preserves the previous version of itself and access to it when it is modified.

After reaching home Alina decided to invent her own persistent data structure. Inventing didn't take long: there is a bookcase right behind her bed. Alina thinks that the bookcase is a good choice for a persistent data structure. Initially the bookcase is empty, thus there is no book at any position at any shelf.

The bookcase consists of n shelves, and each shelf has exactlym positions for books at it. Alina enumerates shelves by integers from1 to n and positions at shelves — from1 to m. Initially the bookcase is empty, thus there is no book at any position at any shelf in it.

Alina wrote down q operations, which will be consecutively applied to the bookcase. Each of the operations has one of four types:

  • 1 i j — Place a book at position j at shelfi if there is no book at it.
  • 2 i j — Remove the book from position j at shelfi if there is a book at it.
  • 3 i — Invert book placing at shelfi. This means that from every position at shelfi which has a book at it, the book should be removed, and at every position at shelfi which has not book at it, a book should be placed.
  • 4 k — Return the books in the bookcase in a state they were after applyingk-th operation. In particular, k = 0 means that the bookcase should be in initial state, thus every book in the bookcase should be removed from its position.

After applying each of operation Alina is interested in the number of books in the bookcase. Alina got 'A' in the school and had no problem finding this values. Will you do so?

Input

The first line of the input contains three integers n,m and q (1 ≤ n, m ≤ 103,1 ≤ q ≤ 105) — the bookcase dimensions and the number of operations respectively.

The next q lines describes operations in chronological order —i-th of them describes i-th operation in one of the four formats described in the statement.

It is guaranteed that shelf indices and position indices are correct, and in each of fourth-type operation the numberk corresponds to some operation before it or equals to0.

Output

For each operation, print the number of books in the bookcase after applying it in a separate line. The answers should be printed in chronological order.

Examples
Input
2 3 3
1 1 1
3 2
4 0
Output
1
4
0
Input
4 2 6
3 2
2 2 2
3 3
3 2
2 2 2
3 2
Output
2
1
3
3
2
4
Input
2 2 2
3 2
2 2 1
Output
2
1
【解题方法】一直以为这题要可持久化过,赛场上也没写出来。早上看卿学姐博客才知道也可以dfs+bitset来搞一下,复杂度O(n*q),这题是完全可以过去了。bitset没怎么用着,几乎照搬代码了,我实在是太弱了,要继续加油。(Trick&&吐槽)出不了D,我看来怎么也上不了1900了,雾。

【AC 代码】

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
int n,m,q;
vector<int>E[maxn];
int op[maxn],a[maxn],b[maxn];
int ans[maxn];
bitset<1001>B[1001];
bitset<1001>C;
void dfs(int x)
{
    if(x==0){
        for(int i=0; i<E[x].size(); i++){
            ans[E[x][i]]=ans[x];
            dfs(E[x][i]);
        }
    }
    if(op[x]==1){
        int mark=0;
        if(!B[a[x]][b[x]]){
            mark = 1;
            ans[x]++;
            B[a[x]][b[x]]=1;
        }
        for(int i=0; i<E[x].size(); i++){
            ans[E[x][i]]=ans[x];
            dfs(E[x][i]);
        }
        if(mark) B[a[x]][b[x]]=0;
    }
    if(op[x]==2){
        int mark=0;
        if(B[a[x]][b[x]]){
            mark = 1;
            ans[x]--;
            B[a[x]][b[x]]=0;
        }
        for(int i=0; i<E[x].size(); i++){
            ans[E[x][i]]=ans[x];
            dfs(E[x][i]);
        }
        if(mark) B[a[x]][b[x]]=1;
    }
    if(op[x]==3){
        ans[x] = ans[x]-B[a[x]].count();
        B[a[x]]^=C;
        ans[x] = ans[x]+B[a[x]].count();
        for(int i=0; i<E[x].size(); i++){
            ans[E[x][i]]=ans[x];
            dfs(E[x][i]);
        }
        B[a[x]]^=C;
    }
    if(op[x]==4){
        for(int i=0; i<E[x].size(); i++){
            ans[E[x][i]]=ans[x];
            dfs(E[x][i]);
        }
    }
}
int main()
{
    cin>>n>>m>>q;
    for(int i=1; i<=m; i++) C[i]=1;
    for(int i=1; i<=q; i++) E[i].clear();
    for(int i=1; i<=q; i++){
        scanf("%d",&op[i]);
        if(op[i]==1) cin>>a[i]>>b[i];
        if(op[i]==2) cin>>a[i]>>b[i];
        if(op[i]==3) cin>>a[i];
        if(op[i]==4) cin>>a[i],E[a[i]].push_back(i);
        else E[i-1].push_back(i);
    }
    dfs(0);
    for(int i=1; i<=q; i++) cout<<ans[i]<<endl;
    return 0;
}