#include <bits/stdc++.h>
using namespace std;
int n, a, b = -1, s, q;
int main() {
  cin >> n;
  while (n--) {
    cin >> a;
    s += a;
    q += 1 - 2 * a;
    b = max(b, q);
    q = max(0, q);
  }
  cout << s + b;
  return 0;
}
