#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int n, sum = 0, mx = -1, mn = 0, x = 0;
  cin >> n;
  while (n--) {
    int m;
    cin >> m;
    sum += m;
    x += 1 - m * 2;
    mx = max(mx, x - mn);
    mn = min(mn, x);
  }
  cout << mx + sum << "\n";
  return 0;
}
