Question
The Lone Break in the Signal
A communication line records signals as a binary array a of length n, where 1 means a strong signal and 0 means interference.
To stabilize the line, you must remove exactly one element from the array.
After this single removal, find the maximum length of a non-empty continuous segment of strong signals (1s) that can remain.
If no such segment can exist, output 0.
Input
The first line contains a single integer KaTeX can only parse string typed expression — the size of the array.
The second line contains KaTeX can only parse string typed expression integers, representing the elements of the array — KaTeX can only parse string typed expression, each being either KaTeX can only parse string typed expression or KaTeX can only parse string typed expression.
The second line contains KaTeX can only parse string typed expression integers, representing the elements of the array — KaTeX can only parse string typed expression, each being either KaTeX can only parse string typed expression or KaTeX can only parse string typed expression.
Output
Print a single integer — the maximum length of a non-empty continuous segment of strong signals (1s) that can remain.
Example
Input
5
1 1 0 1 1
Output
4
Explanation
The communication line has a single interference point. If we delete the KaTeX can only parse string typed expression at index 2, the signal becomes continuous as [1, 1, 1, 1]. The longest uninterrupted strong-signal segment then has length 4.
Input
3
1 1 1
Output
2
Explanation
Even though all signals are strong, one reading must be removed. After deleting any one element, the longest continuous segment of strong signals (1s) has length 2.
5
1 1 0 1 1
Output
4
Explanation
The communication line has a single interference point. If we delete the KaTeX can only parse string typed expression at index 2, the signal becomes continuous as [1, 1, 1, 1]. The longest uninterrupted strong-signal segment then has length 4.
Input
3
1 1 1
Output
2
Explanation
Even though all signals are strong, one reading must be removed. After deleting any one element, the longest continuous segment of strong signals (1s) has length 2.