#401. 反转游戏

反转游戏

题面翻译

小I有些无聊,所以他发明了一个在纸上玩的游戏。

他写下了n个整数a1,a2,a3,a4……an,每个都是0或1中的一个。他被允许做如下的一次操作:他选择一个起点i,一个终点j,保证1<=i<=j<=n,然后将区间中的每一个数翻转。翻转指将ax的值设定为1-ax。 问:翻转一次后,最多有几个1。

输入格式

第一行一个正整数 n n ( 1<=n<=100 1<=n<=100 ). 第二行n个正整数: a1,a2,,an a_{1},a_{2},…,a_{n} . 每个n n 的值为 0 or 1.

输出格式

输出一个正整数,为翻转后得到的最多的1的个数

样例 #1

样例输入1

5
1 0 0 1 0

样例输出 #1

4

样例 #2

样例输入 #2

4
1 0 0 1

样例输出 #2 4

提示

In the first case, flip the segment from 2 to 5 (i=2,j=5) (i=2,j=5) . That flip changes the sequence, it becomes: [1 1 1 0 1]. So, it contains four ones. There is no way to make the whole sequence equal to [1 1 1 1 1]. In the second case, flipping only the second and the third element (i=2,j=3) (i=2,j=3) will turn all numbers into 1.