#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define task "talltree"
#define pll pair<ll, ll>
#define pii pair<pll, pll>
#define fi first
#define se second
#define ull unsigned long long

using namespace std;
const ll mod = 1e12+7;
const ll N = 5005;

ll n, m, t, ans, k, a[N], b[N], tong,  cnt, q, c[N], st[N], dp[N][N];
vector<pll> adj[N];

string s[N];
ll pw(ll k, ll n)
{
    ll total = 1;
    for(; n; n >>= 1)
    {
        if(n & 1)total = total * k % mod;
        k = k * k % mod;
    }
    return total;
}

void sol()
{
    cin >> n;
    k = 1;
    for(int i = 1; i <= n; i ++)
    {
        cin >> a[i];
        if(a[i])b[++m] = i;
    }
    for(int i = 1; i <= m; i ++)dp[0][i] = mod;
    k = 0;
    for(int i = 1; i <= n; i ++)
    {
        if(a[i] == 0)
        {
            ++k;
            for(int j = m; j > 0; j --)
            {
                dp[i][j] = min(dp[i-1][j-1] + abs(i-b[j]), dp[i-1][j]);
            }
        }
        else for(int j = 1; j <= m; j ++)dp[i][j] = dp[i-1][j];
    }
    cout << dp[n][m];
}
int main()
{
    if(fopen(task".inp", "r")){
       freopen(task".inp", "r", stdin);
       freopen(task".out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int ntest = 1;
    //cin >> ntest;
    while(ntest -- > 0)
    sol();
}
/*
3 5
1 2 3 3 1
4 3 2 5 3
2 6 6 2 5
1 2 2 2
2 1 3 3
3 2 3 3
3 5 1 3
*/
