题目链接:​​点击打开链接​


A. Holiday Of Equality



time limit per test



memory limit per test



input



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.

n citizens, the welfare of each of them is estimated as the integer in ai

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



n (1 ≤ n ≤ 100) — the number of citizens in the kingdom.

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


Output



S


Examples



input



5 0 1 2 3 4



output



10



input



5 1 1 0 1 1



output



1



input



3 1 3 1



output



4



input



1 12



output



0


Note



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.

3.

12



大意:问国王为了使每个公民得到公平的对待,需要分发的最小货币量

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
int main()
{
while(~scanf("%d",&n))
{
int mmax=0,sum=0;
for(int i=1;i<=n;i++)
{
int x;
scanf("%d",&x);
sum+=x;
mmax=max(x,mmax);
}
printf("%d\n",n*mmax-sum);
}
return 0;
}


题目链接:

​点击打开链接​


B. Blown Garland



time limit per test



memory limit per test



input



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.

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



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.

s

R', 'B', 'Y' and 'G'.

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



kr, kb, ky, kg



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.






比赛的时候没读懂题目意思,尴尬

大意:给你一串灯泡有四种颜色、“ !” 是不会亮的灯泡,要求任意相邻的四个灯泡不能出现同样颜色的灯泡,现在要将不会亮的灯泡替换掉,问最少需要四种颜色的灯泡各多少个


思路:模拟一下就可以知道相同颜色的灯泡都是间隔一样的,且周期为 4

#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;
char str[110];
int main()
{
while(~scanf("%s",str))
{
int r,b,y,g;
int ans[4]={0};
for(int i=0;str[i];i++)
{
if(str[i]=='R')
r=i%4;
else if(str[i]=='B')
b=i%4;
else if(str[i]=='Y')
y=i%4;
else if(str[i]=='G')
g=i%4;
else
ans[i%4]++;
}
printf("%d %d %d %d\n",ans[r],ans[b],ans[y],ans[g]);
}
return 0;
}


题目链接:​​点击打开链接​


C. Unfair Poll



time limit per test



memory limit per test



input



output


On the Literature lesson Sergei noticed an awful injustice, it seems that some students are asked more often than others.

n rows with m

1-st row, the 2-nd row, ..., the n - 1-st row, the n-th row, the n - 1-st row, ..., the 2-nd row, the 1-st row, the 2-nd row, ...

1-st pupil, the 2-nd pupil, ..., the m-th pupil.

k questions from pupils in order described above. Sergei seats on the x-th row, on the y-th place in the row. Sergei decided to prove to the teacher that pupils are asked irregularly, help him count three values:

  1. the maximum number of questions a particular pupil is asked,
  2. the minimum number of questions a particular pupil is asked,
  3. how many times the teacher asked Sergei.

If there is only one row in the class, then the teacher always asks children from this row.


Input



nmkx and y (1 ≤ n, m ≤ 100, 1 ≤ k ≤ 1018, 1 ≤ x ≤ n, 1 ≤ y ≤ m).


Output



Print three integers:

  1. the maximum number of questions a particular pupil is asked,
  2. the minimum number of questions a particular pupil is asked,
  3. how many times the teacher asked Sergei.


Examples



input



1 3 8 1 1



output



3 2 3



input



4 2 9 4 2



output



2 1 1



input



5 5 25 4 3



output



1 1 1



input



100 100 1000000000000000000 100 100



output



101010101010101 50505050505051 50505050505051


Note



The order of asking pupils in the first test:

  1. the pupil from the first row who seats at the first table, it means it is Sergei;
  2. the pupil from the first row who seats at the second table;
  3. the pupil from the first row who seats at the third table;
  4. the pupil from the first row who seats at the first table, it means it is Sergei;
  5. the pupil from the first row who seats at the second table;
  6. the pupil from the first row who seats at the third table;
  7. the pupil from the first row who seats at the first table, it means it is Sergei;
  8. the pupil from the first row who seats at the second table;

The order of asking pupils in the second test:

  1. the pupil from the first row who seats at the first table;
  2. the pupil from the first row who seats at the second table;
  3. the pupil from the second row who seats at the first table;
  4. the pupil from the second row who seats at the second table;
  5. the pupil from the third row who seats at the first table;
  6. the pupil from the third row who seats at the second table;
  7. the pupil from the fourth row who seats at the first table;
  8. the pupil from the fourth row who seats at the second table, it means it is Sergei;
  9. the pupil from the third row who seats at the first table;



大意:老师提问学生回答问题,一共要点 k 次。点名顺序为,从第 1 行开始点到第 n 行,然后再点第 n-1 行,点到第 1 行,再去点第2 行,在每一行中从左往右点(即从 1~m )。问所有同学中被点到的最多次数和最少次数,在第 x 行第 y 列坐的同学被点了多少次


思路:将 1->n->2 看作为一个周期

#include<cstdio>
#include<algorithm>
#include<cstring>
#define LL long long
using namespace std;
LL n,m,k,x,y;
LL ans[110][110];
int main()
{
while(~scanf("%lld%lld%lld%lld%lld",&n,&m,&k,&x,&y))
{
LL sum=0;
memset(ans,0,sizeof(ans));
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
ans[i][j]++,sum++;
for(int i=n-1;i>=2;i--)
for(int j=1;j<=m;j++)
ans[i][j]++,sum++;
LL t=k/sum;
k=k%sum;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
ans[i][j]*=t;
for(int i=1;i<=n&&k;i++)
for(int j=1;j<=m&&k;j++)
ans[i][j]++,k--;
for(int i=n-1;i>=2&&k;i--)
for(int j=1;j<=m&&k;j++)
ans[i][j]++,k--;
LL mmax=0,mmin=1LL*1e18;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
mmax=max(mmax,ans[i][j]),mmin=min(mmin,ans[i][j]);
printf("%lld %lld %lld\n",mmax,mmin,ans[x][y]);
}
return 0;
}