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

    public class Main {

	static FastScanner scn = new FastScanner();
	static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] HastaLaVistaLa) {
		// Running Number Of TestCases (t)
		int t = 1;
		while(t-- > 0)
			solve();
		out.close();
	}

	static long MOD = 998244353L;
	static long[][] dp;
	static long ans;
	static boolean[][] vis;
	public static void solve() {
		// We're Friends
		int n = scn.nextInt();
		int[] arr = scn.readIntArray(n);
		boolean[] vis = new boolean[n];
		Arrays.fill(vis, false);
		for(int i = 0; i < n; i++) if(arr[i] == 1) vis[i] = true;
		for(int i = 0; i < n; i++) {
			if(arr[i] == 1) {
				boolean flag = false;
				int k = i + 1;
				int j = i - 1;
				while(true) {
					if(j >= 0 && !vis[j]) {
						vis[j] = true;
						ans += (Math.abs(i - j));
						flag = true;
						break;
					}
					if(k < n && !vis[k]) {
						vis[k] = true;
						ans += (Math.abs(i - k));
						flag = true;
						break;
					}
					j--;
					k++;
				}
			}
		}
		out.println(ans);
	} 

	public static HashMap<Integer, List<Integer>> indexes(char[] ch, int n) {

		HashMap<Integer, List<Integer>> map = new HashMap<>();
		for(int i = 0; i < n; i++) {
			int c = ch[i] - 'a';
			if(map.containsKey(c)) {
				List<Integer> temp = map.get(c);
				temp.add(i);
				map.put(c, temp);
			}else {	
				List<Integer> list = new ArrayList<>();
				list.add(i);
				map.put(c, list);
			}
		}
		return map;
	}

	public static boolean isPrime(int p) {
		int l = (int) Math.sqrt(p);
		for(int i = 2; i <= l; i++) {
			if(p % i == 0) return false;
		}
		return true;
	}
 
	public static long binpow(long n, long m, long mod) {
	        long res = 1;
	        while (m > 0) {
	            if (m % 2 == 1) {
	                res *= n;
	                res %= mod;
	                m--;
	            }
	            n *= n;
	            n %= mod;
	            m /= 2;
	        }
	        return res;
    	}

    	// To calculate the Factorial in Combinatorics Problems
	static long[] fact;
    	public static void factorial(int n) {
    		fact = new long[n];
		Arrays.fill(fact, 1);
		for(int i = 1; i < n; i++) fact[i] *= ( ((long) i * (fact[i-1])) % MOD);
    	}

	public static HashMap<Character, Integer> CountCharFrequencies(char[] arr) {
		HashMap<Character, Integer> map = new HashMap<>();
		for (char i : arr) if (map.containsKey(i)) map.put(i, map.get(i) + 1); else map.put(i, 1);
		return map;
	}

	public static HashMap<Integer, Integer> CountIntFrequencies(int[] arr) {
		HashMap<Integer, Integer> map = new HashMap<>();
		for (int i : arr) if (map.containsKey(i)) map.put(i, map.get(i) + 1); else map.put(i, 1);
		return map;
	}

	// Number of Divisor for Range [l, r]
	public static int[] NumberOFDivisors(int l, int r) {
		int[] arr = new int[l - r + 1];
		for(int i = l; i <= r; i++) for(int j = i; j <= r; j += i) arr[j]++;
		return arr;
	}

	public static int LowerBound(int a[], int x) { // x is the target value or key

		  int l = -1,r = a.length;
		  while(l + 1 < r) {
		    int m = (l + r) >>> 1;
		    if(a[m] >= x) r = m;
		    else l = m;

		  }
		  return r;
	}

	static boolean[] prime;
	public static void sieveOfEratosthenes(int n) {

        	prime = new boolean[n+1];
	        for(int i=0;i<n;i++)
	            prime[i] = true;
	        for(int p = 2; p*p <=n; p++) {
	            if(prime[p] == true) {
	                for(int i = p*p; i <= n; i += p)
	                    prime[i] = false;
	            }
	        }
    	}

	public static int UpperBound(int[] a, int x) {// x is the key or target value

		    int l = -1,r = a.length;
		    while(l + 1 < r) {
		       int m = (l + r) >>> 1;
		       if(a[m] <= x) l = m;
		       else r = m;
		    }
		    return l + 1;
	}

    	public static long lcm(long a, long b) {
		return (a * b) / gcd(a, b);
	}

	public static long gcd(long a, long b) {
		if (a == 0)
			return b;
		return gcd(b % a, a);
	}

	public static void sort(int[] arr) {
		Random rand = new Random();
		int n = arr.length;
		for(int i = 0; i<n; i++) {
			swap(arr, i, rand.nextInt(n));
		}
		Arrays.sort(arr);
	}

	public static void swap(int[] arr, int i, int j) {
		if(i!=j) {
			arr[i] ^= arr[j];
			arr[j] ^= arr[i];
			arr[i] ^= arr[j];
		}
	}
     
	public static void sortbyColumn(int[][] arr, int col) {
		Arrays.sort(arr, new Comparator<int[]>() {
			public int compare(final int[] entry1, final int[] entry2) {
				if (entry1[col] > entry2[col])
					return 1;
				else
					return -1;
			}
		});
	}

	public static void ArraySort2D(double[][] arr, int xy) {
		// xy == 0, for sorting wrt X-Axis
		// xy == 1, for sorting wrt Y-Axis
		Arrays.sort(arr, Comparator.comparingDouble(o -> o[xy]));
	}
     
	public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        int[] readIntArray(int n) {
        	int[] a = new int[n];
        	for(int i = 0; i < n; i++) a[i] = scn.nextInt();
        	return a;
        }
        long[] readLongArray(int n) {
        	long[] a = new long[n];
        	for(int i = 0; i < n; i++) a[i] = scn.nextLong();
        	return a;
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}