#include <bits/stdc++.h>
const long long inf = 1e9;
const long long mod = 1e9 + 7;
const long long zero = 0;
const long long maxn = 1e5 + 5;
using namespace std;
long long n, ans, ps[maxn];
bool a[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i > 0) ps[i] = ps[i - 1];
    ps[i] += a[i];
  }
  ans = ps[n - 1];
  if (ps[n - 1] == n) return cout << n - 1 << endl, 0;
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      if (j == 0) {
        if (ps[i] == 0) ans++;
        continue;
      }
      ans = max(ans, ps[n - 1] + (j - i + 1 - 2 * (ps[j] - ps[i - 1])));
    }
  }
  cout << ans << endl;
}
