#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int conv[] = {1, -1};
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  int x = count(arr, arr + n, 1);
  int dp[n];
  dp[0] = conv[arr[0]];
  for (int i = 1; i < n; i++)
    dp[i] = max(dp[i - 1] + conv[arr[i]], conv[arr[i]]);
  cout << x + *max_element(dp, dp + n) << endl;
}
