n = int(input()) a = [int(i)-1 for i in input().split()] b = [int(i)-1 for i in input().split()] from collections import defaultdict, deque 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の配列liの転倒数を数え上げる" bit = Bit(n+1) ans = 0 idx = [0]*n li = [0]*n for i in range(n): idx[a[i]] = i for i in range(n): li[idx[b[i]]] = i for i, p in enumerate(li): bit.add(p+1, 1) ans += i + 1 - bit.sum(p+1) print(ans)