#include <bits/stdc++.h>
using namespace std;
void input() {
  int n;
  cin >> n;
  int a[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int pre[n + 1];
  pre[0] = 0;
  pre[1] = a[1];
  for (int i = 2; i <= n; i++) {
    if (a[i]) {
      pre[i] = pre[i - 1] + 1;
    } else {
      pre[i] = pre[i - 1];
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      int x = 0;
      x += pre[i - 1];
      x += (j - i + 1) - (pre[j] - pre[i - 1]);
      x += (pre[n] - pre[j]);
      ans = max(ans, x);
    }
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  input();
  return 0;
}
