#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
ll n,i,t=0,ma=INT_MIN,d=0;
cin>>n;
vector<ll> a(n);
for(i=0;i<n;i++) cin>>a[i];
for(ll i:a) if(i==1) t++;
for(i=0;i<n;i++)
{
if(a[i]==0) d++;
else d--;
ma=max(ma,d);
if(d<0) d=0;
}
cout<<t+ma;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBsbCBsb25nIGxvbmcKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKaW50IG1haW4oKQp7CiAgICBsbCBuLGksdD0wLG1hPUlOVF9NSU4sZD0wOwogICAgY2luPj5uOwogICAgdmVjdG9yPGxsPiBhKG4pOwogICAgZm9yKGk9MDtpPG47aSsrKSBjaW4+PmFbaV07CiAgICBmb3IobGwgaTphKSAgaWYoaT09MSkgdCsrOwogICAgZm9yKGk9MDtpPG47aSsrKQogICAgewogICAgICAgIGlmKGFbaV09PTApIGQrKzsKICAgICAgICBlbHNlIGQtLTsKICAgICAgICBtYT1tYXgobWEsZCk7CiAgICAgICAgaWYoZDwwKSBkPTA7CiAgICB9CiAgICBjb3V0PDx0K21hOwp9Cg==