Check the string

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 SS (1≤|S|≤50001≤|S|≤5000). 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

Copy

YES

input

Copy

bbacc

output

Copy

NO

input

Copy

aabc

output

Copy

YES

题意:a这个人有个字符串,里面有a字符,让后给b这个人,b可以向里面添加字符b在a给的字符串后面,然后给c这个人,c可以向里面添加字符c,在b给的字符串后面。
题目中保证最后的字符串至少有一个a或者b,然后让你检查这个字符串是否合法。合法就是输出YES,否则NO。

题解:模拟   合法的要求就是a之前不能有b,c字符,b之前不能有c字符,并且c的个数的等于a的个数或者b的个数。

#include <stdio.h>
int main()
{
    char s[5001];
    int a=0,b=0,c=0,flag=0,flag1=0,flag2=0,m=0,i;
    gets(s);
    for(i=0;s[i];i++)
    {
        if(s[i]=='a')
        {
            if(flag1||flag2)
            {
                printf("NO
");
                return 0;
            }
            a++;flag=1;
        }
        else
        if(s[i]=='b')
        {
            if(!flag||flag2)
            {
                m=1;
                break;
            }
            b++;flag1=1;
        }
        else
        if(s[i]=='c')
        {
            if(!flag||!flag1)
            {
                m=1;
                break;
            }
            c++;
            flag2=1;
        }
    }
    if(m==1)
        printf("NO
");
    else
    if(c==a&&c||c==b&&b)
        printf("YES
");
    else
        printf("NO
");
    return 0;
}

 

原文地址:https://www.cnblogs.com/zcy19990813/p/9702816.html