#include <bits/stdc++.h>
long long cmpfunc(const void *a, const void *b) {
  return *(long long *)a - *(long long *)b;
}
int main(int argc, char **argv) {
  int n, i, j;
  scanf("%d", &n);
  int a[n + 1];
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  int original0 = 0, original1 = 0;
  int after_flip_1cnt[n + 1], after_flip_0cnt[n + 1];
  for (i = 1; i <= n; i++) {
    after_flip_1cnt[i] = 0;
    after_flip_0cnt[i] = 0;
    if (a[i] == 0)
      original0++;
    else
      original1++;
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= i; j++) {
      if (a[j] == 1)
        after_flip_0cnt[i]++;
      else
        after_flip_1cnt[i]++;
    }
  }
  int max1 = 0;
  if (original0 == 0) {
    printf("%d\n", n - 1);
    return 0;
  }
  if (original1 == 0) {
    printf("%d\n", n);
    return 0;
  }
  max1 = original1 + 1;
  for (i = 1; i <= n - 1; i++) {
    for (j = i + 1; j <= n; j++) {
      int k = original1 - (after_flip_0cnt[j] - after_flip_0cnt[i]);
      k += after_flip_1cnt[j] - after_flip_1cnt[i];
      if (k > max1) max1 = k;
    }
  }
  printf("%d\n", max1);
  return 0;
}
