#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  int arr[t];
  int ans = 0;
  for (int i = 0; i < t; i++) {
    cin >> arr[i];
    if (arr[i] == 1) {
      ans++;
      arr[i] = -1;
    } else {
      arr[i] = 1;
    }
  }
  int maxi = 0;
  int currentmax = 0;
  int sum = 0;
  if (ans == t) {
    cout << ans - 1;
    return 0;
  }
  for (int i = 0; i < t; i++) {
    sum = max(0, sum + arr[i]);
    maxi = max(sum, maxi);
  }
  cout << ans + maxi;
  return 0;
}
