atcoder#ARC137B. [ARC137B] Count 1's

[ARC137B] Count 1's

Score : 400400 points

Problem Statement

You are given an integer sequence of length NN consisting of 00 and 11: A=(A1,A2,,AN)A=(A_1,A_2,\cdots,A_N).

You will do the operation below exactly once.

  • Choose a contiguous subsequence of AA and flip the elements in it: convert 00 to 11 and vice versa. Here, you may choose an empty subsequence, in which case the elements of AA do not change.

Your score will be the number of 11's in AA. How many values are there that your score can take?

Constraints

  • 1N3×1051 \leq N \leq 3 \times 10^5
  • 0Ai10 \leq A_i \leq 1
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \cdots ANA_N

Output

Print the answer.

4
0 1 1 0
4

There are four possible values for your score: 0,1,2,30, 1, 2, 3. For example, if you flip the 22-nd through 44-th elements of AA, you will get A=(0,0,0,1)A=(0,0,0,1), for a score of 11.

5
0 0 0 0 0
6
6
0 1 0 1 0 1
3