#C4103. Optimal Subsequence Length

    ID: 47605 Type: Default 1000ms 256MiB

Optimal Subsequence Length

Optimal Subsequence Length

You are given a string s consisting of lowercase English letters. Your task is to find the length of an optimal subsequence of s such that the frequencies of characters in the subsequence are as balanced as possible.

More formally, let \( f(c) \) be the frequency of character \( c \) in the string. Define \( \max = \max_{c \in s} f(c) \) and \( \min = \min_{c \in s} f(c) \). The length of the optimal subsequence is then given by:

\( |s| - (\max - \min) \)

For example, if s = "aaabb", the frequency distribution is: a: 3, b: 2, so \( \max = 3 \) and \( \min = 2 \). The optimal subsequence length is \( 5 - (3-2) = 4 \).

inputFormat

The input consists of a single line containing the string s. It is guaranteed that s contains only lowercase English letters.

outputFormat

Output a single integer representing the length of the optimal subsequence, computed as \( |s| - (\max - \min) \), where \( |s| \) is the length of the string and \( \max \) and \( \min \) are the maximum and minimum frequencies of the characters in s respectively.

## sample
aabbcc
6