#include <bits/stdc++.h>
using namespace std;
int a[1000];
int main() {
  int n;
  cin >> n;
  int u = 0;
  for (int k = 1; k <= n; k++) {
    cin >> a[k];
    if (a[k] == 1) u++;
  }
  int s = 0;
  for (int k = 1; k <= n; k++) {
    int p = 0;
    int v = 0;
    for (int j = k; j <= n; j++) {
      if (a[j] == 0) p++;
      if (a[j] == 1) p--;
      if (p > v) v = p;
    }
    if (v > s) s = v;
  }
  if (s == 0)
    cout << u - 1;
  else
    cout << s + u;
  return 0;
}
