#C3798. Can Form Palindrome
Can Form Palindrome
Can Form Palindrome
Given a string s
, determine if any permutation of the string can form a palindrome. A palindrome is a string that reads the same forwards and backwards. Using character frequency counts, it can be shown that a string can be rearranged into a palindrome if and only if at most one character has an odd frequency. Formally, let \(f(c)\) be the frequency of character \(c\) in \(s\); then, \(s\) can form a palindrome if and only if
\[
\sum_{c} \mathbf{1}_{\{f(c)\,\%\,2 = 1\}} \leq 1.
\]
inputFormat
The input consists of a single line containing a non-empty string s
.
outputFormat
Output a single line: "YES" if some permutation of s
can form a palindrome, otherwise output "NO".
civic
YES