#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  int max1 = 0, gain = 0, ans = 0;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    int g;
    if (x == 1) {
      g = -1;
      ans++;
    } else
      g = 1;
    gain = max(g, g + gain);
    max1 = max(gain, max1);
  }
  if (max1 == 0)
    ans--;
  else
    ans += max1;
  cout << ans;
  return 0;
}
