All problems

Problem 323

Longest Palindrome from Letters

Easy · 10 pts · String, Hash Table, Greedy

Problem

You have a bag of letters given as a string. Using each letter at most once (in any order), build the longest possible palindrome, a word that reads the same forwards and backwards. Letters are case-sensitive, so 'A' and 'a' are different. Print the length of the longest palindrome you can build. Hint: every pair of equal letters can go on both sides, and one single letter may sit in the middle.

Input

A single string S of English letters.

Output

Print the length of the longest palindrome that can be built.

Constraints

1 <= |S| <= 100000

Example input

abccccdd

Example output

7

Explanation

From 'abccccdd' you can build 'dccaccd': the pairs cc, cc and dd go on both sides and a single 'a' goes in the middle, for a length of 7.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Determine if Two Strings Are Close Next: Count and Say