#include <bits/stdc++.h>
int a[100];
int max(int, int);
int main() {
  int i, max_so_far, max_till_here, n, total;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", &a[i]);
  total = 0;
  for (i = 0; i < n; i++) total += a[i];
  for (i = 0; i < n; i++) a[i] = (a[i] == 0) ? 1 : -1;
  max_so_far = max_till_here = a[0];
  for (i = 1; i < n; i++) {
    max_till_here = max(max_till_here + a[i], a[i]);
    max_so_far = max(max_so_far, max_till_here);
  }
  printf("%d\n", total + max_so_far);
  return 0;
}
int max(int a, int b) { return (a > b) ? a : b; }
