There are n armchairs, numbered from 1 to n from left to right. Some armchairs are occupied by people (at most one person per armchair), others are not. The number of occupied armchairs is not greater than n/2.

For some reason, you would like to tell people to move from their armchairs to some other ones. If the i-th armchair is occupied by someone and the j-th armchair is not, you can tell the person sitting in the i-th armchair to move to the j-th armchair. The time it takes a person to move from the i-th armchair to the j-th one is |i - j| minutes. You may perform this operation any number of times, but these operations must be done sequentially, i. e. you cannot tell a person to move until the person you asked to move in the last operation has finished moving to their destination armchair.

You want to achieve the following situation: every seat that was initially occupied must be free. What is the minimum time you need to do it?

Input

The first line contains one integer n (2 ≤ n ≤ 5000) — the number of armchairs.

The second line contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 1). a_i = 1 means that the i-th armchair is initially occupied, a_i = 0 means that it is initially free. The number of occupied armchairs is at most n/2.

Output

Print one integer — the minimum number of minutes you have to spend to achieve the following situation: every seat that was initially occupied must be free.

Examples

Input


7
1 0 0 1 0 0 1


Output


3


Input


6
1 1 1 0 0 0


Output


9


Input


5
0 0 0 0 0


Output


0

Note

In the first test, you can perform the following sequence:

  1. ask a person to move from armchair 1 to armchair 2, it takes 1 minute; 
  2. ask a person to move from armchair 7 to armchair 6, it takes 1 minute; 
  3. ask a person to move from armchair 4 to armchair 5, it takes 1 minute. 



In the second test, you can perform the following sequence:

  1. ask a person to move from armchair 1 to armchair 4, it takes 3 minutes; 
  2. ask a person to move from armchair 2 to armchair 6, it takes 4 minutes; 
  3. ask a person to move from armchair 4 to armchair 5, it takes 1 minute; 
  4. ask a person to move from armchair 3 to armchair 4, it takes 1 minute. 



In the third test, no seat is occupied so your goal is achieved instantly.
from collections import defaultdict, OrderedDict, Counter
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
# import numpy as np
from queue import Queue, PriorityQueue
from heapq import *
from statistics import *
from math import sqrt, log10, log2, log, gcd,ceil, floor
import fractions
import copy
from copy import deepcopy
import sys
import io

sys.setrecursionlimit(10000)
import math
import os
import bisect
import collections

mod = int(pow(10, 9)) + 7
import random
from random import *
import time
from time import time;
import timeit
from timeit import timeit

import itertools
from itertools import  combinations,permutations,combinations_with_replacement,product


def ncr(n, r, p=mod):
    num = den = 1
    for i in range(r):
        num = (num * (n - i)) % p
        den = (den * (i + 1)) % p
    return (num * pow(den,
                      p - 2, p)) % p


def normalncr(n, r):
    r = min(r, n - r)
    count = 1;
    for i in range(n - r, n + 1):
        count *= i;

    for i in range(1, r + 1):
        count //= i;
    return count


inf = float("inf")
adj = defaultdict(set)
visited = defaultdict(int)


def addedge(a, b):
    adj[a].add(b)
    adj[b].add(a)


def bfs(v):
    q = Queue()
    q.put(v)
    visited[v] = 1
    while q.qsize() > 0:
        s = q.get_nowait()
        print(s)
        for i in adj[s]:
            if visited[i] == 0:
                q.put(i)
                visited[i] = 1


def dfs(v, visited):
    if visited[v] == 1:
        return;
    visited[v] = 1

    print(v)
    for i in adj[v]:
        dfs(i, visited)


# a9=pow(10,6)+10
# prime = [True for i in range(a9 + 1)]
# def SieveOfEratosthenes(n):
#     p = 2
#     while (p * p <= n):
#         if (prime[p] == True):
#             for i in range(p * p, n + 1, p):
#                 prime[i] = False
#         p += 1
# SieveOfEratosthenes(a9)
# prime_number=[]
# for i in range(2,a9):
#     if prime[i]:
#         prime_number.append(i)
def reverse_bisect_right(a, x, lo=0, hi=None):
    if lo < 0:
        raise ValueError('lo must be non-negative')
    if hi is None:
        hi = len(a)
    while lo < hi:
        mid = (lo + hi) // 2
        if x > a[mid]:
            hi = mid
        else:
            lo = mid + 1
    return lo


def reverse_bisect_left(a, x, lo=0, hi=None):
    if lo < 0:
        raise ValueError('lo must be non-negative')
    if hi is None:
        hi = len(a)
    while lo < hi:
        mid = (lo + hi) // 2
        if x >= a[mid]:
            hi = mid
        else:
            lo = mid + 1
    return lo


def get_list():
    return list(map(int, input().split()))

def make_list(m):
    m+=list(map(int, input().split()))

def get_str_list_in_int():
    return [int(i) for i in list(input())]


def get_str_list():
    return list(input())


def get_map():
    return map(int, input().split())


def input_int():
    return int(input())


def matrix(a, b):
    return [[0 for i in range(b)] for j in range(a)]


def swap(a, b):
    return b, a


def find_gcd(l):
    a = l[0]
    for i in range(len(l)):
        a = gcd(a, l[i])
    return a;


def is_prime(n):
    sqrta = int(sqrt(n))
    for i in range(2, sqrta + 1):
        if n % i == 0:
            return 0;
    return 1;


def prime_factors(n):
    l=[]
    while n % 2 == 0:
        l.append(2)
        n//=2
    sqrta = int(sqrt(n))

    for i in range(3, sqrta + 1, 2):
        while n % i == 0:
            n//=i;
            l.append(i)
    if n>2:
        l.append(n)
    return l

def p(a):
    if type(a) == str:
        print(a + "\n")
    else:
        print(str(a) + "\n")


def ps(a):
    if type(a) == str:
        print(a)
    else:
        print(str(a))


def kth_no_not_div_by_n(n, k):
    return k + (k - 1) // (n - 1)


def forward_array(l):
    """
    returns the forward index where the elemetn is just greater than that element
    [100,200] gives [1,2]
    because element at index 1 is greater than 100 and nearest
    similarly if it is largest then it outputs n
    :param l:
    :return:
    """
    n = len(l)
    stack = []
    forward = [0] * n
    for i in range(len(l) - 1, -1, -1):
        while len(stack) and l[stack[-1]] < l[i]:
            stack.pop()
        if len(stack) == 0:
            forward[i] = len(l);
        else:
            forward[i] = stack[-1]
        stack.append(i)
    return forward;


def backward_array(l):
    n = len(l)
    stack = []
    backward = [0] * n
    for i in range(len(l)):
        while len(stack) and l[stack[-1]] < l[i]:
            stack.pop()
        if len(stack) == 0:
            backward[i] = -1;
        else:
            backward[i] = stack[-1]
        stack.append(i)
    return backward


def char(a):
    return chr(a + 97)


def get_length(a):
    return 1 + int(log10(a))


def issq(n):
    sqrta = int(n ** 0.5)
    return sqrta ** 2 == n;


def ceil(a,b):
    return int((a+b-1)/b)

def equal_sum_partition(arr,n):
    sum = 0
    for i in range(n):
        sum += arr[i]
    if sum % 2 != 0:
        return False

    part = [[True for i in range(n + 1)]
            for j in range(sum // 2 + 1)]

    for i in range(0, n + 1):
        part[0][i] = True

    for i in range(1, sum // 2 + 1):
        part[i][0] = False

    for i in range(1, sum // 2 + 1):

        for j in range(1, n + 1):
            part[i][j] = part[i][j - 1]

            if i >= arr[j - 1]:
                part[i][j] = (part[i][j] or
                              part[i - arr[j - 1]][j - 1])

    return part[sum // 2][n]

def bin_sum_array(arr,n):
    for i in range(n):
        if arr[i]%2==1:
            return i+1
    binarray=[list(reversed(bin(i)[2:])) for i in arr]
    new_array=[0 for i in range(32)]
    for i in binarray:
        for j in range(len(i)):
            if i[j]=='1':
                new_array[j]+=1
    return new_array
def ispalindrome(s):
    return s==s[::-1]
nc = "NO"
yc = "YES"
ns = "No"
ys = "Yes"
def yesno(a):
    print(yc if a else nc)
def reduce(dict,a):
    dict[a]-=1;
    if dict[a]==0:
        dict.pop(a)
# import math as mt
# MAXN=10**7
# spf = [0 for i in range(MAXN)]
# def sieve():
#     spf[1] = 1
#     for i in range(2, MAXN):
#         # marking smallest prime factor
#         # for every number to be itself.
#         spf[i] = i
#
#         # separately marking spf for
#     # every even number as 2
#     for i in range(4, MAXN, 2):
#         spf[i] = 2
#
#     for i in range(3, mt.ceil(mt.sqrt(MAXN))):
#
#         # checking if i is prime
#         if (spf[i] == i):
#
#             # marking SPF for all numbers
#             # divisible by i
#             for j in range(i * i, MAXN, i):
#
#                 # marking spf[j] if it is
#                 # not previously marked
#                 if (spf[j] == j):
#                     spf[j] = i
# def getFactorization(x):
#     ret = list()
#     while (x != 1):
#         ret.append(spf[x])
#         x = x // spf[x]
#
#     return ret
# sieve()


# if(os.path.exists('input.txt')):
#     sys.stdin = open("input.txt","r") ; sys.stdout = open("output.txt","w")


# input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
# input=stdin.readline
# print=stdout.write


t=1
for i in range(t):
    n=int(input())
    l=list(map(int,input().split()))
    people=[0]
    vacant=[0]
    for index,i in enumerate(l):
        if i==1:
            people.append(index)
        else:
            vacant.append(index)
    dp=[[inf for i in range(len(vacant)+10)] for j in range(len(people)+10)]



    for i in range(len(people)):
        for j in range(i,len(vacant)):
            if i==0:
                dp[i][j]=0
            elif j==0:
                dp[i][j]=inf
            else:
                dp[i][j]=min(dp[i][j-1],dp[i-1][j-1]+abs(people[i]-vacant[j]))

    print(dp[len(people)-1][len(vacant)-1])






