t=1
while t:
    n=int(input())
    x=input().split()
    v=input().split()
    ls=[]
    sp_ls=[]
    for i in range(n):
        x[i]=int(x[i])
        v[i]=int(v[i])
        ls.append([x[i],v[i]])
        sp_ls.append([v[i],x[i]])
    sp_ls.sort()    
    total=sum(x)
    lol=n
    dic={}
    i=0
    while i<n:
        dic[sp_ls[i][0]]=[total,n]
        total-=(sp_ls[i][1])
        lol-=1
        i+=1
        while i<n and sp_ls[i][0]==sp_ls[i-1][0]:
            total-=(sp_ls[i][1])
            lol-=1
            i+=1
    ls.sort()
    ans=0
    for i in range(n):
        ans+=dic[ls[i][1]][0]-(dic[ls[i][1]][1]-1)*x[i]
    print(ans)        
    t-=1