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|≤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
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'.

 #include <stdio.h>
#include <string.h>
int main()
{
int a,b,c,flag0,flag1,flag2,flag,i,len;
char s[];
gets(s);
len=strlen(s);
a=;
b=;
c=;
flag0=;
flag1=;
flag2=;
flag=;
len=strlen(s);
for(i=; i<len; i++)
{
if(s[i]=='a')
{
if(flag1||flag2)
{
printf("NO\n");
return ;
}
a++;
flag0=;
}
else if(s[i]=='b')
{
if(!flag0||flag2)
{
flag=;
break;
}
b++;
flag1=;
}
else if(s[i]=='c')
{
if(!flag0||!flag1)
{
flag=;
break;
}
c++;
flag2=;
}
}
if(flag==)
printf("NO\n");
else if((c==a||c==b)&&(c!=&&b!=))///注意要防止出现只有a,没有其他字母的情况
printf("YES\n");
else
printf("NO\n");
return ;
}

Check the string的更多相关文章

  1. Check the string CodeForces - 960A

    A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend ...

  2. 10 Things Every Java Programmer Should Know about String

    String in Java is very special class and most frequently used class as well. There are lot many thin ...

  3. Java - byte[] 和 String互相转换

    通过用例学习Java中的byte数组和String互相转换,这种转换可能在很多情况需要,比如IO操作,生成加密hash码等等. 除非觉得必要,否则不要将它们互相转换,他们分别代表了不同的数据,专门服务 ...

  4. Meteor check

    check方法用于检查参数或类型是否匹配模式. 安装check包 打开命令提示符窗口,并安装该软件包. C:\Users\Administrator\Desktop\meteorApp>mete ...

  5. 567. Permutation in String

    Problem statement: Given two strings s1 and s2, write a function to return true if s2 contains the p ...

  6. list去重,String[]去重,String[]去空,StringBuffer去重,并且以','隔开,list拆分

    1.// 删除ArrayList中重复元素 public static void removeDuplicate(List list) { HashSet h = new HashSet(list); ...

  7. 【LeetCode】字符串 string(共112题)

    [3]Longest Substring Without Repeating Characters (2019年1月22日,复习) [5]Longest Palindromic Substring ( ...

  8. CF1494A ABC String 题解

    Content 给定 \(T\) 个仅包含大写字母 A,B,C 的字符串 \(s\).问你是否能够通过将每个 A,B,C 换成 (,) 中的一个(同一个字母必须要换成同一个字符),使得最后得到的括号序 ...

  9. 学习AOP之透过Spring的Ioc理解Advisor

    花了几天时间来学习Spring,突然明白一个问题,就是看书不能让人理解Spring,一方面要结合使用场景,另一方面要阅读源代码,这种方式理解起来事半功倍.那看书有什么用呢?主要还是扩展视野,毕竟书是别 ...

随机推荐

  1. 806. Number of Lines To Write String (5月24日)

    解答 class Solution { public: vector<int> numberOfLines(vector<int>& widths, string S) ...

  2. <CPP学习 第二天> 字符串的输入 及 String类

    今天简单的学习了字符串的输入以及C++的String类. 1.面向行的输入: getline(); getline()函数读取整行,通过回车键输入的换行符来确定输入结尾.要调用这种方法,可以使用cin ...

  3. diff命令--比较两个文件的命令

    可以使用 --brief 来比较两个文件是否相同,使用 -c参数来比较这两个文件的详细不同之处,这绝对是判断文件是否被篡改的有力神器,

  4. 附件上传——mysql blob类型的数据(springboot)1

    作为一个初出茅庐的菜鸟,这几天做了一下附件的上传与下载,附件文件存储在mysql中,数据类型为blob.在此做一下总结.望指正. 一.先总结附件的上传.(实质是将文件传到controller,后处理成 ...

  5. 纯JS实现前端动态分页码

    思路分析:有3种情况 第一种情况,当前页面curPage < 4 第二种情况,当前页面curPage == 4 第三种情况,当前页面curPage>4 此外,还要考虑,当前页码 curPa ...

  6. 模拟MBR Grub故障修复

    1.  MBR故障修复 备份 mkdir /pp mount /dev/sdb1 /pp dd if=/dev/sda of=/pp/mrb.bak bs=512 count=1   破坏mrb dd ...

  7. yii 后台配置独立子域名方法

    我这里安装的是宝塔面板集成的环境WNMP,官网上虽然也有,但是写的并不明确,对我这种用YII的新手来说也很头疼,折腾了半天终于弄好,记录一下. 首先解析一个子域名:back.domain.com: 用 ...

  8. QOS-配置拥塞避免机制

    QOS-配置拥塞避免机制 2018年7月7日 20:29 尾丢弃及其导致的问题: 队列满时路由器进行尾丢弃,即新到的所有数据包都全部丢弃 丢弃的结果造成高延迟.高抖动.丧失服务保证.TCP全局同步.T ...

  9. python类的多态

    1. 什么是多态     多态指的是同一种/类事物的不同形态   2. 为何要用多态     多态性:在多态的背景下,可以在不用考虑对象具体类型的前提下而直接使用对象     多态性的精髓:统一   ...

  10. 为什么我要放弃javaScript数据结构与算法(第十一章)—— 算法模式

    本章将会学习递归.动态规划和贪心算法. 第十一章 算法模式 递归 递归是一种解决问题的方法,它解决问题的各个小部分,直到解决最初的大问题.递归通常涉及函数调用自身. 递归函数是像下面能够直接调用自身的 ...