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.
import sys,os
from io import BytesIO,IOBase
mod = 10**9+7; Mod = 998244353; INF = float('inf')
# input = lambda: sys.stdin.readline().rstrip("\r\n")
# inp = lambda: list(map(int,sys.stdin.readline().rstrip("\r\n").split()))
#______________________________________________________________________________________________________
# region fastio
# ''' 
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
# endregion'''
#______________________________________________________________________________________________________
input = lambda: sys.stdin.readline().rstrip("\r\n")
inp = lambda: list(map(int,sys.stdin.readline().rstrip("\r\n").split()))
# ______________________________________________________________________________________________________
from math import *
# from bisect import *
# from heapq import *
# from collections import defaultdict as dd
# from collections import OrderedDict as odict
# from collections import Counter as cc
# from collections import deque
# from itertools import groupby
# sys.setrecursionlimit(300_100) #this is must for dfs
# ______________________________________________________________________________________________________
# segment tree for range minimum query and update 0 indexing
# init = float('inf')
# st = [init for i in range(4*len(a))]
# def build(a,ind,start,end):
#     if start == end:
#         st[ind] = a[start]
#     else:
#         mid = (start+end)//2
#         build(a,2*ind+1,start,mid)
#         build(a,2*ind+2,mid+1,end)
#         st[ind] = min(st[2*ind+1],st[2*ind+2])
# build(a,0,0,n-1)
# def query(ind,l,r,start,end):
#     if start>r or end<l:
#         return init
#     if l<=start<=end<=r:
#         return st[ind]
#     mid = (start+end)//2
#     return min(query(2*ind+1,l,r,start,mid),query(2*ind+2,l,r,mid+1,end))
# def update(ind,val,stind,start,end):
# 	if start<=ind<=end:
# 		if start==end:
# 			st[stind] = a[start] = val
# 		else:
# 			mid = (start+end)//2
# 			update(ind,val,2*stind+1,start,mid)
# 			update(ind,val,2*stind+2,mid+1,end)
# 			st[stind] = min(st[left],st[right])
# ______________________________________________________________________________________________________
# Checking prime in O(root(N))
# def isprime(n):
#     if (n % 2 == 0 and n > 2) or n == 1: return 0
#     else:
#         s = int(n**(0.5)) + 1
#         for i in range(3, s, 2):
#             if n % i == 0:
#                 return 0
#         return 1
# def lcm(a,b):
#   return (a*b)//gcd(a,b)
# ______________________________________________________________________________________________________
# nCr under mod
# def C(n,r,mod = 10**9+7):
#   if r>n: return 0
#   if r>n-r: r = n-r
#   num = den = 1
#   for i in range(r):
#       num = (num*(n-i))%mod
#       den = (den*(i+1))%mod
#   return (num*pow(den,mod-2,mod))%mod
# def C(n,r):
#   if r>n:
#       return 0
#   if r>n-r:
#       r = n-r
#   ans = 1
#   for i in range(r):
#       ans = (ans*(n-i))//(i+1)
#   return ans
# ______________________________________________________________________________________________________
# For smallest prime factor of a number
# M = 2*10**5+10
# spf = [i for i in range(M)]
# def spfs(M):
#   for i in range(2,M):
#       if spf[i]==i:
#           for j in range(i*i,M,i):
#               if spf[j]==j:
#                 spf[j] = i
#   return
# spfs(M)
# ______________________________________________________________________________________________________
# def gtc(p):
#     print('Case #'+str(p)+': ',end='')
# ______________________________________________________________________________________________________
tc = 1
# tc = int(input())
for test in range(1,tc+1):
    n, = inp()
    a = inp()
    k = a.count(1)
    b = [i for i in range(n) if a[i]==1]
    dp = [[INF]*(k+1) for i in range(n+1)]
    for i in range(n+1):
        dp[i][0] = 0
    for i in range(1,n+1):
        for j in range(1,k+1):
            dp[i][j] = min(dp[i-1][j],INF if a[i-1]==1 else (dp[i-1][j-1]+abs(b[j-1]-(i-1))))
    print(dp[n][k])