#include <bits/stdc++.h>
using namespace std;
long long int arr[100007];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n;
  cin >> n;
  long long int a[n], one = 0;
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 1) one++;
  }
  long long int o = 0, z = 0;
  long long int max = 0;
  for (long long int i = 0; i < n; i++) {
    if (a[i] == 0) {
      z++;
    }
    if (a[i] == 1) {
      o++;
    }
    if (z - o < 0) {
      z = 0;
      o = 0;
    }
    if (z - o > max) max = z - o;
  }
  if (one == n)
    cout << one - 1;
  else
    cout << one + max;
}
