// Created by ash_98
 
#include<bits/stdc++.h>
using namespace std;
 
#define mx 5005
#define ll long long
#define mod 1000000007
 
int ar[mx];
char ch[mx];
int n,m,ii,k;
int dp[mx][mx];
int vis[mx][mx];
vector<int>v;

int func(int i,int prv)
{
	if(i==k)return 0;
	if(prv>n)return mx*mx;
	if(vis[i][prv]==ii)return dp[i][prv];
	vis[i][prv]=ii;
	int re=func(i,prv+1);
	if(!ar[prv])re=min(re,func(i+1,prv+1)+abs(prv-v[i]));
	return dp[i][prv]=re;
}
 
void solve()
{
	scanf("%d",&n);
	v.clear();
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&ar[i]);
		if(ar[i])v.push_back(i);
	}
	ii++;
	k=v.size();
	printf("%d\n",func(0,1));


}
 
int main()
{
	int t=1;
	//scanf("%d",&t);
	while(t--)solve();
	return 0;
}