# [2018-4-8]BNUZ套题比赛div2 【补题】

A. Check the string
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string.

B now gives this string to C and he appends some number of letters 'c' to the end of the string. However, since C is a good friend of A and B, the number of letters 'c' he appends is equal to the number of 'a' or to the number of 'b' in the string. It is also possible that the number of letters 'c' equals both to the number of letters 'a' and to the number of letters 'b' at the same time.

You have a string in your hands, and you want to check if it is possible to obtain the string in this way or not. If it is possible to obtain the string, print "YES", otherwise print "NO" (without the quotes).

Input

The first and only line consists of a string S (1 ≤ |S| ≤ 5 000). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'.

Output

Print "YES" or "NO", according to the condition.

Examples
input
Copy
aaabccc

output
YES

input
Copy
bbacc

output
NO

input
Copy
aabc

output
YES

Note

Consider first example: the number of 'c' is equal to the number of 'a'.

Consider second example: although the number of 'c' is equal to the number of the 'b', the order is not correct.

Consider third example: the number of 'c' is equal to the number of 'b'.

##### b给的字符串后面添加字符c，题目中保证最后的字符串至少有一个a或者b，然后让你检查这个字符串是否合法。合法就是输出YES，否则NO。
    #include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin>>s;
int a=0,b=0,c=0,flag=0,flag1=0,flag2=0;
for(int i=0; i<s.size(); i++)
{
if(s[i]=='a')
{
if(flag1||flag2)
{
puts("NO");
return 0;
}
a++,flag=1;
}
else if(s[i]=='b')
{
if(!flag||flag2)
{
puts("NO");
return 0;
}
b++,flag1=1;
}
else if(s[i]=='c')
{
if(!flag||!flag1)
{
puts("NO");
return 0;
}
c++,flag2=1;
}
}

if(c==a&&c||c==b&&b)///防止只有a那种情况,然后b=c=0会输出yes
puts("YES");
else puts("NO");
return 0;
}  



## B. Minimize the error

time limit per test
1 second
memory limit per test
256 megabytes
input standard input
output standard output

You are given two arrays A and B, each of size n. The error, E, between these two arrays is defined . You have to perform exactly k1 operations on array A and exactly k2 operations on array B. In one operation, you have to choose one element of the array and increase or decrease it by 1.

Output the minimum possible value of error after k1 operations on array A and k2 operations on array B have been performed.

Input

The first line contains three space-separated integers n (1 ≤ n ≤ 103), k1 and k2 (0 ≤ k1 + k2 ≤ 103, k1 and k2 are non-negative) — size of arrays and number of operations to perform on A and B respectively.

Second line contains n space separated integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — array A.

Third line contains n space separated integers b1, b2, ..., bn ( - 106 ≤ bi ≤ 106)— array B.

Output

Output a single integer — the minimum possible value of after doing exactly k1 operations on array A and exactly k2 operations on array B.

Examples
Input
Copy
2 0 0
1 2
2 3

Output
Copy
2
Input
Copy
2 1 0
1 2
2 2

Output
Copy
0
Input
Copy
2 5 7
3 4
14 4

Output
Copy
1
Note

In the first sample case, we cannot perform any operations on A or B. Therefore the minimum possible error E = (1 - 2)2 + (2 - 3)2 = 2.

In the second sample case, we are required to perform exactly one operation on A. In order to minimize error, we increment the first element of A by 1. Now, A = [2, 2]. The error is now E = (2 - 2)2 + (2 - 2)2 = 0. This is the minimum possible error obtainable.

In the third sample case, we can increase the first element of A to 8, using the all of the 5 moves available to us. Also, the first element of B can be reduced to 8 using the 6 of the 7 available moves. Now A = [8, 4] and B = [8, 4]. The error is now E = (8 - 8)2 + (4 - 4)2 = 0, but we are still left with 1 move for array B. Increasing the second element of B to 5 using the left move, we get B = [8, 5] and E = (8 - 8)2 + (4 - 5)2 = 1.

A. A Compatible Pair

Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming.

Little Tommy has n lanterns and Big Banban has m lanterns. Tommy's lanterns have brightness a1, a2, ..., an, and Banban's have brightness b1, b2, ..., bm respectively.

Tommy intends to hide one of his lanterns, then Banban picks one of Tommy's non-hidden lanterns and one of his own lanterns to form a pair. The pair's brightness will be the product of the brightness of two lanterns.

Tommy wants to make the product as small as possible, while Banban tries to make it as large as possible.

You are asked to find the brightness of the chosen pair if both of them choose optimally.

Input

The first line contains two space-separated integers n and m (2 ≤ n, m ≤ 50).

The second line contains n space-separated integers a1, a2, ..., an.

The third line contains m space-separated integers b1, b2, ..., bm.

All the integers range from  - 109 to 109.

Output

Print a single integer — the brightness of the chosen pair.

Examples
input
2 2
20 18
2 14

output
252

input
5 3
-1 0 1 2 3
-1 0 1

output
2

### 题意：现在有A,B两个数组，分别取一个数相乘，可以删掉A数组中一个元素，删除后从AB各挑一个数相乘让这个结果最大。这个题一开始就想着暴力，结果各种wa，想法失误，应该直接把所有结果存起来，直接取去掉一个数的最大值，唉，真的觉得都挺简单，结果就是各种卡题。。

    #include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a[110],b[110],n,m,p1,p2,mmax;
int main()
{
while(~scanf("%lld%lld",&n,&m))
{
for(ll i=1;i<=n;i++)scanf("%lld",&a[i]);
for(ll i=1;i<=m;i++)scanf("%lld",&b[i]);
mmax=-9e18;
for(ll i=1;i<=n;i++)
{
for(ll j=1;j<=m;j++)
{
if(a[i]*b[j]>mmax)
{
mmax=a[i]*b[j];
p1=i;
p2=j;
}
}
}
mmax=-9e18;
for(ll i=1;i<=n;i++)
{
for(ll j=1;j<=m;j++)
{
if(i==p1)continue;
if(a[i]*b[j]>mmax)mmax=a[i]*b[j];
}
}
printf("%lld\n",mmax);
}
return 0;
}