Maximum Number of 1s
Submissions: 924   Accuracy:

31.58%

  Difficulty: Easy   Marks: 2

You are a binary string A consisting of 0s and 1s only. You are allowed to do exactly one move that is you have to choose two indices i and j (1 ≤ i ≤ j ≤ |A| where |A| is string length) and toggle all the characters at position k where i ≤ k ≤ j. Toggling means changing 0 to 1 and 1 to 0.

The task is that after exactly one move you have to obtain the maximum possible number of 1's.


Input:
The first line contains the number of test cases T. Each test case contains a string S consisting of 0s and 1s only.


Output:
Corresponding to each test case, in a new line, print the maximal number of 1's that can be obtained after exactly one move.


Constraints:
1 ≤ T ≤ 200
1 ≤ Length of string≤ 1005

Example:
Input
3
1010
1
10111

Output
3
0
5

 

** For More Input/Output Examples Use 'Expected Output' option **

Author: Hemang Sarkar


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.