A. Check the string

Codeforces
IDCF960A
Time1000ms
Memory256MB
Difficulty
implementation
English · Original
Chinese · Translation
Formal · Original
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 \le |S| \le 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. [samples] ## 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 有一个由若干个小写英文字母 '_a_' 组成的字符串。他将这个字符串交给他的朋友 B,B 在字符串末尾追加若干个 '_b_'。由于 A 和 B 都喜欢字符 '_a_' 和 '_b_',他们确保此时字符串中 *至少存在一个 '_a_' 和一个 '_b_'*。 B 现在将这个字符串交给 C,C 在字符串末尾追加若干个 '_c_'。然而,由于 C 是 A 和 B 的好朋友,他追加的 '_c_' 的数量等于当前字符串中 '_a_' 的数量,或等于 '_b_' 的数量。也有可能 '_c_' 的数量同时等于 '_a_' 和 '_b_' 的数量。 你现在手中有一个字符串,你想判断这个字符串是否可以通过上述方式得到。如果可以,请输出 "_YES_",否则输出 "_NO_"(不含引号)。 第一行且仅有一行包含一个字符串 $S$($1 lt.eq | S | lt.eq 5 thin 000$)。保证字符串仅由小写英文字母 '_a_'、'_b_'、'_c_' 组成。 根据条件输出 "_YES_" 或 "_NO_"。 考虑第一个例子:'_c_' 的数量等于 '_a_' 的数量。 考虑第二个例子:虽然 '_c_' 的数量等于 '_b_' 的数量,但顺序不正确。 考虑第三个例子:'_c_' 的数量等于 '_b_' 的数量。 ## Input 第一行且仅有一行包含一个字符串 $S$($1 lt.eq | S | lt.eq 5 thin 000$)。保证字符串仅由小写英文字母 '_a_'、'_b_'、'_c_' 组成。 ## Output 根据条件输出 "_YES_" 或 "_NO_"。 [samples] ## Note 考虑第一个例子:'_c_' 的数量等于 '_a_' 的数量。考虑第二个例子:虽然 '_c_' 的数量等于 '_b_' 的数量,但顺序不正确。考虑第三个例子:'_c_' 的数量等于 '_b_' 的数量。
**Definitions** Let $ S $ be a string over the alphabet $ \{a, b, c\} $. Let $ n_a = |S|_a $, $ n_b = |S|_b $, $ n_c = |S|_c $ denote the counts of characters 'a', 'b', and 'c' in $ S $, respectively. **Constraints** 1. $ n_a \geq 1 $, $ n_b \geq 1 $, $ n_c \geq 1 $ 2. All occurrences of 'a' come before all occurrences of 'b', and all occurrences of 'b' come before all occurrences of 'c'. That is, $ S $ must be of the form $ a^* b^* c^* $. 3. $ n_c = n_a $ **or** $ n_c = n_b $ (or both). **Objective** Determine whether $ S $ satisfies all above constraints. If yes, output "YES"; otherwise, output "NO".
Samples
Input #1
aaabccc
Output #1
YES
Input #2
bbacc
Output #2
NO
Input #3
aabc
Output #3
YES
API Response (JSON)
{
  "problem": {
    "name": "A. Check the string",
    "description": {
      "content": "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",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF960A"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "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...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "A 有一个由若干个小写英文字母 '_a_' 组成的字符串。他将这个字符串交给他的朋友 B,B 在字符串末尾追加若干个 '_b_'。由于 A 和 B 都喜欢字符 '_a_' 和 '_b_',他们确保此时字符串中 *至少存在一个 '_a_' 和一个 '_b_'*。\n\nB 现在将这个字符串交给 C,C 在字符串末尾追加若干个 '_c_'。然而,由于 C 是 A 和 B 的好朋友,他追加的 '_c_' 的...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ S $ be a string over the alphabet $ \\{a, b, c\\} $.  \nLet $ n_a = |S|_a $, $ n_b = |S|_b $, $ n_c = |S|_c $ denote the counts of characters 'a', 'b', and 'c' in $ S $, respectiv...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments