MIN-MEX Cut solution codeforces
A binary string is a string that consists of charactersand .
Letof a binary string be the smallest digit among , , or that does not occur in the string. For example, of is , because and occur in the string at least once, of is , because and do not occur in the string and .
A binary stringis given. You should cut it into any number of substrings such that each character is in exactly one substring. It is possible to cut the string into a single substring — the whole string.
A stringis a substring of a string if can be obtained from by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.
What is the minimal sum of of all substrings pieces can be?
The input consists of multiple test cases. The first line contains a single integer( ) — the number of test cases. Description of the test cases follows.
Each test case contains a single binary string( ).
It’s guaranteed that the sum of lengths ofover all test cases does not exceed .
For each test case print a single integer — the minimal sum ofof all substrings that it is possible to get by cutting optimally.
6 01 1111 01100 101 0000 01010
1 0 2 1 1 2
In the first test case the minimal sum is.
In the second test case the minimal sum is.
In the third test case the minimal sum is.