import sys input = sys.stdin.buffer.readline class Bit: """1-indexed""" __slots__ = ("size", "tree") 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 = int(input()) A = sorted(map(int, input().split())) B = list(map(int, input().split())) coor_comp = {x: i for i, x in enumerate(sorted(set(A + B)), 1)} L = len(coor_comp) bit = Bit(L) ans = 0 for a, b in zip(A, B): bit.add(coor_comp[b], 1) ans += bit.sum(coor_comp[a] - 1) print(ans)