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.
                              /*WIWIWH*/
                      
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
typedef long long ll;
ll min(ll a, ll b){
                if(a<b)
                return a;
                else
                return b;
}
ll dp[5001][5001];
//dp[i][j] denotes person at index i is seated at chair at j
//and all 0 to i-1 persons are already seated optimally
vector<int> one,zero;
ll calc(ll i, ll j){
  //j = position of zero
  //i = position of one;
  if(i == one.size())
  return 0;
  if(j == zero.size()) //not a valid answer bcz persons are  still there
    return 2 * 1e18 + 1;       //standing and chairs are exhausted

  if(dp[i][j] != -1)
    return dp[i][j];

  int possibility1 = calc(i+1,j+1) + abs(one[i] - zero[j]);
  //means one[i]th person chooses chair at index zero[j] and 
  //our search space now reduces to find from i+1th person and j+1th chair

  int possibility2 = calc(i,j+1);
  //person i refuses to sit at chair j so  answer now is answer for ith person till end from 
  //j+1th chair till end
  //start placing ith person from j+1th chair
  //actually dp[i][j] is optimal answer for ith to last  person with available chairs from jth to zero.size()
  //then our final answer will be at dp[0][0]
  //bcz we want from starting person with all the chairs available to sit

  dp[i][j] = min(possibility1,possibility2);
  //It's like ith person went in the future and saw what will cost him the minimum 
  //sum if he will sit on the jth chair then he calculated future ans from i+1th and j+1th 
  //and if we will not sit on jth chair instead choose from j+1th chair
  //now if ith person rejects jth chair it won't we there  to sit 
  //for any of i+1th to nth person so he calculated (i,j+1);
  //we are calculating ans backward
  return dp[i][j];
}
void solve(){
int n;
cin>>n;
int x;
memset(dp,-1,sizeof(dp));
for(int i = 0; i<n;i++){
  cin>>x;
  if(x)
    one.pb(i);
  else
    zero.pb(i);
  // Eg. 12
  // 0 0 1 1 0 1 1 0 1 1 0 0
  // we need to place all the ones at some positions 
  // where zeros are kept such that sum of abs difference is minimum
  // observations 1 :
  // indexes at which one occur are = 2, 3, 5, 6, 8, 9
  // indexes at which zero occur are= 0, 1, 4, 7, 10, 11
  //now since we are humans we know first one must come at index 0 or 1 
  //but WTLOG let we choose to place first one at index 4 
  //then we know for sure that second one which is at index 3 must be placed
  //after index 4 because if the person at index 3 finds a vacant seat that is
  //to the left of person at index 2 then why would not person at 2 go and 
  //sit there because it is nearer to person at 2 than person at 3.
  //so if we are considering that 1st person is seated at position x then 
  //to find optimal answer we must consider that 2nd person will be seated 
  //at any index of zero that is after the chosen index of zero.
 //we are at first index of 0(0) and first index of 1(2)
}
if(one.size() == 0)
{
                cout<<"0";
                return;
}
cout<<calc(0,0);
}
int main(){
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    int t=1;
    //cin>>t;
    while(t--){
    solve();
    cout<<"\n";
    }
    return 0;
  }    