#include <bits/stdc++.h>
using namespace std;
int X[4] = {1, 0, -1, 0};
int Y[4] = {0, 1, 0, -1};
int main() {
  int n;
  while (cin >> n) {
    vector<int> v;
    for (int i = 0; i < n; i++) {
      int x;
      cin >> x;
      v.push_back(x);
    }
    int maxi = -2;
    int c = 0;
    int s = 0;
    for (int i = 0; i < n; i++) {
      if (v[i] == 1) s++;
    }
    for (int i = 0; i < n; i++) {
      int c = 0;
      for (int j = i; j >= 0; j--) {
        if (v[j] == 1)
          c--;
        else
          c++;
        maxi = max(maxi, c);
      }
    }
    cout << s + maxi << endl;
  }
}
