#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, INF = 1e9 + 7;
int main() {
  int i, n, a, x, y, mx;
  cin >> n;
  for (mx = x = y = i = 0; i < n; i++) {
    cin >> a;
    if (a) y++;
    if (!a)
      x++, mx = x > mx ? x : mx;
    else if (x > 0)
      x--;
  }
  if (!mx) mx--;
  cout << y + mx;
}
