#K4716. Valid Rearranged Frequencies

    ID: 28137 Type: Default 1000ms 256MiB

Valid Rearranged Frequencies

Valid Rearranged Frequencies

You are given a string message. Your task is to determine whether it is possible to rearrange the characters such that every character appears the same number of times. In other words, check if all characters have equal frequency, or if by removing exactly one occurrence of any character, the frequencies can become uniform.

More formally, let (f(c)) denote the frequency of character (c). The string is considered valid if either all (f(c)) are equal, or if there exist exactly two distinct frequencies (a) and (b) such that one of them occurs exactly once and either (a=1) or (|a-b|=1).

inputFormat

A single line containing the string message. Input is provided via standard input (stdin).

outputFormat

Output a single line: either (YES) if the string can be rearranged (or modified by removing one occurrence) to have uniform character frequencies, or (NO) otherwise. The result should be printed to standard output (stdout).## sample

aabbcc
YES