#include <bits/stdc++.h>
using namespace std;
void solve();
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t = 1;
  while (t--) {
    solve();
  }
}
void solve() {
  long long n;
  bool fnd0 = false;
  cin >> n;
  vector<long long> arr(n + 1, 0);
  vector<long long> count(n + 1, 0);
  long long cnt = 0;
  for (long long i = 1; i <= n; i++) {
    long long a;
    cin >> a;
    arr[i] = a == 0 ? arr[i - 1] + 1 : arr[i - 1];
    if (a == 1) {
      cnt++;
    } else {
      fnd0 = true;
    }
    count[i] = cnt;
  }
  long long ans = 0;
  if (fnd0) {
    for (long long i = 1; i <= n; i++) {
      for (long long j = i; j >= 0; j--) {
        long long val = arr[i] - arr[j];
        val += cnt - count[i] + count[j];
        if (val > ans) {
          ans = val;
        }
      }
    }
  } else {
    ans = cnt - 1;
  }
  cout << ans << "\n";
}
