#C6261. Longest Subsequence with Doubled Occurrences
Longest Subsequence with Doubled Occurrences
Longest Subsequence with Doubled Occurrences
You are given a string S
consisting of lowercase letters. Your task is to find the length of the longest subsequence of S
such that every character in the subsequence appears at least twice.
In other words, for each character c
in the subsequence, if its frequency in the subsequence is f, then f must satisfy
$$f \ge 2.$$
Note: The subsequence does not need to be contiguous, but the order must be preserved. However, since you only need to count frequencies, you can simply add pairs of each character. The answer can be computed using:
$$answer = \sum_{c \in \text{alphabet}} 2 \left\lfloor \frac{\text{count}(c)}{2} \right\rfloor.$$
inputFormat
A single line containing the string S.
outputFormat
Print a single integer which is the length of the longest subsequence in which every character appears at least twice.## sample
abcabc
6