#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define vpii vector<pair<int,int>>
#define pii pair<int,int>
#define ff first
#define ss second
#define print(x) cout<<x<<endl
#define printt(x,y) cout<<x<<" "<<y<<"\n"
#define pb push_back
#define all(v) v.begin(),v.end()
#define sz(x) (int)x.size()
#define vvi vector<vector<int>>
#define maxq priority_queue<int>
#define minq priority_queue<int,vector<int>,greater<int>>
const int mod = 1e9 + 7;
const int N = 200005;

int dp[5005][5005];
vi a, b;
int sol(int i, int j) {

    if (i == sz(a))
        return 0;

    if (j == sz(b))
        return 1e9;

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

    int ans = 1e9;

    ans = min(ans, abs(a[i] - b[j]) + sol(i + 1, j + 1));

    ans = min(ans, sol(i, j + 1));

    return dp[i][j] = ans;
}

void solve() {

    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        int u;
        cin >> u;
        if (u == 1)
            a.pb(i);
        else
            b.pb(i);
    }
    memset(dp, -1, sizeof(dp));
    int ans = sol(0, 0);

    print(ans);

}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
}