Marcus loves strings, especially cute strings and ones consisting of the letters a
, b
, and c
. He recently received such a string (which we'll call
A merge operation is defined as follows:
Let
- Select an index
such that . - Remove the letters
and and replace them with the letter that is neither one of those two out ofa
,b
, andc
(i.e. if you removed the lettersa
andb
you would replace them with the letterc
).
Marcus managed to shorten his string quite a bit, but he wants you to verify his answer by helping him find the shortest length he can make his string after some number (possibly zero) of merge operations.
Lastly, to ensure the integrity of your solution, each input file will contain
Constraints
For all subtasks:
a
, b
, and c
.
The sum of
Subtask 1 [20%]
The sum of
Subtask 2 [30%]
The sum of
Subtask 3 [50%]
No additional constraints.
Input Specification
The first line will contain
Each case consists of a single line, the string
Output Specification
For each test case, output the shortest length that
Sample Input
3
abcabc
cccc
ab
Sample Output
2
4
1
Explanation
Here is an example sequence of merge operations in the first test case that yields an optimal answer (the portion in brackets denotes the indices being merged):
ab[ca]bc
->abbbc
abb[bc]
->abba
ab[ba]
->abc
a[bc]
->aa
aa
In the second case, no merge operations are possible so the answer is simply the length of the string.
In the last test case, ab
can be merged into c
.
Comments