Codeforces Round #392 (Div. 2) A、B之我是zz

来源:互联网 发布:qq记牌器源码 编辑:程序博客网 时间:2024/05/17 05:10

A. Holiday Of Equality
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.

Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).

You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them.

Input

The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom.

The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen.

Output

In the only line print the integer S — the minimum number of burles which are had to spend.

Examples
input
50 1 2 3 4
output
10
input
51 1 0 1 1
output
1
input
31 3 1
output
4
input
112
output
0
Note

In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.

In the second example it is enough to give one burle to the third citizen.

In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.

In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles.

#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#include <cmath>using namespace std;const int maxn = 1e6;long long save[maxn];int main(){    int n;    long long ans=0;    scanf("%d",&n);    int i;    long long maxx = -1;    for(i=1;i<=n;i++){        scanf("%I64d",&save[i]);        maxx = max(maxx,save[i]);    }    for(i=1;i<=n;i++){        ans += maxx-save[i];    }    printf("%I64d\n",ans);    return 0;}
B. Blown Garland
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Nothing is eternal in the world, Kostya understood it on the 7-th of January when he saw partially dead four-color garland.

Now he has a goal to replace dead light bulbs, however he doesn't know how many light bulbs for each color are required. It is guaranteed that for each of four colors at least one light is working.

It is known that the garland contains light bulbs of four colors: red, blue, yellow and green. The garland is made as follows: if you take any four consecutive light bulbs then there will not be light bulbs with the same color among them. For example, the garland can look like "RYBGRYBGRY", "YBGRYBGRYBG", "BGRYB", but can not look like "BGRYG", "YBGRYBYGR" or "BGYBGY". Letters denote colors: 'R' — red, 'B' — blue, 'Y' — yellow, 'G' — green.

Using the information that for each color at least one light bulb still works count the number of dead light bulbs of each four colors.

Input

The first and the only line contains the string s (4 ≤ |s| ≤ 100), which describes the garland, the i-th symbol of which describes the color of the i-th light bulb in the order from the beginning of garland:

  • 'R' — the light bulb is red,
  • 'B' — the light bulb is blue,
  • 'Y' — the light bulb is yellow,
  • 'G' — the light bulb is green,
  • '!' — the light bulb is dead.

The string s can not contain other symbols except those five which were described.

It is guaranteed that in the given string at least once there is each of four letters 'R', 'B', 'Y' and 'G'.

It is guaranteed that the string s is correct garland with some blown light bulbs, it means that for example the line "GRBY!!!B" can not be in the input data.

Output

In the only line print four integers kr, kb, ky, kg — the number of dead light bulbs of red, blue, yellow and green colors accordingly.

Examples
input
RYBGRYBGR
output
0 0 0 0
input
!RGYB
output
0 1 0 0
input
!!!!YGRB
output
1 1 1 1
input
!GB!RG!Y!
output
2 1 1 0
Note

In the first example there are no dead light bulbs.

In the second example it is obvious that one blue bulb is blown, because it could not be light bulbs of other colors on its place according to the statements.


#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#include <cmath>#include <map>using namespace std;string save[30]={"RBYG","RBGY","RYBG","RYGB","RGBY","RGYB","BRYG","BRGY","BYRG","BYGR","BGRY","BGYR","YRBG","YRGB","YBGR","YBRG","YGRB","YGBR","GRBY","GRYB","GBRY","GBYR","GYRB","GYBR"};string ori[30];void init(){    int i,j=-1,k;    string now;    for(i=1;i<=24;i++){        now.clear();        for(j=1;j<=35;j++){            now += save[i-1];        }        ori[i] =now;    }}string in;int len;int check(int x){    int i,j;    bool flag = true;    for(i=0;i<10;i++){        for(j=0;j<len;j++){            if(in[j]!='!'&&in[j]!=ori[x][i+j]){                flag = false;            }        }        if(flag){            return i;        }    }    return -1;}map<char,int> change;int main(){    init();    int i,j;    cin>>in;    change.clear();    len = in.length();    int add;    for(i=1;i<=24;i++){        add = check(i);        if(add!=-1){            for(j=0;j<len;j++){                if(in[j]=='!'){                    change[ori[i][add+j]]++;                                    }            }            printf("%d %d %d %d\n",change['R'],change['B'],change['Y'],change['G']);            return 0;        }    }    return 0;}








0 0