#C2593. Palindrome Rearrangement Check

    ID: 45926 Type: Default 1000ms 256MiB

Palindrome Rearrangement Check

Palindrome Rearrangement Check

Given a string of n characters, determine if they can be rearranged to form a palindrome.

A string can be rearranged into a palindrome if and only if at most one of its characters has an odd frequency. Mathematically, let \( f(c) \) be the frequency of character \( c \) in the string. Then, the string can form a palindrome if and only if:

\[ \sum_{c} \left[ f(c) \mod 2 \neq 0 \right] \leq 1 \]

For example, for the string "aabbccd", the counts are \(a:2, b:2, c:2, d:1\); since there is only one character with an odd count, the answer is "YES".

inputFormat

The input is read from standard input.

  • The first line contains an integer n representing the number of characters.
  • The second line contains a string of n characters.

outputFormat

Output to standard output a single line containing "YES" if the characters can be rearranged to form a palindrome; otherwise, output "NO".

## sample
7
aabbccd
YES