#C8270. Can Form Palindrome
Can Form Palindrome
Can Form Palindrome
Given a string s
consisting of Latin letters, determine whether its characters can be rearranged to form a palindrome.
A string is a palindrome if it reads the same backward as forward. For a string to be rearranged into a palindrome, at most one character can appear an odd number of times.
For example, the string "civic"
is already a palindrome and "ivicc"
can be rearranged into "civic"
, but "hello"
cannot. Note that the check is case-sensitive.
Mathematical Formulation:
Let \( f(c) \) be the frequency of character \( c \) in s
. The string can form a palindrome if and only if
\[
\sum_{c \in s} \mathbf{1}_{\{f(c) \,\%\, 2 \neq 0\}} \leq 1
\]
where \( \mathbf{1} \) is the indicator function.
inputFormat
The input consists of a single line containing the string s
. The string may contain both lowercase and uppercase Latin letters.
outputFormat
Output a single line with either True
or False
(without quotes) indicating whether the characters of s
can be rearranged to form a palindrome.## sample
civic
True