#include <bits/stdc++.h>
using namespace std;
const int INF = int(1e7) + 7;
const int mx = (int)1e6 + 1;
int cnt, ans, a[1000], k, sum, ma = -9999;
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == 1) {
      ans++;
    }
  }
  if (n == ans) {
    cout << ans - 1;
    return 0;
  }
  if (n == 1) {
    if (ans == 1) {
      cout << 0;
    } else {
      cout << 1;
    }
    return 0;
  }
  ma = ans;
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      if (a[j] == 0) {
        cnt++;
      }
      if (a[j] == 1) {
        cnt--;
      }
      if ((ans + cnt) > ma) {
        ma = (ans + cnt);
      }
    }
    cnt = 0;
    sum = 0;
  }
  cout << ma;
}
