#K36952. Palindrome Rearrangement

    ID: 25868 Type: Default 1000ms 256MiB

Palindrome Rearrangement

Palindrome Rearrangement

You are given T strings. For each string, determine whether it is possible to rearrange its characters to form a palindrome.

A string can be rearranged into a palindrome if and only if the number of characters with an odd frequency is at most one. Mathematically, if we let \(f(c)\) be the frequency of character \(c\) in the string, then the string can form a palindrome if \[ \sum_{c} [f(c) \mod 2 \neq 0] \le 1 \] where \([P]\) equals 1 if the predicate \(P\) is true, and 0 otherwise.

Example:

  • For the string aabb: that can form the palindrome "abba" or "baab" hence the answer is YES.
  • For abc: it cannot form any palindrome so the answer is NO.
  • For civic: the string is already a palindrome and the answer is YES.

inputFormat

The first line contains an integer T (the number of test cases). Each of the following T lines contains a non-empty string S.

It is guaranteed that the string consists of lowercase English letters.

outputFormat

For each test case, print a single line containing YES if it is possible to rearrange the string into a palindrome, otherwise print NO.

## sample
3
aabb
abc
civic
YES

NO YES

</p>