#C1097. Longest Subsequence with Paired Letters
Longest Subsequence with Paired Letters
Longest Subsequence with Paired Letters
Given a string s consisting of lowercase alphabets, find the length of the longest subsequence such that each character in the subsequence appears exactly twice and the first occurrence appears before the second.
In other words, for every character c that appears in the subsequence, if its frequency in s is f, you can use it in the subsequence 2 ⌊f/2⌋ times. The final answer is the sum over all characters, i.e.,
$$\text{result} = \sum_{c \in s} 2\left\lfloor \frac{f(c)}{2} \right\rfloor.$$
For example, if s = "aabbcc", the answer is 6, and if s = "xxyyz", the answer is 4.
inputFormat
The input consists of a single line containing a string s of lowercase alphabets.
outputFormat
Output a single integer representing the length of the longest subsequence where each letter appears exactly twice following the order of their appearance.
## sampleaabbcc
6