#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, ones = 0, sum = 0, globalsum = 0;
  cin >> x;
  int A[x], B[x];
  for (int i = 0; i < x; i++) {
    cin >> A[i];
    if (A[i] == 1) {
      B[i] = -1;
      ones++;
    } else
      B[i] = 1;
  }
  if (x == ones) {
    cout << x - 1;
    return 0;
  }
  for (int i = 0; i < x; i++) {
    if (B[i] != 1)
      sum--;
    else
      sum++;
    if (sum < 0) sum = 0;
    if (sum > globalsum) globalsum = sum;
  }
  cout << ones + globalsum;
  return 0;
}
