#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000001;
int arr[1001];
int n, cnt1, ans = -INF;
string s;
int main() {
  setlocale(0, "");
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[i] == 1) cnt1++;
  }
  int k = 0;
  for (int i = 0; i < n; i++) {
    if (k < 0) k = 0;
    if (arr[i] == 0) {
      k++;
    } else {
      k--;
    }
    ans = max(ans, k);
  }
  cout << ans + cnt1 << endl;
  return 0;
};
