#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl "\n"
#define quick ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ALL(x) x.begin(),x.end()
#define SORT(x) sort(ALL(x))
#define FOR(a,b,c) for(ll (a)= (b);(a)<(c);++(a))
#define REP(a,b) FOR(a,0,b)
#define mp make_pair
#define pb push_back
#define pll pair<ll,ll>
#define f first
#define s second
ll t = 1;

template <class myType>
void print_arr(myType &arr, ll L, string sep){
    REP(i,L){
        cout << arr[i];
        if (i < L-1){
            cout << sep;
        }
    }
    cout << endl;
    return;
}

/*

*/

void solve(){
    int n;
    cin >> n;
    vector<int> a(n+1);
    REP(i,n) cin >> a[i+1];
    vector<int> pos;
    for(int i = 1; i <= n; i++) {
        if (a[i] == 1) pos.pb(i);
    }
    vector<vector<int>> dp(pos.size()+1, vector<int> (n+1,1e9));
    REP(i,n+1) dp[0][i] = 0;
    for (int i = 1; i <= pos.size(); i++) {
        for (int j = 1; j <= n; j++) {
            dp[i][j] = min(dp[i][j],dp[i][j-1]);
            if (a[j] == 1) continue;
            dp[i][j] = min(dp[i][j],dp[i-1][j-1] + abs(pos[i-1]-j));
            //cout << i << " " << j << " " << dp[i][j] << endl;
        }
    }
    int ans = 1e9;
    REP(i,n+1) {
        ans = min(ans,dp[pos.size()][i]);
    }
    cout << ans << endl;
    return;
}


int main(){  
    quick;
    //cin >> t;
    while (t--) solve();
    return 0;
}
