Check the string CodeForces

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
aaabccc
Output
YES
Input
bbacc
Output
NO
Input
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'.

题析:字符串规则 ‘a' 'b'出现的次数都不能为0,必须按a b c顺序,’c'出现的次数要等于‘a'次数或者’b'的次数。上面就是条件!

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 
 4 int main() {
 5     string str;
 6     cin>>str;
 7     int a,b,c;
 8     int flag  = 1;
 9     a = 0;
10     b = 0;
11     c = 0;
12     for(int i = 0; i <     str.length(); i++) {
13         if(str[i] == 'a') a++;
14         else if(str[i] == 'b') b++;
15         else if(str[i] == 'c') c++;
16         if( i>= 1 && str[i-1]>str[i]) flag = 0;
17     }
18     if( (a == c|| c == b) && flag && (a!=0&&b!=0))    cout<<"YES"<<endl;
19     else     cout<<"NO"<<endl;
20 
21     return 0;
22 }
原文地址:https://www.cnblogs.com/jj81/p/8747642.html