#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, one = 0;
  cin >> n;
  int arr[n], dp[n];
  for (int i = 0; i < n; i++) {
    cin >> x;
    arr[i] = x;
    if (x == 1) one++;
  }
  if (one == n)
    cout << n - 1 << endl;
  else {
    if (arr[0] == 1)
      dp[0] = 0;
    else
      dp[0] = 1;
    for (int i = 1; i < n; i++) {
      if (arr[i] == 0)
        dp[i] = dp[i - 1] + 1;
      else {
        if (dp[i - 1] == 0)
          dp[i] = 0;
        else
          dp[i] = dp[i - 1] - 1;
      }
    }
    sort(dp, dp + n);
    cout << dp[n - 1] + one << endl;
  }
}
