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

public class Problem {
    static int Mod = 1000000007;

    public static void main(String[] args) {
        MyScanner scan = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
      //int t = scan.nextInt();
     int t=1;
        while (t-- > 0) {
         int p=scan.nextInt();
         int a[]=new int[p];
         ArrayList<Integer> zero = new ArrayList<>();
         ArrayList<Integer> one = new ArrayList<>();
         for(int i=0;i<p;i++){
           a[i]=scan.nextInt();
           if(a[i]==0)
           zero.add(i);
           else one.add(i);
         }

         int n=one.size();
         int m=zero.size();
         long dp[][]=new long[n+1][m+1];
        for(long i[] : dp){
            Arrays.fill(i,-1);
        }
        out.println(solve(n,m,one,zero,dp));
     //  out.println(Integer.MIN_VALUE);
       }
        out.close();
    }


    static long solve(int n, int m, ArrayList<Integer> one, ArrayList<Integer> zero,long dp[][]){
       if(n==0)
       return dp[n][m]=0l;
       if(m==0)
       return dp[n][m]= Integer.MAX_VALUE;
       if(dp[n][m]!=-1)
       return dp[n][m];

       return dp[n][m]= Math.min( solve(n-1,m-1,one,zero,dp) + (long)Math.abs(one.get(n-1)-zero.get(m-1)) , solve(n,m-1,one,zero,dp) );
       

    }

    static class Pair {
        long l;
        long r;

        Pair(long l, long r) {
            this.l = l;
            this.r = r;
        }
        
        @Override
        public String toString() {
            return "Pair [l=" + l + ", r=" + r + "]";
        }
    
        @Override
        public int hashCode() {
            final int prime = 31;
            int result = 1;
            result = prime * result + (int) (l ^ (l >>> 32));
            result = prime * result + (int) (r ^ (r >>> 32));
            return result;
        }

        @Override
        public boolean equals(Object obj) {
            if (this == obj)
                return true;
            if (obj == null)
                return false;
            if (getClass() != obj.getClass())
                return false;
            Pair other = (Pair) obj;
            if (l != other.l)
                return false;
            if (r != other.r)
                return false;
            return true;
        }    
        

    }


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

    public static void sort(long[] array) {
        ArrayList<Long> copy = new ArrayList<>();
        for (Long i : array)
            copy.add(i);
        Collections.sort(copy);
        for (int i = 0; i < array.length; i++)
            array[i] = copy.get(i);
    }
    
    public static void sort(double[] array) {
        ArrayList<Double> copy = new ArrayList<>();
        for (Double i : array)
            copy.add(i);
        Collections.sort(copy);
        for (int i = 0; i < array.length; i++)
            array[i] = copy.get(i);
    }

    public static long gcd(long a,long b)
    {
        if (b == 0)
            return a;
        return gcd(b, a % b); // gcd(a,b) = gcd(a-b,b) or gcd(a,b) = gcd(b,a%b) where a>b
    }

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

    static long power(long x, long y) {
        long temp;
        if (y == 0) // a^b= (a^b/2)^2 if b is even
            return 1; // = (a*a^(b-1)) if b is odd
        temp = power(x, y / 2);
        if (y % 2 == 0)
            return temp * temp;
        else
            return x * temp * temp;
    }

    static long mod(long x) {
        return ((x % Mod + Mod) % Mod);
    }

    static long add(long a, long b) {
        return mod(mod(a) + mod(b));
    }

    static long mul(long a, long b) {
        return mod(mod(a) * mod(b));
    }

    static long pow(long x, long y, int p) {
        long res = 1; // Initialize result
        x = x % p; // Update x if it is more than or equal to p

        if (x == 0)
            return 0; // In case x is divisible by p;

        while (y > 0) {
            // If y is odd, multiply x with result
            if ((y & 1) != 0)
                res = (res * x) % p;

            // y must be even now
            y = y >> 1; // y = y/2
            x = (x * x) % p;
        }
        return res;
    }

}

class MyScanner {
    BufferedReader br;
    StringTokenizer st;

    public MyScanner() {
        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());
    }

    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;
    }

}
