#include <bits/stdc++.h>
using namespace std;
long long ara[300000], i, j, k, n, max1 = 0, max2 = -1, one = 0;
int main() {
  scanf("%I64d", &n);
  for (i = 0; i < n; i++) {
    scanf("%I64d", &ara[i]);
  }
  for (i = 0; i < n; i++) {
    if (ara[i] == 0) {
      max1++;
    } else {
      max1--;
      one++;
    }
    if (max1 > max2) max2 = max1;
    if (max1 < 0) max1 = 0;
  }
  printf("%I64d", max2 + one);
  return 0;
}
