#C4739. Minimum Distinct Characters After Arbitrary Swaps
Minimum Distinct Characters After Arbitrary Swaps
Minimum Distinct Characters After Arbitrary Swaps
You are given a string S. You can perform a swap operation on any two characters of S any number of times. Determine the minimum possible number of distinct characters in the final string.
Observation: You can rearrange the characters arbitrarily, so if all the characters are the same, the answer is 1; otherwise, you can always achieve a configuration with exactly 2 distinct characters even if the original string contains more than two distinct characters.
Formally, if S is a non-empty string, the answer is:
$$\text{answer} = \begin{cases} 1, &\text{if all characters in } S \text{ are identical} \\ 2, &\text{otherwise} \end{cases} $$Note that when S has a single character, the answer is trivially 1.
inputFormat
The input consists of a single line containing the string S (1 ≤ |S| ≤ 105). The string only contains printable ASCII characters.
outputFormat
Output a single integer representing the minimum possible number of distinct characters in the final string after performing the swap operations.
## sampleaabcc
2