Iahub helps his grandfather at the farm. Today he must milk the cows. There are n cows sitting in a row, numbered from 1 to n from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the cows that see the current cow get scared and lose one unit of the quantity of milk that they can give. A cow facing left sees all the cows with lower indices than her index, and a cow facing right sees all the cows with higher indices than her index. A cow that got scared once can get scared again (and lose one more unit of milk). A cow that has been milked once cannot get scared and lose any more milk. You can assume that a cow never loses all the milk she can give (a cow gives an infinitely amount of milk).

Iahub can decide the order in which he milks the cows. But he must milk each cow exactly once. Iahub wants to lose as little milk as possible. Print the minimum amount of milk that is lost.


-----Input-----

The first line contains an integer n (1 ≤ n ≤ 200000). The second line contains n integers a_1, a_2, ..., a_{n}, where a_{i} is 0 if the cow number i is facing left, and 1 if it is facing right.


-----Output-----

Print a single integer, the minimum amount of lost milk.

Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.


-----Examples-----
Input
4
0 0 1 0

Output
1
Input
5
1 0 1 0 1

Output
3


-----Note-----

In the first sample Iahub milks the cows in the following order: cow 3, cow 4, cow 2, cow 1. When he milks cow 3, cow 4 loses 1 unit of milk. After that, no more milk is lost.

Difficulty: competition

Starter code:

Solutions:
__author__ = 'Pavel Mavrin'

n = int(input())
a = [int(x) for x in input().split()]

s = 0
res = 0
for i in a:
    if i == 0:
        res += s
    else:
        s += 1

print(res)


import sys
n=int(input())
L=list(map(int,sys.stdin.readline().split()))

z=L.count(0)

if(z==n or z==0):
    print(0)
    Zeros=[0]*n
    Zeros[n-1]+=1-L[n-1]
    for i in range(n-2,-1,-1):
        Zeros[i]=Zeros[i+1]
        if(L[i]==0):
            Zeros[i]+=1
else:
    Zeros=[0]*n
    Zeros[n-1]+=1-L[n-1]
    for i in range(n-2,-1,-1):
        Zeros[i]=Zeros[i+1]
        if(L[i]==0):
            Zeros[i]+=1

    Ans=0
    o=0
    z=0
    p=L[0]
    if(L[0]==1):
        o+=1
    for i in range(1,n):
        if(L[i]==p):
            
            if(p==1):
                o+=1
        else:
            if(L[i]==0):
                Ans+=Zeros[i]*o
                p=0
            else:
                o=1
                p=1
    print(Ans)


n=int(input())
a=list(map(int,input().split()))
b=[0,0]
ans=0
for i in range(n):
    b[a[i]]+=1
    if a[i]==0: ans+=b[1]
print(ans)


input()
s = k = 0
for i in input()[:: 2]:
    if i == '1': k += 1
    else: s += k
print(s)

import fileinput
for line in fileinput.input():   
    x = [ int(i) for i in line.split()]

rightCows = 0
total = 0

for i in range(0,len(x)):
    if x[i]:
        rightCows+=1
    else:
        total +=rightCows

print(total)

n = int(input())
a = [int(x) for x in input().split()]
ans = 0
r = 0
for x in a:
	if x == 1:
		r += 1
	else:
		ans += r
print(ans)


def main():
    input()
    i = res = 0
    for c in input()[::2]:
        if c == "1":
            i += 1
        else:
            res += i
    print(res)


def __starting_point():
    main()

__starting_point()

n = int(input())
s = k = 0
for i in input()[::2]:
    if i == '1': 
        k += 1
    else: 
        s += k
print(s)

n=int(input())
nm=[0]+list(map(int,input().split()))+[-1]
sm=[0]*len(nm)
for i in range(n+1,0,-1):
    if not nm[i]:
        sm[i-1]=sm[i]+1
    else:
        sm[i-1]=sm[i]
ans=0
for i in range(1,n+1):
    if nm[i]:ans+=sm[i]
print(str(ans))

n = int(input())
a = [int(x) for x in input().split()]
ans = 0
r = 0
for x in a:
	if x == 1:
		r += 1
	else:
		ans += r
print(ans)

# Made By Mostafa_Khaled 
bot = True 
n = int(input())

s = k = 0

for i in input()[::2]:

    if i == '1': 

        k += 1

    else: 

        s += k

print(s)

# Made By Mostafa_Khaled


def cows(lst):
    k1, k2 = 0, 0
    for i in range(len(lst)):
        if lst[i] == 1:
            k1 += 1
        else:
            k2 += k1
    return k2


n = int(input())
a = [int(j) for j in input().split()]
print(cows(a))


n, v = int(input()), list(map(int, input().split())) # v = [int(x) for x in input().split()]

ans = 0
r = 0

for i in v:
    if i == 1:
        r += 1
    else:
        ans += r

print(ans)




n = input()
a = list(map(int, input().split(' ')))

n0 = a.count(0)
n1 = a.count(1)

res = list()
if n0 < n1:
    n1_cnt = 0
    for i in a:
        if i == 1:
            n1_cnt += 1
        else:
            res.append(n1_cnt)
else:
    n0_cnt = 0
    for i in reversed(a):
        if i == 0:
            n0_cnt += 1
        else:
            res.append(n0_cnt)

print(sum(res))


n=int(input())
l=[int(i) for i in input().split()]
zeroes=[0]*n 
if l[-1]==0:
    zeroes[n-1]=1 
else:
    zeroes[n-1]=0 
for i in range(n-2,-1,-1):
    zeroes[i]=zeroes[i+1]
    if l[i]==0:
        zeroes[i]+=1 
cnt=0 
for i in range(n):
    if l[i]==1:
        cnt+=zeroes[i]
print(cnt)

#! usr/bin/env python3
# coding:UTF-8

ans = 0
cnt = 0
N = input()
t = input().split()

for i in t:
    if(int(i) == 1):
        cnt += 1
    else:
        ans += cnt

print(ans)


#! usr/bin/env python3
# coding:UTF-8

# wdnmd UKE

ans = 0
cnt = 0
N = input()
t = input().split()

for i in t:
    if(int(i) == 1):
        cnt += 1
    else:
        ans += cnt

print(ans)


#! usr/bin/env python3
# coding:UTF-8

# wdnmd UKE
# wcnm UKE

ans = 0
cnt = 0
N = input()
t = input().split()

for i in t:
    if(int(i) == 1):
        cnt += 1
    else:
        ans += cnt

print(ans)


#! usr/bin/env python3
# coding:UTF-8

# wdnmd UKE
# wcnm UKE
# wrnnn UKE

ans = 0
cnt = 0
N = input()
t = input().split()

for i in t:
    if(int(i) == 1):
        cnt += 1
    else:
        ans += cnt

print(ans)


#! usr/bin/env python3
# coding:UTF-8

# wdnmd UKE
# wcnm UKE
# wrnnn UKE
# UKE 5

ans = 0
cnt = 0
N = input()
t = input().split()

for i in t:
    if(int(i) == 1):
        cnt += 1
    else:
        ans += cnt

print(ans)


#! usr/bin/env python3
# coding:UTF-8

# wdnmd UKE
# wcnm UKE
# wrnnn UKE
# UKE 5
# UKE 6

ans = 0
cnt = 0
N = input()
t = input().split()

for i in t:
    if(int(i) == 1):
        cnt += 1
    else:
        ans += cnt

print(ans)


#! usr/bin/env python3
# coding:UTF-8

# wdnmd UKE
# wcnm UKE
# wrnnn UKE
# UKE 5
# UKE 6
# UKE 7

ans = 0
cnt = 0
N = input()
t = input().split()

for i in t:
    if(int(i) == 1):
        cnt += 1
    else:
        ans += cnt

print(ans)


n = int(input())
arr = list(map(int, input().split()))
cnt_zero, res = 0, 0
for i in range(n-1, -1, -1):
    if arr[i] == 0:
        cnt_zero += 1
    else:
        res += cnt_zero
print(res)


def cows(n, lst):
    zeros, result = 0, 0
    for i in range(n - 1, -1, -1):
        if lst[i] == 0:
            zeros += 1
        else:
            result += zeros
    return result


m = int(input())
a = [int(j) for j in input().split()]
print(cows(m, a))