class BIT: #0-indexed def __init__(self, n): self.tree = [0]*(n+1) def sum(self, i): #a_0 + ... + a_{i} #閉区間 s = 0; i += 1 while i > 0: s += self.tree[i] i -= i & -i return s def range(self,l,r): #a_l + ... + a_r 閉区間 return sum(r) - sum(l-1) def add(self, i, x): i += 1 while i <= n: self.tree[i] += x i += i & -i n = int(input()) *a, = map(int,input().split()) *b, = map(int,input().split()) r = [0]*n for i in range(n): r[a[i]-1] = i for i in range(n): b[i] = r[b[i]-1] bit = BIT(n) ans = 0 for i,bi in enumerate(b): ans += i-bit.sum(bi) bit.add(bi,1) print(ans)