#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, n, t = 0, p = 0, m = 0, z = 0, ara[100000];
  cin >> n;
  int ma = -n;
  for (i = 0; i < n; i++) {
    cin >> ara[i];
    if (ara[i] == 1) {
      p++;
    }
  }
  for (i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      if (ara[j] == 1) {
        m--;
      } else {
        m++;
      }
      ma = max(ma, m);
    }
    m = 0;
  }
  cout << p + ma << endl;
}
