#include <bits/stdc++.h>
int main() {
  long long int i, j, k, l, s, t, N[1000000], supermax, max, flag = 0, c;
  scanf("%lld", &s);
  for (j = 0; j < s; j++) {
    scanf("%lld", &N[j]);
  }
  max = 0;
  supermax = 0;
  c = 0;
  for (j = 0; j < s; j++) {
    if (N[j] == 0) {
      flag = 1;
      max = max + 1;
    }
    if (max >= supermax && max >= 0) {
      supermax = max;
    }
    if (N[j] == 1 && max > 0) {
      max = max - 1;
    }
    if (N[j] == 1) {
      c = c + 1;
    }
  }
  if (flag == 1) {
    printf("%lld\n", supermax + c);
  } else {
    printf("%lld\n", s - 1);
  }
  return 0;
}
