#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int arr[109];
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    cin >> arr[i];
    if (arr[i]) ++ans;
  }
  int cnt = ans;
  int ori = ans;
  if (ans < N) {
    for (int i = 0; i < N; ++i) {
      if (arr[i]) {
        if (cnt - 1 < ori) {
          cnt = ori;
          continue;
        } else
          cnt--;
      } else {
        ++cnt;
        ans = max(ans, cnt);
      }
    }
  } else
    ans--;
  cout << ans;
  return 0;
}
