#include <bits/stdc++.h>
using namespace std;
int main() {
  int t = 1;
  while (t--) {
    int n;
    cin >> n;
    int arr[n + 10];
    for (int i = 0; i < n; i++) cin >> arr[i];
    int ons = 0;
    for (int i = 0; i < n; i++) ons += arr[i];
    if (ons == n) {
      cout << n - 1 << endl;
      continue;
    }
    int zeros[1001][1001], ones[1001][1001];
    for (int i = 0; i < n; i++) {
      zeros[i][i] = !arr[i];
      ones[i][i] = arr[i];
      for (int j = i + 1; j < n; j++) {
        zeros[i][j] = zeros[i][j - 1] + !arr[j];
        ones[i][j] = ones[i][j - 1] + arr[j];
      }
    }
    int mx = ons;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        mx = max(mx, ons + zeros[i][j] - ones[i][j]);
      }
    }
    cout << mx << endl;
  }
}
