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. 项目管理器 ProjectManager Beta 10 发布

    本次更新内容: 可以设置主界面是否显示表格线 去除了开发日志界面的表格线,看起来好像好看一些 修复主界面时间显示的问题 自定义问候语 修复习惯统计记录时间显示错误的问题 修复创建项目时间错误问题 增加 ...

  2. hdu1789 Doing Homework again---(经典贪心)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1789 题目大意: 给出N个作业的截至日期,和N个作业不交所扣掉的分数,要求输出扣除分数做少的方案. ...

  3. js中获取元素的样式兼容性的写法

    1:设计元素的样式:el.style.color="red"||el.style["color"]="red"  获取元素的样式:el.st ...

  4. jacascript 滚动 scroll 与回到顶部

    前言:这是笔者学习之后自己的理解与整理.如果有错误或者疑问的地方,请大家指正,我会持续更新! 滚动 scroll scrollHeight 表示元素的总高度,包括由于溢出而无法展示在网页的不可见部分: ...

  5. (CLR-Via-C#) 类型基础

    CLR要求每个类型最终都派生自System.Object Object提供的公共方法: Equals: 如果两个对象具有相同的值,就返回true GetHashCode: 返回对象的哈希码 ToStr ...

  6. Java集合框架之四大接口、常用实现类

    Java集合框架 <Java集合框架的四大接口> Collection:存储无序的.不唯一的数据:其下有List和Set两大接口. List:存储有序的.不唯一的数据: Set:存储无序的 ...

  7. 使用控制台调试WinForm窗体程序

    .程序代码结构 .Win32DebuggerHelper.cs using System.Runtime.InteropServices; /* TODO:使用方法 Win32.AllocConsol ...

  8. 0307-关于html

    html最主要的三点: 1.标签的写法.用法 <标签名 属性名1="属性值1" 属性名2="属性值2">内容</标签名> 比如:< ...

  9. window10下安装linux虚拟机

    一.准备工具 虚拟机.镜像.putty 1.安装虚拟机 VMware Workstation Pro 安装成功之后需要输入密钥,请点击以下链接 http://www.360doc.com/conten ...

  10. [HNOI 2017]单旋

    Description H 国是一个热爱写代码的国家,那里的人们很小去学校学习写各种各样的数据结构.伸展树(splay)是一种数据 结构,因为代码好写,功能多,效率高,掌握这种数据结构成为了 H 国的 ...