#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int a[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  int m = 0, M = 0, c = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == 0) {
      m++;
    } else {
      c++;
      m--;
    }
    if (m < 0) {
      m = 0;
    }
    M = max(m, M);
  }
  if (M == 0) {
    M = -1;
  }
  printf("%d", c + M);
  return 0;
}
