#include <bits/stdc++.h>
using namespace std;
int n, a[101], v[102], k = 0, k1 = 0, mx[101], mn[101], p = 0;
int main() {
  cin >> n;
  v[0] = 0;
  for (int i = 1; i <= n; ++i) {
    mn[i] = 102;
    mx[i] = 0;
    cin >> a[i];
    if (a[i] == 0) {
      v[i] = v[i - 1] + 1;
      k1++;
    } else {
      v[i] = v[i - 1] - 1;
      k++;
    }
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= i; ++j) p = max(p, v[i] - v[j]);
  if (k == n)
    cout << n - 1;
  else {
    if (k1 == n)
      cout << n;
    else
      cout << k + p;
  }
  return 0;
}
