#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, sum = 0, mx = 0, best, cnt = 0;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (x == 1) {
      arr[i] = -1;
      cnt++;
    } else
      arr[i] = 1;
  }
  for (int i = 0; i < n; i++) {
    best = max(sum + arr[i], arr[i]);
    sum = best;
    if (best > mx) mx = best;
  }
  if (mx == 0)
    cout << mx + cnt - 1 << endl;
  else
    cout << mx + cnt << endl;
}
