#include <bits/stdc++.h>
using namespace std;
#define intt long long int
#define F first 
#define S second
#define pb push_back

int main()
{
    int n;cin>>n;
    int arr[n+1];
    
    vector<int> pos;
    pos.pb(-1);

    for(int i=1;i<=n;i++) {cin>>arr[i];if(arr[i]==1) pos.pb(i); }
    int m=pos.size()-1; // no. of 1s

    int dp[n][m+1]; // dp[][]== ith posn tak use karke , pehle j 1's ko shift karna hai .

    for(int i=0;i<=n;i++)dp[i][0]=0;
    for(int i=1;i<=m;i++) dp[0][i]=1e9;

    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {   
            if(arr[i]==1)
            dp[i][j]=dp[i-1][j];
            else 
            dp[i][j]=min(dp[i-1][j],dp[i-1][j-1]+abs(pos[j]-i));
        }
    }
    cout<<dp[n][m]<<endl;
    return 0;
}