#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  int str[n], init = 0;
  for (int i = 0; i < n; i++) {
    cin >> str[i];
    init += str[i];
  }
  int best = -1;
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      int sum = init;
      int tmp = 0;
      for (int k = i; k <= j; k++) {
        if (str[k] == 1) {
          tmp -= 1;
        } else {
          tmp += 1;
        }
      }
      sum += tmp;
      best = max(best, sum);
    }
  }
  cout << best << "\n";
}
