#include <bits/stdc++.h>
const int maxn = 105;
int a[maxn], dp[maxn];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  dp[0] = !a[0];
  int cnt = (a[0] == 1), maxx = dp[0];
  for (int i = 1; i < n; i++) {
    if (a[i] == 1) {
      cnt++;
    }
    if (dp[i - 1] > 0) {
      dp[i] = dp[i - 1] + (a[i] == 1 ? -1 : 1);
    } else {
      dp[i] = a[i] == 0 ? 1 : 0;
    }
    maxx = std::max(maxx, dp[i]);
  }
  if (cnt == n) {
    printf("%d\n", n - 1);
  } else {
    printf("%d\n", cnt + maxx);
  }
  return 0;
}
