n=int(input())
x=[int(x) for x in input().split()]
v=[int(x) for x in input().split()]
d=0
for i in range(n):
    for j in range(i+1, n):
        if v[i]==v[j]:
            d+=abs(x[i]-x[j])
        elif v[i]<v[j] and x[i]<x[j]:
            d+=abs(x[i]-x[j])
        elif v[j]>v[i] and x[j]>x[i]:
            d+=abs(x[i]-x[j])
print(d)
