There are n armchairs, numbered from 1 to n from left to right. Some armchairs are occupied by people (at most one person per armchair), others are not. The number of occupied armchairs is not greater than n/2.

For some reason, you would like to tell people to move from their armchairs to some other ones. If the i-th armchair is occupied by someone and the j-th armchair is not, you can tell the person sitting in the i-th armchair to move to the j-th armchair. The time it takes a person to move from the i-th armchair to the j-th one is |i - j| minutes. You may perform this operation any number of times, but these operations must be done sequentially, i. e. you cannot tell a person to move until the person you asked to move in the last operation has finished moving to their destination armchair.

You want to achieve the following situation: every seat that was initially occupied must be free. What is the minimum time you need to do it?

Input

The first line contains one integer n (2 ≤ n ≤ 5000) — the number of armchairs.

The second line contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 1). a_i = 1 means that the i-th armchair is initially occupied, a_i = 0 means that it is initially free. The number of occupied armchairs is at most n/2.

Output

Print one integer — the minimum number of minutes you have to spend to achieve the following situation: every seat that was initially occupied must be free.

Examples

Input


7
1 0 0 1 0 0 1


Output


3


Input


6
1 1 1 0 0 0


Output


9


Input


5
0 0 0 0 0


Output


0

Note

In the first test, you can perform the following sequence:

  1. ask a person to move from armchair 1 to armchair 2, it takes 1 minute; 
  2. ask a person to move from armchair 7 to armchair 6, it takes 1 minute; 
  3. ask a person to move from armchair 4 to armchair 5, it takes 1 minute. 



In the second test, you can perform the following sequence:

  1. ask a person to move from armchair 1 to armchair 4, it takes 3 minutes; 
  2. ask a person to move from armchair 2 to armchair 6, it takes 4 minutes; 
  3. ask a person to move from armchair 4 to armchair 5, it takes 1 minute; 
  4. ask a person to move from armchair 3 to armchair 4, it takes 1 minute. 



In the third test, no seat is occupied so your goal is achieved instantly.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;

public class Solve {

	static int mod = 1000000000 + 7;
	static int INF = 1000_000_00;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner();
		PrintWriter pw = new PrintWriter(System.out);
		int n = sc.nextInt();
		int a[] = sc.nextIntArray(n);
		ArrayList<Integer> ones = new ArrayList<Integer>();
		ArrayList<Integer> zeros = new ArrayList<Integer>();

		for (int i = 0; i < n; i++) {
			if (a[i] == 1)
				ones.add(i);
			if (a[i] == 0)
				zeros.add(i);
		}
		if (n == 2 && ones.size() > 0) {
			pw.println(1);
			pw.flush();
			return;
		}

		int sz0 = zeros.size();
		int sz1 = ones.size();

		int dp[][] = new int[sz1 + 1][sz0 + 1];

		for (int i = 0; i < sz1; i++)
			Arrays.fill(dp[i], INF);

		dp[0][0] = 0;
		Arrays.fill(dp[0], 0);

		for (int i = 1; i <= sz1; i++) {
			for (int j = 1; j <= sz0; j++) {
				if (i > j) {
					dp[i][j] = INF;
					continue;
				}
				int oneIndex = ones.get(i - 1);
				int zeroIndex = zeros.get(j - 1);
				int cost = Math.abs(oneIndex - zeroIndex);

				dp[i][j] = Math.min(dp[i][j - 1], cost + dp[i - 1][j - 1]);

			}
		}

		pw.println(dp[sz1][sz0]);

		// dp[i][j] = minimum distance we can have using first 1 ones and first j zeros

		pw.flush();

	}

	public static int primeFactors(int n) {
		int count = 0;
		// Print the number of 2s that divide n
		while (n % 2 == 0) {
			n /= 2;
		}

		if (n == 1)
			return 0;

		// n must be odd at this point. So we can
		// skip one element (Note i = i +2)
		for (int i = 3; i <= Math.sqrt(n); i += 2) {
			// While i divides n, print i and divide n
			while (n % i == 0) {
				n /= i;
				count++;
			}
		}

		if (n > 1)
			count++;

		return count;

	}

	static int gcd(int a, int b) {
		if (a == 0)
			return b;
		if (b == 0)
			return a;

		return gcd(b, a % b);

	}

	public static int[] swap(int data[], int left, int right) {

		// Swap the data
		int temp = data[left];
		data[left] = data[right];
		data[right] = temp;

		// Return the updated array
		return data;
	}

	static long nCrModp(int n, int r, int p) {
		if (r > n - r)
			r = n - r;

		// The array C is going to store last
		// row of pascal triangle at the end.
		// And last entry of last row is nCr
		int C[] = new int[r + 1];

		C[0] = 1; // Top row of Pascal Triangle

		// One by constructs remaining rows of Pascal
		// Triangle from top to bottom
		for (int i = 1; i <= n; i++) {

			// Fill entries of current row using previous
			// row values
			for (int j = Math.min(i, r); j > 0; j--)

				// nCj = (n-1)Cj + (n-1)C(j-1);
				C[j] = (C[j] + C[j - 1]) % p;
		}
		return C[r];
	}

	static void sort(int[] a) {
		ArrayList<Integer> l = new ArrayList<>();
		for (int i : a)
			l.add(i);
		Collections.sort(l);
		for (int i = 0; i < a.length; i++)
			a[i] = l.get(i);
	}

}

class Pair implements Comparable<Pair> {
	int tower;
	int value = 0;

	Pair(int x, int y) {
		tower = x;
		value = y;
	}

	public int compareTo(Pair o) {
		return this.value - o.value;
	}

}

class Scanner {
	BufferedReader br;
	StringTokenizer st;

	Scanner() {
		br = new BufferedReader(new InputStreamReader(System.in));
	}

	String next() throws IOException {
		while (st == null || !st.hasMoreElements())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}

	int nextInt() throws NumberFormatException, IOException {
		return Integer.parseInt(next());
	}

	int[] nextIntArray(int n) throws NumberFormatException, IOException {
		int a[] = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = Integer.parseInt(next());
		return a;
	}

	long nextLong() throws NumberFormatException, IOException {
		return Long.parseLong(next());
	}

	long[] nextLongArray(int n) throws NumberFormatException, IOException {
		long a[] = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = Long.parseLong(next());
		return a;
	}

	double nextDouble() throws NumberFormatException, IOException {
		return Double.parseDouble(next());
	}
}
