from bisect import bisect_left class BIT(): def __init__(self, init): if type(init) == int: self.n = init + 1 self.X = [0] * self.n else: self.n = len(init) + 1 self.X = [0] + init for i in range(1, self.n): if i + (i & -i) < self.n: self.X[i + (i & -i)] += self.X[i] def add(self, i, x=1): i += 1 while i < self.n: self.X[i] += x i += i & (-i) def getsum(self, i): ret = 0 while i != 0: ret += self.X[i] i -= i&(-i) return ret def getrange(self, l, r): return self.getsum(r) - self.getsum(l) def inversion_number(L): bit = BIT(len(L)) ret = 0 for i, a in enumerate(L): ret += i - bit.getsum(a + 1) bit.add(a) return ret N = int(input()) A = list(map(int,input().split())) B = list(map(int,input().split())) b = [] for j in range(N): b.append((B[j],j)) b.sort() l = [] for i in range(N): j = bisect_left(b,(A[i],0)) l.append(b[j][1]) ans = inversion_number(l) print(ans)