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 CodeForces extends Functions {
    /*
        --> we have some index having 1 in it which are stored in ones.
        --> we have some index having 0 on it which are stored in ones.
        --> we need to select exactly one 0index for one 1index.
        --> so in total we need exactly freq of 1 numbers element from 0. to find this optimally , we do dp
     */
    static long[][] dp;
    private static void solve() {
        int n = sc.nextInt();
        int[] arr = sc.setintArray(n);
        List<Integer> ones = new ArrayList<>();
        List<Integer> zeros = new ArrayList<>();
        for(int i=0;i<n;i++)
            if(arr[i]==0)zeros.add(i);
            else ones.add(i);
        dp = new long[ones.size()][zeros.size()];
        for(int i=0;i<ones.size();i++)Arrays.fill(dp[i],-1);
        out.println(helper(0,0,ones,zeros));

    }
    private static long helper(int i,int j,List<Integer> ones,List<Integer> zeros){
        if(i==ones.size()) return 0;
        if(j==zeros.size()) return INT_MAX;
        if(dp[i][j]!=-1)return dp[i][j];
        long c1 = Math.abs(zeros.get(j) - ones.get(i)) + helper(i+1,j+1,ones,zeros);
        long c2 = helper(i,j+1,ones,zeros);
        return dp[i][j] = Math.min(c1,c2);
    }



    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        int testCase = 1;
//        testCase= sc.nextInt();
        while (testCase-->0) solve();
        long end = System.currentTimeMillis();
//        out.println("time took in ms : "+(end-start));
        sc.close();
        out.flush();
        out.close();
    }

    static Scanner sc = new Scanner(); // Input
    static  PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));  // output
}


class Functions {
    public static long mod = (long)1e9+7L;
    public static final int INT_MAX = Integer.MAX_VALUE;
    public static final int INT_MIN = Integer.MIN_VALUE;
    public static final long LONG_MAX = Long.MAX_VALUE;
    public static final long LONG_MIN = Long.MIN_VALUE;
    public static final double DOUBLE_MAX = Double.MAX_VALUE;
    public static final double DOUBLE_MIN = Double.MIN_VALUE;
    public static final String YES = "YES";
    public static final String NO = "NO";

    public static void sort(int[] a,boolean isAscending){
        ArrayList<Integer> temp = new ArrayList<>();
        for (int j : a) temp.add(j);
        sort(temp,isAscending);
        for(int i=0;i<a.length;i++)a[i] = temp.get(i);
    }

    public static void sort(List list,boolean isAscending){
        if(isAscending)
            Collections.sort(list);
        else Collections.sort(list,Collections.reverseOrder());
    }
    // euclidean algorithm
    public static long gcd(long a, long b) {
        // time O(max (loga ,logb))
        long x = Math.min(a,b);
        long y = Math.max(a,b);
        if (y % x == 0) return x;
        return gcd(y%x,x);
    }
    public static long lcm(long a, long b) {
        // lcm(a,b) * gcd(a,b) = a * b
        return (a / gcd(a, b)) * b;
    }

    public static long factorial(long n){
        long fact = 1L;
        for(int i=2;i<=n;i++)fact = (fact*i)%mod;
        return fact;
    }
    public static long firstDivisor(long n){
        if(n==1)return n;
        for(long i=2;i*i<=n;i++)
            if(n%i==0)return i;
        return -1;
    }
    public static long power(long x,long n){
        // calculate x^n %mod using binary exponentiation
        // time : O(logn)
        long ans = 1;
        while(n>0){
            if(n%2!=0){
                ans *= x;
                n--;
            }else {
                x *= x;
                n/=2;
            }
            x %=mod;
            ans %=mod;
        }
        return ans;
    }
    public  static int ncr(int n, int r){
        // time O(n+r)
        if (r > n)
            return 0;
        long[] inv = new long[r + 1];
        inv[1] = 1;
        // Getting the modular inversion
        // for all the numbers
        // from 2 to r with respect to m
        for (int i = 2; i <= r; i++) {
            inv[i] = mod - (mod / i) * inv[(int) (mod % i)] % mod;
        }
        int ans = 1;
        // for 1/(r!) part
        for (int i = 2; i <= r; i++) {
            ans = (int) (((ans % mod) * (inv[i] % mod)) % mod);
        }
        // for (n)*(n-1)*(n-2)*...*(n-r+1) part
        for (int i = n; i >= (n - r + 1); i--) {
            ans = (int) (((ans % mod) * (i % mod)) % mod);
        }
        return ans;
    }
    public static void reverseArray(int[] a){
        int left = 0;
        int right = a.length-1;
        while (left<right){
            int temp =a[left];
            a[left] = a[right];
            a[right] = temp;
            left++;
            right--;
        }
    }
}

class Scanner {
    private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    private StringTokenizer st = new StringTokenizer("");
    public String next(){
        while (!st.hasMoreTokens())
            try {
                st = new StringTokenizer(br.readLine());
            }catch (IOException e){
                e.printStackTrace();
            }
        return st.nextToken();

    }
    public int nextInt(){return Integer.parseInt(next());}
    public long nextLong(){return Long.parseLong(next());}
    public double nextDouble(){return Double.parseDouble(next());}
    public int[] setintArray(int n){
        int[] arr =new int[n];
        for(int i=0;i<n;i++)arr[i] = nextInt();
        return arr;
    }
    public long[] setlongArray(int n){
        long[] arr =new long[n];
        for(int i=0;i<n;i++)arr[i] = nextLong();
        return arr;
    }
    public int[][] set2DintArray(int row, int col){
        int[][] arr = new int[row][col];
        for(int i=0;i<row;i++)
            for(int j= 0;j<col;j++)
                arr[i][j] = nextInt();
        return arr;
    }
    public long[][] set2DlongArray(int row, int col){
        long[][] arr = new long[row][col];
        for(int i=0;i<row;i++)
            for(int j= 0;j<col;j++)
                arr[i][j] = nextLong();
        return arr;
    }
    public void close(){
        try{
            br.close();
        }catch (IOException e){
            e.printStackTrace();
        }
    }
}
