# [Solution] Binary String solution codeforces

Binary String solution codeforces – You are given a string đť‘ sÂ consisting of charactersÂ 0Â and/orÂ 1.

## [Solution] Binary String solution codeforces

You have to remove several (possibly zero) characters from the beginning of the string, and then several (possibly zero) characters from the end of the string.Â The string may become empty after the removals. The cost of the removal is theÂ maximumÂ of the following two values:

• the number of charactersÂ 0Â left in the string;
• the number of charactersÂ 1Â removed from the string.

What is theÂ minimumÂ cost of removal you can achieve?

## [Solution] Binary String solution codeforces

The first line contains one integerÂ đť‘ˇtÂ (1â‰¤đť‘ˇâ‰¤1041â‰¤tâ‰¤104) â€” the number of test cases.

Each test case consists of one line containing the stringÂ đť‘ sÂ (1â‰¤|đť‘ |â‰¤2â‹…1051â‰¤|s|â‰¤2â‹…105), consisting of charactersÂ 0Â and/orÂ 1.

The total length of stringsÂ đť‘ sÂ in all test cases does not exceedÂ 2â‹…1052â‹…105.

Output

For each test case, print one integer â€” the minimum cost of removal you can achieve.

Example
input

Copy

## [Solution] Binary String solution codeforces

5
101110110
1001001001001
0000111111
00000
1111

output

Copy
1
3
0
0
0


## Binary String solution codeforces

Consider the test cases of the example:

1. in the first test case, it’s possible to remove two characters from the beginning and one character from the end. Only oneÂ 1Â is deleted, only oneÂ 0Â remains, so the cost isÂ 11;
2. in the second test case, it’s possible to remove three characters from the beginning and six characters from the end. Two charactersÂ 0Â remain, three charactersÂ 1Â are deleted, so the cost isÂ 33;
3. in the third test case, it’s optimal to remove four characters from the beginning;
4. in the fourth test case, it’s optimal to remove the whole string;
5. in the fifth test case, it’s optimal to leave the string as it is.