import collections

def ff(x, d):
    res = 0
    for i in d.keys():
        if i < x:
            res += 1
        else:
            break
    return res

n = int(input())
x = list(map(int, input().split()))
v = list(map(int, input().split()))
d = [(x[i], v[i]) for i in range(n)]
d.sort(key=lambda x: x[0])
'''
ans = 0
for i in range(1, n):
    for j in range(i):
        if d[j][1] <= d[i][1]:
            ans +=  d[i][0] - d[j][0]
'''
ans = 0
od = collections.OrderedDict()
for i in range(n):
    ind = ff(d[i][1] + 1, od)
    ans += ind * d[i][0]
    #print(ind * d[i][0])
    od[d[i][1]] = i

od = collections.OrderedDict()
for i in range(n-1, -1, -1):
    ind = len(od) - ff(d[i][1], od)
    ans -= ind * d[i][0]
    #print(len(od), ff(d[i][1] - 1, od), -ind * d[i][0])
    od[d[i][1]] = i

print(ans)
