#C2699. Shortest Possible Reduced String
Shortest Possible Reduced String
Shortest Possible Reduced String
You are given a string s consisting of lowercase English letters. You are allowed to perform certain operations on the string that essentially reduce its length. It can be shown that the final shortest length of the string only depends on the number of distinct characters in s.
In particular, if s consists of only one unique character, no matter what operations you perform, you will always obtain a string of length 1. Otherwise, if s contains at least two different characters, it can always be reduced to a string of length 2.
This result can be expressed mathematically as follows:
$$L_{min} = \begin{cases} 1, & \text{if } |\{ s_i \}| = 1 \\ 2, & \text{if } |\{ s_i \}| > 1 \end{cases} $$You are required to compute and output the value of Lmin for the given string.
Examples:
- Input:
abaacb
— Output:2
- Input:
a
— Output:1
- Input:
abcd
— Output:2
inputFormat
The input is provided as a single line on standard input that contains a string s composed of lowercase English letters.
outputFormat
Output a single integer on standard output that represents the minimum possible length of the string after performing the allowed operations.
## sampleabaacb
2