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


A. Compote



time limit per test



memory limit per test



input



output


a lemons, b apples and c pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio1: 2: 4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4

0.


Input



a (1 ≤ a ≤ 1000) — the number of lemons Nikolay has.

b (1 ≤ b ≤ 1000) — the number of apples Nikolay has.

c (1 ≤ c ≤ 1000) — the number of pears Nikolay has.


Output



Print the maximum total number of lemons, apples and pears from which Nikolay can cook the compote.


Examples



input



2 5 7



output



7



input



4 7 13



output



21



input



2 3 2



output



0


Note



1 lemon, 2 apples and 4 pears, so the answer is 1 + 2 + 4 = 7.

3 lemons, 6 apples and 12 pears, so the answer is 3 + 6 + 12 = 21.

0.



#include<cstdio>
#include<algorithm>
using namespace std;
int a,b,c;
int main()
{
while(~scanf("%d%d%d",&a,&b,&c))
{
int x1=a;
int x2=b/2;
int x3=c/4;
printf("%d\n",min(x1,min(x2,x3))*7);
}
return 0;
}


题目链接:

​点击打开链接​


B. Decoding



time limit per test



memory limit per test



input



output


median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, info. If the word consists of single letter, then according to above definition this letter is the median letter.

volga as logva.

s


Input



n (1 ≤ n ≤ 2000) — the length of the encoded word.

s of length n


Output



Print the word that Polycarp encoded.


Examples



input



5 logva



output



volga



input



2 no



output



no



input



4 abba



output



baba


Note



volga. At first, he wrote down the letter l from the position 3, after that his word looked like voga. After that Polycarp wrote down the letter o from the position 2, his word became vga. Then Polycarp wrote down the letter gwhich was at the second position, the word became va. Then he wrote down the letter v, then the letter a. Thus, the encoding looked likelogva.

no. He wrote down the letter n, the word became o, and he wrote down the letter o. Thus, in this example, the word and its encoding are the same.

baba. At first, he wrote down the letter a, which was at the position 2, after that the word looked like bba. Then he wrote down the letter b, which was at the position 2, his word looked like ba. After that he wrote down the letterb, which was at the position 1, the word looked like a, and he wrote down that letter a. Thus, the encoding is abba.



大意:给出一种编码方式,告诉你某单词的编码结果,求原单词

思路:观察可以看出,按编码结果字母的顺序,中间的位置开始:左边一个,右边一个,排完之后就是原单词。

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<stack>
using namespace std;
int n;
char str[2010];
int main()
{
while(~scanf("%d",&n))
{
scanf("%s",str);
stack<char> l;
char r[1010];
bool flag=0;
char ch;
if(n&1)
{
flag=1;
ch=str[0];
}
int temp=0,num=0;
for(int i=0;i<n;i++)
{
if(i==0&&flag)
continue;
temp++;
if(temp&1)
l.push(str[i]);
else
r[num++]=str[i];
}
while(!l.empty())
{
printf("%c",l.top());
l.pop();
}
if(flag)
putchar(ch);
for(int i=0;i<num;i++)
putchar(r[i]);
puts("");
}
return 0;
}


题目链接:

​点击打开链接​


C. Tram



time limit per test



memory limit per test



input



output


0 to the point s and back, passing 1 meter per t1 seconds in both directions. It means that the tram is always in the state of uniform rectilinear motion, instantly turning around at points x = 0 and x = s.

x1. He should reach the point x2. Igor passes 1 meter per t2

x1 to the point x2, if it is known where the tram is and in what direction it goes at the moment Igor comes to the point x1.

not obligatory that points in which Igor enter and exit the tram are integers. Assume that any boarding and unboarding happens instantly. Igor can move arbitrary along the line (but not faster than 1 meter per t2


Input



sx1 and x2 (2 ≤ s ≤ 1000, 0 ≤ x1, x2 ≤ sx1 ≠ x2) — the maximum coordinate of the point to which the tram goes, the point Igor is at, and the point he should come to.

t1 and t2 (1 ≤ t1, t2) — the time in seconds in which the tram passes 1 meter and the time in seconds in which Igor passes 1

p and d (1 ≤ p ≤ s - 1, d is either 1 or 

codeforces-746【思维】【模拟】_i++

) — the position of the tram in the moment Igor came to the point x1 and the direction of the tram at this moment. If 

codeforces-746【思维】【模拟】_ide_02

, the tram goes in the direction from the point s to the point 0. If d = 1, the tram goes in the direction from the point 0 to the point s.

Output


x1 to the point x2.


Examples


input


4 2 43 4 1 1


output


8


input


5 4 01 2 3 1


output


7


Note


2 meters and it takes 8 seconds in total, because he passes 1 meter per 4

x2 and get to the point 1 in 6 seconds (because he has to pass 3meters, but he passes 1 meters per 2 seconds). At that moment the tram will be at the point 1, so Igor can enter the tram and pass 1meter in 1 second. Thus, Igor will reach the point x2 in 7



大意:给出人和电车的起始位置,以及速度,人可以在合适的位置上乘坐电车,求从出发点到终点的最小时间

思路:

1)人在某一时刻可以坐顺风车,那么求人和电车到达 x2 点的时间的最小值即可;

2)人全程都坐不上顺风车,那么只能是人到达 x2 的时间

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int s,x1,x2,t1,t2,p,d;
int main()
{
while(~scanf("%d%d%d%d%d%d%d",&s,&x1,&x2,&t1,&t2,&p,&d))
{
int ans1=0;
int ans2=abs(x1-x2)*t2;
bool flag=0;
while(1)
{
if(p==x1)
flag=1;
if(p==x2&&flag) // 保证电车是从 x1 开向 x2
break;
if(p==0&&d==-1)
d=1;
if(p==s&&d==1)
d=-1;
if(d==1)
p++;
else
p--;
ans1+=t1;
}
printf("%d\n",min(ans1,ans2));
}
return 0;
}


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


D. Green and Black Tea


time limit per test


memory limit per test


input


output


n cups of tea. He would be happy to drink more but he had exactly ntea bags, a of them are green and b

k times in a row. Your task is to determine the order of brewing tea bags so that Innokentiy will be able to drink n cups of tea, without drinking the same tea more than k


Input


nka and b (1 ≤ k ≤ n ≤ 105, 0 ≤ a, b ≤ n) — the number of cups of tea Innokentiy wants to drink, the maximum number of cups of same tea he can drink in a row, the number of tea bags of green and black tea. It is guaranteed thata + b = n.


Output


n cups of tea, print "NO" (without quotes).

n, which consists of characters 'G' and 'B'. If some character equals 'G', then the corresponding cup of tea should be green. If some character equals 'B', then the corresponding cup of tea should be black.

If there are multiple answers, print any of them.


Examples


input


5 1 3 2


output


GBGBG


input


7 2 2 5


output


BBGBGBB


input


4 3 4 0


output


NO



大意:一个人有两种茶,但是他喝一种茶最多连续 k 次,输出一种合法的喝茶方案

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,k,a,b;
char A='G',B='B';
int pos[100010]; // 表示第 i 个位置之后喝另一种茶的次数
int main()
{
while(~scanf("%d%d%d%d",&n,&k,&a,&b))
{
if(a<b)
{
swap(a,b);
swap(A,B);
}
int x=a/k;
if(a%k==0)
x--;
if(x>b) // 最少要换 x 次茶喝
{
puts("NO");
continue;
}
memset(pos,0,sizeof(pos));
for(int i=k;i<a;i+=k) // 保证要换 x 次茶喝
{
b--;
pos[i]++;
}
for(int i=1;i<=a;i++)
{
while(b&&pos[i]<k)
{
b--;
pos[i]++;
}
}
while(b--) // b 不为 0,就在前面输出
putchar(B);
for(int i=1;i<=a;i++)
{
putchar(A);
for(int j=1;j<=pos[i];j++)
putchar(B);
}
puts("");
}
return 0;
}