Time Limit: 2 sec / Memory Limit: 256 MB
配点 : 400 点
問題文
すぬけ君は a
、b
、c
の 3 種類の文字のみからなる文字列 S を持っています。
回文恐怖症のすぬけ君は S の文字を自由に並び替えて、2 文字以上の回文を部分文字列として含まないようにしようと思いました。 これが可能かどうかを判定して下さい。
制約
- 1 \leq |S| \leq 10^5
- S は
a
、b
、c
以外の文字を含まない。
入力
入力は以下の形式で標準入力から与えられる。
S
出力
可能な場合は YES
、不可能な場合は NO
を出力せよ。
入力例 1
abac
出力例 1
YES
このままだと aba
という回文を含みますが、例えば acba
のように並び替えると 2 文字以上の回文を含まなくなります。
入力例 2
aba
出力例 2
NO
入力例 3
babacccabab
出力例 3
YES
Score : 400 points
Problem Statement
Snuke has a string S consisting of three kinds of letters: a
, b
and c
.
He has a phobia for palindromes, and wants to permute the characters in S so that S will not contain a palindrome of length 2 or more as a substring. Determine whether this is possible.
Constraints
- 1 \leq |S| \leq 10^5
- S consists of
a
,b
andc
.
Input
Input is given from Standard Input in the following format:
S
Output
If the objective is achievable, print YES
; if it is unachievable, print NO
.
Sample Input 1
abac
Sample Output 1
YES
As it stands now, S contains a palindrome aba
, but we can permute the characters to get acba
, for example, that does not contain a palindrome of length 2 or more.
Sample Input 2
aba
Sample Output 2
NO
Sample Input 3
babacccabab
Sample Output 3
YES