# Binary Indexed Tree (Fenwick Tree) class BIT: def __init__(self, n): self.n = n self.bit = [0]*(n+1) self.el = [0]*(n+1) def sum(self, i): s = 0 while i > 0: s += self.bit[i] i -= i & -i return s def add(self, i, x): # assert i > 0 self.el[i] += x while i <= self.n: self.bit[i] += x i += i & -i def get(self, i, j=None): if j is None: return self.el[i] return self.sum(j) - self.sum(i-1) def lower_bound(self,x): w = i = 0 k = 1<<((self.n).bit_length()) while k: if i+k <= self.n and w + self.bit[i+k] < x: w += self.bit[i+k] i += k k >>= 1 return i+1 N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) A.sort() comp = lambda arr: {e: i+1 for i, e in enumerate(sorted(set(arr)))} compAB = comp(A+B) bit = BIT(2*N+2) ans = 0 for i in range(N): bit.add(compAB[B[i]],1) ans += bit.sum(compAB[A[i]]-1) print(ans)