include bits stdc define lli long long int define endl define mp make_

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <bits/stdc++.h>
#define lli long long int
#define endl "\n"
#define mp make_pair
#define pb push_back
#define MOD 1000000007
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
lli n, count1 = 0, count0 = 0, count0Max = 0;
cin >> n;
lli A[n];
for(lli i = 0; i < n; i++)
cin >> A[i];
for(lli i = 0; i < n; i++)
{
if(A[i] == 1)
{
++count1;
if(count0 > 0)
count0 = 0;
}
else
{
++count0;
if(count0 > count0Max)
count0Max = count0;
}
}
cout << count1 + count0Max << endl;
return 0;
}