atcoder#ABC240H. [ABC240Ex] Sequence of Substrings
[ABC240Ex] Sequence of Substrings
Score : points
Problem Statement
You are given a string of length consisting of 's and 's.
Find the maximum integer such that there is a sequence of pairs of integers $\big((L_1, R_1), (L_2, R_2), \ldots, (L_K, R_K)\big)$ that satisfy all three conditions below.
- for each .
- for .
- The string is strictly lexicographically smaller than the string .
Constraints
- is an integer.
- is a string of length consisting of 's and 's.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
7
0101010
3
For , one sequence satisfying the conditition is $(L_1, R_1) = (1, 1), (L_2, R_2) = (3, 5), (L_3, R_3) = (6, 7)$. Indeed, is strictly lexicographically smaller than , and is strictly lexicographically smaller than . For , there is no sequence $\big((L_1, R_1), (L_2, R_2), \ldots, (L_K, R_K)\big)$ satisfying the condition.
30
000011001110101001011110001001
9