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.
/***********************************************************************************************
/                                                                                              /
/                                      SUBMITTED BY:                                           /
/                                     SAUMITRA SHUKLA                                          /
/                                                                                              /
/                                                                                              /
***********************************************************************************************/


#include<bits/stdc++.h>
using namespace std;

#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define pub push_back
#define pob pop_back
#define sz size()
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<vector<int>>
#define umi unordered_map<int,int>
#define usi unordered_set<int>
#define minheap priority_queue<int,vector<int>,greater<int>>
#define maxheap priority_queue<int> 
#define N 1000005
#define mod = 1000000007;
#define nMax = 200010;
/*....Lambda Expression Implementation....
     
    auto mycmp = [](pii &a, pii &b){return a.second<b.second;};
    priority_queue<pii,vector<pii>,decltype(mycmp)> pq(mycmp);
    pq.push({10,3});
    pq.push({2,15});
    pq.push({3,9});
    while(!pq.empty()){
        cout<<pq.top().second<<" ";
        pq.pop();
    }     
*/

/*
int dx[8]={-1,-1,-1,1,1,1,0,0};
int dy[8]={1,-1,0,1,0,-1,1,-1};

bool prime[N];

int gcd(int a,int b){
    if(b==0)
    return a;
    return gcd(b,a%b);
}

ll fastpower(ll a, ll n, ll modu){
    ll res = 1;
    while (n){
        if(n % 2){
            res = (res * a) % modu;
            n--;
        }
        else{
            a = (a * a) % modu;
            n = n/2;
        }
    }
    return res;
}
void seive(int n){
    fill(prime,prime+n+1,true);
    for(int i=2;i<n+1;i++){
        if(prime[i]){
            for(int j=i*i;j<n+1;j+=i)
            prime[j]=false;
        }    
    }
}

bool isW(vii &adj,int x,int y,int r,int c){
    return (x>0 && y>0 && x<r && y<c && adj[x][y]=='W');
}
bool isB(vii &adj,int x,int y,int r,int c){
    return (x>0 && y>0 && x<r && y<c && adj[x][y]=='B');
}
bool issafe(vii &adj,int x,int y,int r,int c){
    return (x>0 && y>0 && x<r && y<c && adj[x][y]=='.');
}

void dfs(vii &adj,int i,bool visited[]){
    visited[i]=true;
    for(auto x:adj[i])
    if(!visited[x])
    dfs(adj,x,visited);
}

ll fact(ll x){
    ll fac = 1;
    for(int i = 1; i <= x; i++){
        fac = (fac * i) % mod;
    }
    return fac;
}

void perms(vector<int> &res,int start,int end, set<vi> &ans){
    if(start==end)
    return;
    ans.insert(res);
    for(int i=start;i<end;i++){
        swap(res[i],res[start]);
        perms(res,start+1,end,ans);
        swap(res[i],res[start]);
    }
}
int indexof(int arr[],int k,int n){
    for(int i=1;i<=n;i++)
    if(arr[i]==k)
    return i;

    return -1;
}

void dfsisland(vector<vector<char>> &adj,int i,int j,int r,int c,int &score){
    if(i<0||j<0||i>=r||j>=c||adj[i][j]=='0')
    return;
    adj[i][j]='0';
    score++;
    dfsisland(adj,i+1,j,r,c,score);
    dfsisland(adj,i,j+1,r,c,score);
    dfsisland(adj,i-1,j,r,c,score);
    dfsisland(adj,i,j-1,r,c,score);
}

struct Node{
    int data;
    Node *left,*right;
    Node(int x){
        this->data=x;
        left=NULL;
        right=NULL;
    }
};
void traverse(Node* head){
    if(head==NULL)
    return;
    traverse(head->left);
    cout<<head->data;
    traverse(head->right);
}
Node* maketree(int arr[],int si,int ei,vector<int> &res,int depth=0){
    if(si>ei)
    return NULL;

    int el=INT_MIN,id=101;
    for(int i=si;i<=ei;i++){
        if(el<arr[i]){
            el=arr[i];
            id=i;
        }
    }
    Node* root = new Node(el);

    root->left=maketree(arr,si,id-1,res,depth+1);
    res.push_back(depth);
    root->right=maketree(arr,id+1,ei,res,depth+1);

    return root;
}

bool check(vector<int> adj[],int i,int val[],bool visited[],int col=0){
    visited[i]=true;
    val[i]=col;
    for(auto x:adj[i]){
        if(!visited[x]){
            if(!check(adj,x,val,visited,col^1))
                return false;
        }
        else if(val[i]==val[x])
            return false;
           
    }
    return true;
}
struct LLNode{
    int data;
    LLNode* next;
    LLNode(int data){
        this->data = data;
        this->next=NULL;
    }
};

int digits(int x){
    int val=0;
    while(x!=0){
        x/=10;
        val++;
    }
    return val;
}

void addedge(vector<int> adj[], int u, int v){
    adj[u].pub(v);
}*/


void solve(){
    int n;
    cin >> n;
    bool ok[n], done[n];
    fill(ok, ok + n, false);
    memset(done, false, n);
    vector<int> vis, n_vis;
    for(int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if(x == 1){
            vis.pub(i);
            done[i] = true;
        }    
        else{
            ok[i] = true;
            n_vis.pub(i);
        }
    }
    sort(vis.begin(),vis.end());
    sort(n_vis.begin(), n_vis.end());
    int len[n] = {0};
    for(int i = 1; i < n; i++){
        for(auto x : vis){
            if(done[x] == false)
            continue;
            for(auto y : n_vis){
                if(ok[y] && abs(x - y) == i)
                {
                    len[i]++;
                    ok[y] = false;
                    done[x] = false;
                    break;
                }
            }
        }
    }
    int res = 0;
    for(int i = 0; i < n; i++) {
        res += i * len[i];
    }    
    cout << res;


    

}

int main(){
    /*int t;
    cin >> t;
    while (t--) {
        solve();
        cout << '\n';
    }
    */
   solve();
}    