#K48652. Longest Palindrome Construction
Longest Palindrome Construction
Longest Palindrome Construction
Given a string S, determine the maximum length of a palindrome that can be built using the characters from S. The palindrome does not need to be a substring of S; you can rearrange the characters arbitrarily. In other words, for each character, you can use it as many times as it appears in S, and you can form a palindrome by pairing up characters. If any characters appear an odd number of times, one of them can be placed in the middle.
The mathematical formulation is as follows:
Let \(f(c)\) be the frequency of character \(c\) in S. The answer is given by:
\[ \text{length} = \sum_{c} \left\lfloor \frac{f(c)}{2} \right\rfloor \times 2 + \begin{cases} 1, & \text{if any } f(c) \text{ is odd} \\ 0, & \text{otherwise} \end{cases} \]
Compute and output this maximum possible palindrome length.
inputFormat
The input consists of a single line containing the string S.
The string may include letters, digits, and other characters. The input is read from the standard input (stdin).
outputFormat
Output a single integer representing the length of the longest palindrome that can be constructed using the characters of S. The output should be written to the standard output (stdout).
## sampleabccccdd
7