#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n], z = 0, b[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i]) z++;
    if (a[i])
      b[i] = -1;
    else
      b[i] = 1;
  }
  if (z == n) {
    cout << n - 1 << endl;
    return 0;
  }
  int maxi = 0, sum = 0, s = 0, e = 0;
  for (int i = 0; i < n; i++) {
    sum += b[i];
    if (sum < 0) {
      sum = 0;
      s = i + 1;
    }
    if (sum > maxi) {
      maxi = sum;
      e = i;
    }
  }
  cout << maxi + z << endl;
  return 0;
}
