#include <bits/stdc++.h>
using namespace std;
int max(int a, int b) { return (a > b) ? a : b; }
int main() {
  int64_t n;
  cin >> n;
  int64_t a[n], b[n], ones = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i])
      b[i] = -1, ones++;
    else
      b[i] = 1;
  }
  int maxsum = b[0], sum = b[0];
  for (int i = 1; i < n; i++) {
    sum = max(b[i], sum + b[i]);
    maxsum = max(maxsum, sum);
  }
  cout << ones + maxsum << "\n";
  return 0;
}
