#K54852. Rearranging the String

    ID: 29845 Type: Default 1000ms 256MiB

Rearranging the String

Rearranging the String

You are given a string s consisting of lowercase letters. Your task is to determine whether it is possible to rearrange the letters in s so that no two adjacent characters are the same.

More formally, let n be the length of the string. A rearrangement is possible if and only if for every character, its frequency does not exceed \( \left\lfloor \frac{n+1}{2} \right\rfloor \). Otherwise, it is impossible.

Example:

  • If s = "aabb", one possible rearrangement is "abab", so the answer is YES.
  • If s = "aaab", there is no rearrangement meeting the condition, so the answer is NO.

inputFormat

The input consists of a single line containing the string s. The string contains only lowercase letters.

Note: The input is provided via standard input.

outputFormat

Output a single line containing YES if it is possible to rearrange the letters so that no two adjacent characters are the same. Otherwise, output NO.

Note: The output should be printed to standard output.

## sample
aabb
YES