// Arup Guha
// 10/12/2013
// Solution to UCF JV Practice Problem A: Flipping Game

import java.util.*;

public class a {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int n = stdin.nextInt();
		int[] array = new int[n];

		// Read initial.
		int init = 0;
		for (int i=0; i<n; i++) {
			array[i] = stdin.nextInt();
			init += array[i];
		}

		// Try each substring, and keep track of how much you can increase
		// the number of 1s from the initial.
		int bestAdd = 0;
		for (int start=0; start<n; start++) {

			// Just iterate the end of the substring and update current. If we
			// see a 0, we add 1 to our count, a 1 subtract one (since it's flipped).
			int cur = 0;
			for (int end=start; end<n; end++) {
				if (array[end] == 0)
					cur++;
				else
					cur--;

				// Just keep track of the best we've seen.
				if (cur > bestAdd)
					bestAdd = cur;
			}

		}

		// Annoying special case where we started with all 1s and must flip 1.
		if (init == n) init--;

		System.out.println(init+bestAdd);
	}
}