#include <bits/stdc++.h>
using namespace std;
int main() {
  int S, i = 0, one = 0, zero = 0, temp = 0;
  cin >> S;
  int ar[S];
  while (i < S) {
    cin >> ar[i];
    if (ar[i] == 1) {
      ar[i++] = -1;
      one++;
    } else
      ar[i++] = 1;
  }
  for (int k = 0; k < S; k++) {
    temp += ar[k];
    if (temp < 0) temp = 0;
    if (zero < temp) zero = temp;
  }
  if (zero)
    cout << one + zero << endl;
  else
    cout << --one << endl;
  return 0;
}
