#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n];
  int ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[i] == 1) ans++;
  }
  int maxs = INT_MIN;
  int countZero = 0;
  int countOne = 0;
  for (int i = 0; i < n; i++) {
    countZero = 0;
    countOne = 0;
    for (int j = i; j < n; j++) {
      if (arr[j] == 0)
        countZero++;
      else
        countOne++;
      int diff = countZero - countOne;
      maxs = max(maxs, diff);
    }
  }
  cout << ans + maxs << endl;
}
