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]

print(ans)
