#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  scanf("%d", &n);
  int arr[n];
  int dp[n];
  int ans = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &x);
    ans += x;
    if (x == 1) {
      arr[i] = -1;
    } else {
      arr[i] = 1;
    }
  }
  dp[0] = arr[0];
  int ans2 = dp[0];
  for (int i = 1; i < n; i++) {
    dp[i] = max(arr[i], arr[i] + dp[i - 1]);
    ans2 = max(ans2, dp[i]);
  }
  cout << ans + ans2;
  return 0;
}
