#C8734. Longest Palindrome Length

    ID: 52749 Type: Default 1000ms 256MiB

Longest Palindrome Length

Longest Palindrome Length

Given a string (s) consisting of lowercase letters, determine the length of the longest palindrome that can be constructed using the letters in (s). You may rearrange the letters arbitrarily and use some or all of them. The idea is to count the frequency of each character; for characters with an even frequency, add the whole count, while for odd frequency characters add the largest even number (i.e. (count - 1)) and finally, if there is any character with an odd count, add one to place in the center. Formally, the result can be computed as: (result = \sum_{x \in letters} (\text{if } count_x \text{ is even then } count_x \text{ else } count_x - 1) + \bigl(\text{if any } count_x \text{ is odd then } 1 \text{ else } 0\bigr)).

inputFormat

Standard input contains a single line with a non-empty string (s) consisting only of lowercase English letters.

outputFormat

Output a single integer which is the length of the longest palindrome that can be built using the letters of the string.## sample

aabbcc
6