#Pye
from os import path
from sys import stdin, stdout
from bisect import bisect_left
if path.exists('inp.txt'): stdin = open("inp.txt", "r")
maxn = 200005
a = []; b = []; fen = [(0, 0) for i in range(maxn)]
res = 0
n = int(stdin.readline())
def update(x, val):
    global fen
    while x > 0:
        fen[x] = (fen[x][0] + val, fen[x][1] + 1)
        x -= x & (-x)
def get(x, val):
    global n, fen
    A = 0; B = 0
    while x < n+2:
        A += fen[x][0]
        B += fen[x][1]
        x += x & (-x)
    return A - B * val
af = list(map(int, stdin.readline().split()))
ad = list(map(int, stdin.readline().split()))
for i in range(n): a.append((af[i], ad[i])); b.append(ad[i])
a.sort()
b.sort()
for i in range(n): a[i] = (a[i][0], bisect_left(b, a[i][1]) + 1)
for i in range(n-1, -1, -1):
    res += get(a[i][1], a[i][0])
    update(a[i][1], a[i][0])
print(res)