#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
int n, a[maxn], cunt = 0, dp[maxn];
int main() {
  memset(dp, 0, sizeof(dp));
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int c;
    scanf("%d", &c);
    if (c == 1)
      a[i] = -1, cunt++;
    else
      a[i] = 1;
  }
  dp[0] = a[0];
  int maxc = a[0];
  for (int i = 1; i < n; i++)
    dp[i] = max(dp[i - 1] + a[i], a[i]), maxc = max(maxc, dp[i]);
  printf("%d\n", maxc + cunt);
  return 0;
}
