#include <bits/stdc++.h>
using namespace std;
int main() {
  int arr[1000000];
  int n;
  cin >> n;
  int x, sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (x == 1)
      arr[i] = -1;
    else
      arr[i] = 1;
    sum += x;
  }
  int max1 = arr[0], max2 = arr[0];
  for (int i = 1; i < n; i++) {
    max1 = max(arr[i], arr[i] + max1);
    max2 = max(max1, max2);
  }
  cout << sum + max2;
  return 0;
}
