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.*;
import java.util.*;



public class A {

	static long modInverse(long a, long m) {
		long m0 = m;
		long y = 0, x = 1;

		if (m == 1)
			return 0;

		while (a > 1) {

			long q = a / m;

			long t = m;

			m = a % m;
			a = t;
			t = y;

			y = x - q * y;
			x = t;
		}

		if (x < 0)
			x += m0;

		return x;
	}

	static void pla() {

		int a = 0;
		int b = 2;
		int c = 0;
		int d = 0;

		a = (int) Math.pow(2, 32);

		c = a + b;
		b = c / a;
		d = a + b + c;

	}

	static int mod = (int) 1e9 + 7;

	static Scanner sc = new Scanner(System.in);
	static StringBuilder out = new StringBuilder();

	public static void main(String[] args) throws IOException {

		int t = 1;// sc.nextInt();

		while (t-- > 0) {

			A run = new A();

			run.run();

		}

		System.out.println(out);

	}

	public static int gcd(int a, int b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	public void run() throws IOException {

//	int k = sc.nextInt();

//		if(100%k==0)out.append((100/k)+"\n");
//		
//		else {
//			out.append(100+"\n");
//		}

//		int ans=(int)1e9;
//		for(int i=1;i<=k;i++) {
//			
//			
//			if(i*100%k==0) {
//				
//				ans=Math.min(ans,i*)
//				
//				
//			}
//			
//		}

//		
//		int ans = 100 - k;
//		if (k == 100)
//			out.append(1);
//		else {
//			int g = gcd(k, ans);
//			out.append((k / g) + (ans / g));
//		}
//		out.append("\n");
//		

//		int n = sc.nextInt();
//		int a[] = new int[n];
//		
//		for(int i=0;i<n;i++)a[i]=sc.nextInt();
//		int min = Integer.MAX_VALUE, mx = Integer.MIN_VALUE;
//		for (int i = 0; i < n; i++) {
//			min = Math.min(min, a[i]);
//			mx = Math.max(mx, a[i]);
//		}
//		int b[] = a.clone();
//		sort(b,n);
//		if (Arrays.equals(a, b)) {
//			out.append(0);
//		} else if (a[0] == min || a[n - 1] == mx) {
//			out.append(1);
//		} else if (a[0] == mx && a[n - 1] == min) {
//			out.append(3);
//		} else {
//			out.append(2);
//		}
//		out.append("\n");

		int n = sc.nextInt();

		int a[] = new int[n];

		TreeSet<Integer> ts = new TreeSet<>();

		ArrayList<Integer> a1 = new ArrayList<>();
		ArrayList<Integer> b = new ArrayList<>();
		for (int i = 0; i < n; i++) {

			a[i] = sc.nextInt();
			if (a[i] == 1)
				a1.add(i);
			else
				b.add(i);

		}

		int dp[] = new int[n];
		int sum = 0;

		memo = new int[n][n];

		for (int tem[] : memo)
			Arrays.fill(tem, -1);

		sum = solve(0, 0, a1, b);
		out.append(sum + "\n");
	}

	static int memo[][];

	static int solve(int i, int j, ArrayList<Integer> a, ArrayList<Integer> b) {

		if(i==a.size())return 0;
		if(a.size()-i>b.size()-j)return (int)1e9;
		if(j==b.size())return (int)1e9;
		if(memo[i][j]!=-1)return memo[i][j];
		int ans = (int) 1e9;

		
		
		

			ans = Math.min(solve(i + 1, j+1 , a, b) + Math.abs(a.get(i) - b.get(j)),solve(i,j+1,a,b));
		
		
		return memo[i][j]=ans;

	}

	static boolean check(int[] dp, int cnt) {

		int count = 0;

		for (int i = 0; i < dp.length; i++) {

			if (dp[i] == 1)
				count++;
		}

		return (count == cnt);

	}

	static void sort(int a[], int n) {

		ArrayList<Integer> al = new ArrayList<>();

		for (int i = 0; i < n; i++) {

			al.add(a[i]);
		}

		Collections.sort(al);

		for (int i = 0; i < n; i++) {

			a[i] = al.get(i);
		}
	}

	static void sort(long a[], int n) {

		ArrayList<Long> al = new ArrayList<>();

		for (int i = 0; i < n; i++) {

			al.add(a[i]);
		}

		Collections.sort(al);

		for (int i = 0; i < n; i++) {

			a[i] = al.get(i);
		}
	}

//	static Reader sc = new Reader();

	static class Reader {
		final private int BUFFER_SIZE = 1 << 16;
		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		public Reader() {
			din = new DataInputStream(System.in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public Reader(String file_name) throws IOException {
			din = new DataInputStream(new FileInputStream(file_name));
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public String readLine() throws IOException {
			byte[] buf = new byte[64]; // line length
			int cnt = 0, c;
			while ((c = read()) != -1) {
				if (c == '\n')
					break;
				buf[cnt++] = (byte) c;
			}
			return new String(buf, 0, cnt);
		}

		public int nextInt() throws IOException {
			int ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (neg)
				return -ret;
			return ret;
		}

		public long nextLong() throws IOException {
			long ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');
			if (neg)
				return -ret;
			return ret;
		}

		public double nextDouble() throws IOException {
			double ret = 0, div = 1;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();

			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (c == '.') {
				while ((c = read()) >= '0' && c <= '9') {
					ret += (c - '0') / (div *= 10);
				}
			}

			if (neg)
				return -ret;
			return ret;
		}

		private void fillBuffer() throws IOException {
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}

		private byte read() throws IOException {
			if (bufferPointer == bytesRead)
				fillBuffer();
			return buffer[bufferPointer++];
		}

		public void close() throws IOException {
			if (din == null)
				return;
			din.close();
		}
	}

}