#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9;
int main() {
  int n, zerosMax = -1, ones = 0, zeros = 0, ans = -INF;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    if (a == 1) {
      ones++;
      if (zeros > 0) {
        zeros--;
      }
    } else {
      zeros++;
      if (zeros > zerosMax) {
        zerosMax = zeros;
      }
    }
  }
  printf("%d\n", zerosMax + ones);
}
