Hackers with Bits

3.9

101 votes
Approved, Basic Programming, Easy
Problem

Hackers love bits, so does Alex. Alex has just started his career as hacker and found a special binary array A (containing and ).

In one operation, he can choose any two positions in the array, and can swap their values. He has to perform exactly one operation and maximize the length of the subarray containing only .

Note: The positions can be different or same.

As Alex is a newbie in his field, help him for the same, and output the required length of the sub array containing only .

Input Format:

First line consists of one integer N, denoting the number of elements in the array.

Second line consists of N space-separated integers, denoting the elements of the array.

Output Format:

Print the required length of the sub array containing only .

Input Constraints:

Sample Input
5
1 1 1 0 1
Sample Output
4
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Here .

And if we choose positions and (1 based indexing in array), we can swap their values and the length of the sub-array (from index 1 to 4) containing only , will be 4.

Editor Image

?