#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  int a[n];
  int d[n];
  int k = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i]) {
      d[i] = -1;
      k++;
    } else
      d[i] = 1;
  }
  if (k == n) {
    cout << n - 1;
    return;
  }
  int max_so_far = 0, max_end_here = 0;
  int start = 0, end = 0, s = 0;
  for (int i = 0; i < n; i++) {
    max_end_here += d[i];
    if (max_end_here < 0) {
      max_end_here = 0;
      s = i + 1;
    } else if (max_end_here > max_so_far) {
      start = s;
      max_so_far = max_end_here;
      end = i;
    }
  }
  cout << k + max_so_far;
}
int main() { solve(); }
