n = int(input())
x = [int(a) for a in input().split()]
v = [int(a) for a in input().split()]
sum = 0
for i in range(1, n):
    for j in range(i, n):
        if x[j] < x[j-1]:
            temp = x[j]
            x[j] = x[j-1]
            x[j-1] = temp
            temp = v[j]
            v[j] = v[j-1]
            v[j-1] = temp
for i in range(n):
    for j in range(i, n):
        if v[j] > v[i]:
            sum += x[j] - x[i]
print(sum)