#include<iostream>
#include<vector>
using namespace std;
int getc(int a,int b){
	if(a>=b)
		return a-b;
	return b-a;
}
int main(){
	int n;
	cin>>n;
	vector<int>si(1,-1);
	vector<int>pe(1,-1);
	for(int i=1;i<=n;++i){
		int x;
		cin>>x;
		if(x==1)
			pe.push_back(i);
		else
			si.push_back(i);
	}
	n=pe.size()-1;
	int m=si.size()-1;
	int dp[n+1][m+1];
	for(int i=1;i<=n;++i)
		for(int j=0;j<=m;++j)
			dp[i][j]=100000000;
	for(int j=0;j<=m;++j)
		dp[0][j]=0;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
			dp[i][j]=min(dp[i][j-1],dp[i-1][j-1]+getc(si[j],pe[i]));
	int minv=100000000;
	for(int i=1;i<=m;++i)
		minv=min(minv,dp[n][i]);
	cout<<minv<<endl;
}