#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
int main() {
  int n;
  int cnt = 0;
  int ans = 0;
  cin >> n;
  int a[n];
  for (int i = (int)(0); i <= (int)(n - 1); i++) {
    cin >> a[i];
    if (a[i])
      a[i] = -1, cnt++;
    else
      a[i] = 1;
  }
  int mx = INT_MIN;
  for (int i = (int)(0); i <= (int)(n - 1); i++) {
    ans += a[i];
    if (ans > mx) mx = ans;
    if (ans < 0) ans = 0;
  }
  cout << mx + cnt << '\n';
}
