#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n], b[n], p = -1, q = -1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0)
      b[i] = 1;
    else
      b[i] = -1;
  }
  int max = 0, sum = 0;
  for (int i = 0; i < n; i++) {
    sum += b[i];
    if (sum > max) {
      max = sum;
      p = p == -1 ? i : p;
      q = i;
    }
    if (sum < 0) {
      sum = 0;
      p = q = -1;
    }
  }
  if (p == -1 and max == 0) max -= 1;
  for (int i = 0; i < n; i++) {
    if (a[i] == 1) max += 1;
  }
  cout << max << endl;
}
