#include <bits/stdc++.h>
using namespace std;
int a[105];
int dp[105], b[105];
int main() {
  int n, ans = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    ans += a[i];
    if (a[i])
      b[i] = -1;
    else
      b[i] = 1;
  }
  dp[1] = b[1];
  int sum = dp[1];
  for (int i = 2; i <= n; ++i) {
    if (dp[i - 1] < 0)
      dp[i] = b[i];
    else
      dp[i] = dp[i - 1] + b[i];
    sum = max(dp[i], sum);
  }
  printf("%d\n", ans + sum);
  return 0;
}
