#K56067. Alternating Characters Rearrangement

    ID: 30116 Type: Default 1000ms 256MiB

Alternating Characters Rearrangement

Alternating Characters Rearrangement

You are given a string s and your task is to determine if it is possible to rearrange its characters so that no two adjacent characters are the same. In other words, the characters must be arranged in an alternating sequence. One necessary and sufficient condition for such an arrangement is that the maximum frequency of any character in the string does not exceed \( \lceil \frac{n}{2} \rceil \), where \( n \) is the length of the string.

The input consists of multiple test cases. For each test case, you are given a string, and you must output "YES" if the string can be rearranged into a sequence with no adjacent identical characters, or "NO" otherwise.

Example:

Input:
3
 aabb
 aaab
 abcabc

Output: YES NO YES

</p>

inputFormat

The first line of input contains an integer \( T \) representing the number of test cases. Each of the following \( T \) lines contains a single string \( s \) consisting of lowercase or uppercase letters.

outputFormat

For each test case, output a single line containing "YES" if the string can be rearranged so that no two adjacent characters are the same, or "NO" otherwise.

## sample
3
aabb
aaab
abcabc
YES

NO YES

</p>