#include <bits/stdc++.h>
using namespace std;
int x, y, a[10000], sum = 0, b[1000], n, mx, mnloc, mxloc, one = 0, answer,
                    l = 1, ans = 0, one2 = 0;
int main() {
  cin >> x;
  for (int i = 0; i < x; i++) {
    cin >> n;
    if (n == 1) {
      one++;
      if (mx > 0) mx -= 1;
    } else {
      mx += 1;
      if (mx > answer) answer = mx;
    }
  }
  if (one != x)
    cout << one + answer;
  else
    cout << x - 1;
}
