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.
#include<bits/stdc++.h>
// #include <boost/functional/hash.hpp>
using namespace std;

#define Ff(i,a,b) for(i=a;i<b;i++)
#define Fb(i,a,b) for(i=a-1;i>=b;i--)
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define ff first
#define ss second
#define PI 2*asin(1)
#define all(x) x.begin(),x.end()
#define trav(x) for(auto& i:x)
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define spc ' '
#define nO {cout<<"NO\n"; return;}
#define yES {cout<<"YES\n"; return;}
#define oNE {cout<<-1<<endl; return;}

#define int long long

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<long long> vll;
typedef map<int, int> mi;
typedef map<long long, long long> mll;
typedef unordered_map<int, int> umi;
typedef unordered_map<long long, long long> umll;
typedef set<int> si;
typedef set<long long> sll;
typedef unordered_set<int> usi;
typedef unordered_set<long long> usll;

const ll N = 1e9 + 7;

// #define int long long

void sub() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output2.txt", "w", stdout);
#endif
}

// check(int a) {
//     int g = sqrt(a);
//     if (g * g == a) return 1;
//     return 0;
// }


// int bs(vi &a, int l, int r, int z) {
//     int m;
//     r--;
//     int y = r + 1;
//     int h = a[r + 1];
//     int c;
//     while (l <= r) {
//         m = (l + r) / 2;
//         if (h - a[m] == z) return y - m + 1;
//         else if (h - a[m] > z) l = m + 1;
//         else {c = m; r = m - 1;}
//     }
//     return y - c + 1;
// }
// void sieve (vector<pair<bool, int>>&pr, int n) {
//     // int n = 1000005;
//     int d = sqrt(n);
//     int i, j;
//     Ff(i, 2, n) {
//         if (pr[i].ff == 0) continue;
//         pr[i].ss = i;
//         for (j = 2 * i; j < n; j += i) {
//             pr[j].ff = 0;
//             if (pr[j].ss == 0) pr[j].ss = i;
//         }
//     }
// }
// void dfs(vector<string>&a, vector<string>&b, int n, int p, int q, bool&f, vector<vb>&v) {

//     if (f && a[p][q] != b[p][q])f = 0;
//     if (a[p][q] == '0')return;
//     v[p][q] = 1;
//     // if(f&&)
//     if (p - 1 >= 0 && v[p - 1][q] == 0) dfs(a, b, n, p - 1, q, f, v);
//     if (p + 1 < n &&  v[p + 1][q] == 0) dfs(a, b, n, p + 1, q, f, v);
//     if (q - 1 >= 0 && v[p][q - 1] == 0) dfs(a, b, n, p, q - 1, f, v);
//     if (q + 1 < n  && v[p][q + 1] == 0) dfs(a, b, n, p, q + 1, f, v);
// }

// int find(vector<string>&a, vector<string>&b, int n) {
//     vector<vb>v(n, vb(n, 0));
//     bool f = 1;
//     int i, j, k;
//     k = 0;
//     Ff(i, 0, n) {
//         Ff(j, 0, n) {
//             if (a[i][j] == '0' || v[i][j] == 1) continue;
//             f = 1;
//             dfs(a, b, n, i, j, f, v);
//             if (f) k++;
//         }
//     }
//     return k;
// }
void find(vi&a, vi&b, vi&c, int& k, int q, int p, vector<vi>&v) {
    // if (v[p].size() == 0) { return b[p];}
    int i;
    c[p] = k++;
    Ff(i, 0, v[p].size()) if (v[p][i] != q)find(a, b, c, k , p, v[p][i], v);
    Ff(i, 0, v[p].size()) if (v[p][i] != q)b[p] += b[v[p][i]];
    b[p] += a[p];
    // return b[p];
}


void solve() {
    int n, j, i, m , k;
    cin >> n;
    vi a(n);
    trav(a) cin >> i;
    vi one, zero;
    Ff(i, 0, n) { if (a[i])one.pb(i); else zero.pb(i);}
    int p = one.size();
    int q = zero.size();
    // cout << p << q << ' ';
    vector<vi>dp(p + 1, vi(q + 1, 0));
    Ff(i, 1, p + 1) {
        int mn = INT_MAX;
        Ff(j, i, q - p + 1 + i) {
            mn = min(mn, dp[i - 1][j - 1]);
            dp[i][j] = abs(one[i - 1] - zero[j - 1]) + mn;
            // cout << dp[i][j] << ' ';
        }
        // cout << endl;
    }
    k = INT_MAX;
    Ff(i, p, q + 1) k = min(k, dp[p][i]);
    cout << k << endl;
}









int32_t main() {
    FIO
    sub();
    int t = 1, s;
    // cin >> t;
    Ff(s, 1, t + 1)
    {
        // cout << "Case #" << s << ": " << solve() << endl ;
        solve();

    }
    return 0;
}



