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'的次数。上面就是条件!

 #include<bits/stdc++.h>
using namespace std; int main() {
string str;
cin>>str;
int a,b,c;
int flag = ;
a = ;
b = ;
c = ;
for(int i = ; i < str.length(); i++) {
if(str[i] == 'a') a++;
else if(str[i] == 'b') b++;
else if(str[i] == 'c') c++;
if( i>= && str[i-]>str[i]) flag = ;
}
if( (a == c|| c == b) && flag && (a!=&&b!=)) cout<<"YES"<<endl;
else cout<<"NO"<<endl; return ;
}

Check the string CodeForces - 960A的更多相关文章

  1. Minimal string CodeForces - 797C

    Minimal string CodeForces - 797C 题意:有一个字符串s和空串t和u,每次操作可以将s的第一个字符取出并删除然后放到t的最后,或者将t的最后一个字符取出并删除然后放到u的 ...

  2. D. Mahmoud and Ehab and the binary string Codeforces Round #435 (Div. 2)

    http://codeforces.com/contest/862/problem/D 交互题 fflush(stdout) 调试: 先行给出结果,函数代替输入 #include <cstdio ...

  3. Check the string

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

  4. You Are Given a Decimal String... CodeForces - 1202B [简单dp][补题]

    补一下codeforces前天教育场的题.当时只A了一道题. 大致题意: 定义一个x - y - counter :是一个加法计数器.初始值为0,之后可以任意选择+x或者+y而我们由每次累加结果的最后 ...

  5. Median String CodeForces - 1144E

    You are given two strings ss and tt, both consisting of exactly kk lowercase Latin letters, ss is le ...

  6. Minimal string CodeForces – 797C

    题目链接 题目难度: 1700rating 题目类型:string+贪心+STL 题目思路: 由于题目要求的最终结果是字典序最小的那个字符串,那么我们从贪心的从’a’开始查找字符串里是否存在,如果存在 ...

  7. Crisp String CodeForces - 1117F (状压)

    #include <iostream> #include <algorithm> #include <cstdio> #include <math.h> ...

  8. Balanced Ternary String CodeForces - 1102D (贪心+思维)

    You are given a string ss consisting of exactly nn characters, and each character is either '0', '1' ...

  9. codeforces 930b//Game with String// Codeforces Round #468 (Div. 1)

    题意:一个串,右循环移位后,告诉你第一个字母,还能告诉你一个,问你能确定移位后的串的概率. 用map记录每个字母出现的位置.对于每个字母,用arr[j][k]记录它的所有出现位置的后j位是字母k的个数 ...

随机推荐

  1. antd 主题色

    如果是自己配置的reac项目,而非官方推荐的creat-react-app或者dva-cli等阿里自己开发的脚手架去引入antd,会有两个问题 第一,用babel-plugin-import设置sty ...

  2. Python基础-用户验证

    一.项目需求 1.根据用户名和密码,验证用户是否可登陆 2.允许一次执行可验证三次 3.当用户名输错三次后,该用户名锁定,永久不可登陆 二.代码如下 #!/usr/bin/env python #-* ...

  3. tar命令-vi编辑器-磁盘分区及格式化-软链接及硬链接文件

    一.tar命令 1.将用户信息数据库文件和组信息数据库文件纵向合并为一个文件/1.txt(覆盖) [root@localhost  /] #  cat  /etc/passwd  /etc/group ...

  4. C#的扩展方法简介

    顾名思义,这是一种可以扩展C#类的操作,MSDN上的说法是: "扩展方法使您能够向现有类型"添加"方法,而无需创建新的派生类型.重新编译或以其他方式修改原始类型.&quo ...

  5. jacascript AJAX 学习

    前言:这是笔者学习之后自己的理解与整理.如果有错误或者疑问的地方,请大家指正,我会持续更新! AJAX 是 asynchronous javascript and XML 的简写,就是异步的 java ...

  6. Java中的几种常用循环

     循环的条件 反复执行一段相同或相似的代码 一     for循环        先判断,再执行   代码示例为 ① for (int i = 0; i < args.length; i++) ...

  7. Python处理Excel生成CSV文档

    Python是一种解释型的.动态数据类型的.面向对象的高级程序设计语言.拥有丰富的处理数据和文本类库,并且得益于它是一种解释型的语言,在程序修改和功能扩展上,可以很容易做到大规模的调整.综合考虑Pyt ...

  8. Spring-framework 源码导入 IntelliJ IDEA 记录

    前言 想学习spring框架,不看源码怎么行.网上有很多教程,但是自己实施起来还是稍微有点坎坷的,不过最后还是成功了.遂以此文记录. 环境说明: Idea  2017.2.5 spring-frame ...

  9. [LeetCode] Word Abbreviation 单词缩写

    Given an array of n distinct non-empty strings, you need to generate minimal possible abbreviations ...

  10. Python系列之 - 字符编码问题

    1.内存和硬盘都是用来存储的. CPU:速度快 硬盘:永久保存 2.文本编辑器存取文件的原理(nodepad++,pycharm,word) 打开编辑器就可以启动一个进程,是在内存中的,所以在编辑器编 ...