#include <bits/stdc++.h>
using namespace std;
long long max(long long a, long long b) { return (a > b) ? a : b; }
long long min(long long a, long long b) { return (a < b) ? a : b; }
signed main() {
  long long t = 1;
  while (t--) {
    long long n;
    cin >> n;
    long long a[n];
    long long ans = 0, cur = 0;
    for (long long i = 0; i < n; i++) {
      cin >> a[i];
      if (a[i] == 1) cur++;
    }
    for (long long i = 0; i < n; i++) {
      for (long long j = i; j < n; j++) {
        long long rr = 0, tt = 0;
        for (long long k = i; k < j + 1; k++) {
          if (a[k] == 1)
            rr++;
          else
            tt++;
        }
        ans = max(cur - rr + tt, ans);
      }
    }
    cout << ans;
  }
}
