#include <bits/stdc++.h>
using namespace std;
bool sort_karo_ulta(const pair<long long, long long> &yeh,
                    const pair<long long, long long> &woh) {
  return (yeh.first > woh.first);
}
void solve() {
  long long n;
  cin >> n;
  long long arr[n];
  for (long long i = 0; i < n; i++) cin >> arr[i];
  long long ans = -1, ones = 0;
  for (long long i = 0; i < n; i++)
    if (arr[i] == 1) ones++;
  long long cur_value = 0;
  for (long long i = 0; i < n; i++) {
    cur_value = 0;
    for (long long j = i; j < n; j++) {
      cur_value += 1 - 2 * arr[j];
      ans = max(ans, cur_value);
    }
  }
  cout << ans + ones;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
