#agc045b. [agc045_b]01 Unbalanced
[agc045_b]01 Unbalanced
Problem Statement
Given is a string , where each character is 0
, 1
, or ?
.
Consider making a string by replacing each occurrence of ?
with 0
or 1
(we can choose the character for each ?
independently). Let us define the unbalancedness of as follows:
- (The unbalancedness of ) \= \\max \\{ The absolute difference between the number of occurrences of
0
and1
between the -th and -th character of (inclusive) :\\ 1 \\leq l \\leq r \\leq |S|\\}
Find the minimum possible unbalancedness of .
Constraints
- Each character of is
0
,1
, or?
.
Input
Input is given from Standard Input in the following format:
Output
Print the minimum possible unbalancedness of .
Sample Input 1
0??
Sample Output 1
1
We can make 010
and achieve the minimum possible unbalancedness of .
Sample Input 2
0??0
Sample Output 2
2
Sample Input 3
??00????0??0????0?0??00??1???11?1?1???1?11?111???1
Sample Output 3
4