class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i N, = map(int, input().split()) X = list(map(int, input().split())) Y = list(map(int, input().split())) Z = list(set(X+Y)) Z.sort() x2i = dict() i = 1 for z in Z: x2i[z] = i i+=1 M = i bt = Bit(M) X.sort() R = 0 for i in range(N): y = x2i[Y[i]] bt.add(y, 1) x = x2i[X[i]] R += bt.sum(x-1) print(R)