#include <bits/stdc++.h>

using namespace std;

int dp[5005][5005];

int main(){
    int n; cin >> n;
    vector<int> a,b;
    for(int i=0,c;i<n;i++){
        cin >> c;
        if(c){
            a.push_back(i);
        }
        else{
            b.push_back(i);
        }
    }
    memset(dp,0x3f,sizeof(dp));
    dp[0][0] = 0;
    for(int i=0;i<b.size();i++){
        for(int j=0;j<=a.size();j++){
            if(j<a.size())
                dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j]+abs(b[i]-a[j]));
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
        }
    }
    cout << dp[b.size()][a.size()] << endl;
    return 0;
}