#include <bits/stdc++.h>
using namespace std;
void solve() {
  int i, j;
  int n, m, s;
  cin >> n;
  int a[n], count = 0;
  for (i = 0; i < n; ++i) {
    cin >> a[i];
    count += a[i];
  }
  int maxval = -1, curr = 0;
  for (i = 0; i < n; ++i) {
    curr += (a[i] == 1) ? -1 : 1;
    if (curr > maxval) maxval = curr;
    if (curr < 0) curr = 0;
  }
  cout << count + maxval;
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  for (int it = 1; it <= t; it++) {
    solve();
  }
  return 0;
}
