#K57587. Maximize Contiguous Ones

    ID: 30453 Type: Default 1000ms 256MiB

Maximize Contiguous Ones

Maximize Contiguous Ones

Given a binary string s of '0's and '1's, you are allowed to flip exactly one '0' to '1'. Your task is to determine the maximum possible length of a contiguous sequence of '1's after making the flip. If the string contains no '0', then the answer is simply the length of the string.

For a binary string s, let ones_left be the number of consecutive '1's before a '0' and ones_right be the number of consecutive '1's after that '0'. Flipping that '0' yields a contiguous sequence of length ones_left + ones_right + 1, but it cannot exceed the length of s. The final answer is the maximum such value over all positions of '0' in the string.

Note: Use LaTeX formatting for any formulas. For example, the contiguous sequence length when flipping a '0' can be expressed as \( ones\_left + ones\_right + 1 \) with the constraint \( ones\_left + ones\_right + 1 \leq |s| \).

inputFormat

The first line contains a single integer \(T\) which denotes the number of binary strings. Each of the following \(T\) lines contains a binary string consisting of characters '0' and '1'.

outputFormat

For each binary string, output the maximum possible length of a contiguous sequence of '1's after flipping exactly one '0'. Print each result on a new line.

## sample
1
1101011
4

</p>