#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void input(vector<T>& v) {
  for (T& x : v) cin >> x;
}
void solve() {
  int n;
  cin >> n;
  vector<int> v(n);
  input(v);
  int qtd = 0;
  for (auto x : v) qtd += x == 1 ? 1 : 0;
  vector<int> diff(n);
  for (int i = 0; i < n; ++i) {
    int ddiff = v[i] == 0 ? 1 : -1;
    diff[i] = ddiff + (i == 0 ? 0 : diff[i - 1]);
  }
  int min_diff = 0;
  int ans = INT_MIN;
  for (int i = 0; i < n; ++i) {
    ans = max(ans, diff[i] - min_diff);
    min_diff = min(diff[i], min_diff);
  }
  cout << ans + qtd << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}
