Palindrome-phobia

AtCoder
IDcf17_final_b
Time2000ms
Memory256MB
Difficulty
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` and `c`. ## Input Input is given from Standard Input in the following format: $S$ [samples]
Samples
Input #1
abac
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.
Input #2
aba
Output #2
NO
Input #3
babacccabab
Output #3
YES
API Response (JSON)
{
  "problem": {
    "name": "Palindrome-phobia",
    "description": {
      "content": "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 ",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "cf17_final_b"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Snuke has a string $S$ consisting of three kinds of letters: `a`, `b` and `c`.\nHe has a phobia for palindromes, and wants to permute the characters in $S$ so that $S$ will not contain a palindrome of ...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments