import sys
input=sys.stdin.readline
def getsum(BITTree,i):
    s = 0
    while i > 0:
        s += BITTree[i]
        i -= i & (-i) 
    return(s)
def updatebit(BITTree , n , i ,v):
    while i <= n:
        BITTree[i] += v
        i += i & (-i)
n=int(input())
x=[int(i) for i in input().split() if i!='\n']
v=[int(i) for i in input().split() if i!='\n']
for i in range(n):
        v[i]=[v[i],i]
v.sort()
pos=dict()
store,prev=1,v[0][0]
for i in range(n):
        if i>0:
            if prev==v[i][0]:
                pos[x[v[i][1]]]=store
            else:
                store+=1
                pos[x[v[i][1]]]=store
        else:
            pos[x[v[i][1]]]=store
#print(pos)
sort=sorted(pos.keys())
bit=[0]*(n+1)
ind=[0]*(n+1)
ans,count,diff=0,0,0
length=max(sort)
total=0
for i in range(len(sort)):
        count=getsum(bit,pos[sort[i]])
        diff=getsum(ind,pos[sort[i]])
        ans+=count*sort[i]-diff
        updatebit(bit,len(bit)-1,pos[sort[i]],1)
        updatebit(ind,len(ind)-1,pos[sort[i]],sort[i])
print(int(ans))
        
        

