#include <bits/stdc++.h>
using namespace std;
int n, ans, x, ct, ct2;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &x);
    ct += (x == 0 ? 1 : -1);
    if (ct < 0) ct = 0;
    ct2 += (x == 1 ? 1 : 0);
    ans = max(ct, ans);
  }
  if (ans == 0) ans = -1;
  printf("%d\n", ans + ct2);
  return 0;
}
