201371: [AtCoder]ARC137 B - Count 1's

Memory Limit:1024 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $400$ points

Problem Statement

You are given an integer sequence of length $N$ consisting of $0$ and $1$: $A=(A_1,A_2,\cdots,A_N)$.

You will do the operation below exactly once.

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

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

Constraints

  • $1 \leq N \leq 3 \times 10^5$
  • $0 \leq A_i \leq 1$
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

$N$
$A_1$ $A_2$ $\cdots$ $A_N$

Output

Print the answer.


Sample Input 1

4
0 1 1 0

Sample Output 1

4

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


Sample Input 2

5
0 0 0 0 0

Sample Output 2

6

Sample Input 3

6
0 1 0 1 0 1

Sample Output 3

3

Input

题意翻译

给定一个长度为 $n$ 的由 $0,1$ 组成的整数序列 $A=(A_1,A_2,\cdots,A_n)$ 。你可以做以下的操作**一次且仅一次**: - 选择 $A$ 的一个连续的子段,对该子段进行反转操作,也就是将 $0$ 变成 $1$ ,将 $1$ 变成 $0$ 。注意,你可以选择一个空字段,这就相当于你什么都没有做。 最后 $A$ 中的 $1$ 的个数,是你能获得的分数。请问你有多少种可能的得分。

加入题单

上一题 下一题 算法标签: