#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int NR[n];
  int OneCount = 0;
  int resStart = 0, Start = 0;
  int resEnd = 0;
  bool swich = false;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (a == 1) {
      OneCount++;
      NR[i] = 1;
    } else
      NR[i] = 0;
  }
  int maxim = 0, mx = 0;
  for (int j = 0; j < n; j++) {
    if (NR[j] == 0) {
      if (!swich) {
        Start = j;
      }
      maxim++;
      if (mx <= maxim) {
        mx = maxim;
        resStart = Start;
        resEnd = j;
      }
      swich = true;
    } else {
      maxim--;
      if (maxim < 0) {
        swich = false;
        maxim = 0;
      }
    }
  }
  int zero = 0;
  int one = 0;
  for (int a = resStart; a < resEnd + 1; a++) {
    if (NR[a] == 1)
      one++;
    else
      zero++;
  }
  cout << OneCount + zero - one;
  return 0;
}
