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.
//In rememberance to GOD//
//May GOD take care to me,my family and all the creatures//
#include<bits/stdc++.h>
using namespace std;
using namespace chrono;



#define ll long long
#define int ll   
#define mod ((int)1e9+7)
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define vc vector<char>
#define vpi vector<pii>
#define vpic vector<pair<int,char>>
#define vpid vector<pair<int,double>>
#define vb vector<bool>
#define vvb vector<vb>
#define vs vector<string>
#define INF (ll)1e15
#define all(x)  (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define pb push_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define eb emplace_back

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d) \
    for ( \
        auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); \
        blockTime.second; \
        debug("%s: %lld ms\n", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false \
    )

//fill memset iota function
// use 1ll<<number(left shift)

const int N=15*((int)1e6)+1;


// int primes[N];
// // // int spf[N];
// vector<int> pr;
// vi pr1;

// void sieve(){

//     // iota(spf+2,spf+N,2);

// 	for(ll i=2;i<N;i++){
// 		if(primes[i]==0){
// 		 	pr.eb(i);
// 			for(ll j=i*i;j<N;j+=i){
//                 // if(spf[j]==j)
//                 // spf[j]=i;
// 				primes[j]=1;
// 			}
// 		}
// 		primes[i]^=1;
// 	}



// }
// nloglogn




ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}
void swap(int &x, int &y) {int temp = x; x = y; y = temp;}
ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}
ll power(ll x, ll y) {ll res = 1;while (y > 0){ if (y & 1) res = (res*x)%mod;y = y>>1;x = x*x%mod;}return res;}
//avoid it in power of 2.
//logn implementation
//divisors in o(sqrt(n)) and no of divisors less than 2*(n^1/2);//128(max divisors for n<=1e5)
//for n>=1e5 no of divisors is less than n^1/3;
// use i&1 instead of i%2
//stoll convert string to integer(long long)
//  if(a>b) { return a/b+fun(b,a%b);} else return b/a+fun(a,b%a); technique of mod and minus similar answer but diffent time complexity.
// if(a>b) { return 1+fun(b,a-b);} else return 1+fun(a,b-a);
// class cmp { public:
//     bool operator()(const pair<int,pii> &p1,const pair<int,pii> &p2) const { if(p1.first!=p2.first) return p1.first>p2.first;else
//         {
//             if(p1.second.first!=p2.second.first)
//             {
//                 return p1.second.first>p2.second.first;
//             }
//             else
//             {
//                 return p1.second.second>p2.second.second;
//             }
            
//         }
        
//     }
 
// };
// instead of priority queue i use set defined with cmp class strictly using '=' sign in comparisons(work as multi set)
//erase function with values won't work
//to modify a set i use cmp class stictly without using '=' sign in comparions,example above!!!!  
//erase function with values will work
//sizeof terminate on spaces in charater array........
//prime gap o((logn)^2) approx
//prime gap till 1e9 is 282
//prime gap<sqrt(n)
//no of primes N/lnN till N
//we just have to remove a single element in order to remove equal sum partition subsequences and that too having minimun num of multiplication of two.
//topological sorting in queue(element with 0 indegree) 







/////////////////////////////////////// CODE ////////////////////////////////////////////////


// int dx[] = {1,0,-1,0};
// int dy[] = {0,1,0,-1};
// int dr[] = {1,1,0,-1,-1,-1, 0, 1}; // trick to explore an implicit 2D grid
// int dc[] = {0,1,1, 1, 0,-1,-1,-1};





// vi adj[N];
// int visited[N];
// int par[N];
// int d[N];
// int dp[N];



// int binary_searching(vi &v,int num,int sum)
// {
//     int n=v.size();
//     int start=0;
//     int end=n-1;

//     while(start+1!=end)
//     {
//         int mid=(start+end)/2;
//         if(sum-v[mid]>=num)
//         {
//             start=mid;
//         }
//         else
//         end=mid;
//     }

//     if(sum-v[start]==num)
//     {
//         return start;
//     }
//     else
//     {
//         return -1;
//     }
    

    
    
// }



// int index=-1;




// void dfs(int current,double & maxi,vector<double>&v)
// {
//     visited[current]=true;

//     for(auto x:adj[current])
//     {
//         int node=x.first;
//         int weight=x.second;

//         maxi=max(maxi,(v[current]+v[node])/weight);
//         if(!visited[node])
//         {
//             dfs(node,maxi,v);
//         }


//     }

// }

// int query(int l,int r)
// {
//     cout<<"? "<<l<<" "<<r<<'\n';
//     fflush(stdout);
//     int x;
//     cin>>x;

//     return x;
// }


// int binary_searching(int n,int k)
// {
//     int start=0;
//     int end=n;

//     while(start+1!=end)
//     {
//         int mid=(start+end)/2;
//         int o=query(1,mid);
//         int z=mid-o;

//         if(z>=k)
//         {
//             end=mid;
//         }
//         else
//         {
//             start=mid;
//         }
        
//     }
//     return end;
// }




    




void solve()
{
    int n;
    cin>>n;


    vi v(n);
    vi f,e;
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
        if(v[i]==1)
        {
            f.eb(i);
        }
        else
        {
            e.eb(i);
        }
    }

    n=f.size();
    int m=e.size();


    vvi dp(n+1,vi (m+1,INF));
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=m;j++)
        {
            if(i==0)
            {
                dp[i][j]=0;
            }
            else if(j==0)
            {
                dp[i][j]=INF;
            }
            else
            {
                if(j>=i)
                {
                    dp[i][j]=min(dp[i-1][j-1]+abs(f[i-1]-e[j-1]),dp[i][j-1]);
                }
            }
        }
    }


    cout<<dp[n][m]<<'\n';
































}








int32_t main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    // freopen("input.txt","rt",stdin);
	// freopen("output.txt","wt",stdout);

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int t;
    // cin>>t;


    // sieve();

    
    t=1;

    
   

    

    for(int i=1;i<=t;i++)
    {
        solve();
        // IshanMakkar
        // time__("solve");
    }


    return 0;
}