#include <bits/stdc++.h>
using namespace std;
int MaxSumSub(vector<int> &S, int sum, int n) {
  if (sum == n) return n - 1;
  int sum2, ans;
  sum2 = 0;
  ans = 0;
  for (int k = 0; k < n; ++k) {
    if (sum2 + S[k] > 0)
      sum2 += S[k];
    else
      sum2 = 0;
    ans = max(ans, sum2);
  }
  return ans + sum;
}
int main() {
  int n, tmp, sum = 0;
  vector<int> num;
  cin >> n;
  while (n--) {
    cin >> tmp;
    if (tmp == 1) {
      sum++;
      tmp = -1;
    } else
      tmp = 1;
    num.push_back(tmp);
  }
  cout << MaxSumSub(num, sum, num.size());
  return 0;
}
