#include <bits/stdc++.h>
using namespace std;
int fun(const vector<int> &v) { return count(v.begin(), v.end(), 1); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  vector<int> v(n);
  for (auto &x : v) {
    cin >> x;
  }
  int best = fun(v);
  bool flip = 0;
  for (int i = 0; i < n; ++i) {
    int len = n;
    while (len >= i) {
      for (int j = i; j < len; ++j) {
        v[j] ^= 1;
      }
      if (best < max(best, fun(v))) {
        best = max(best, fun(v));
        flip = 1;
      }
      for (int j = i; j < len; ++j) {
        v[j] ^= 1;
      }
      len--;
    }
  }
  if (!flip) {
    cout << best - 1 << endl;
  } else
    cout << best << endl;
  return 0;
}
