#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, A[10000], count = 0, i, j, B[10000], Max[10000], ans;
  cin >> N;
  for (i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i]) count++;
  }
  for (i = 0; i < N; i++) {
    if (i == 0 && A[i])
      B[i] = -1;
    else if (i == 0)
      B[i] = 1;
    else if (A[i])
      B[i] = B[i - 1] - 1;
    else
      B[i] = B[i - 1] + 1;
  }
  Max[N - 1] = B[N - 1];
  for (i = N - 2; i >= 0; i--) Max[i] = (B[i] > Max[i + 1]) ? B[i] : Max[i + 1];
  ans = 0;
  if (count == 0) ans = N;
  for (i = 0; i < N - 1; i++) {
    if (Max[i + 1] - B[i] > ans) ans = Max[i + 1] - B[i];
  }
  if (count != N)
    cout << count + ans;
  else {
    count--;
    cout << count;
  }
  return 0;
}
