N = int(input()) A = [0] + list(map(int,input().split())) B = [0] + list(map(int,input().split())) P = [0] * (N + 1) Q = [0] * (N + 1) for i in range(N + 1): P[A[i]] = i for i in range(N + 1): Q[i] = P[B[i]] from atcoder.fenwicktree import FenwickTree ft = FenwickTree(N + 1) cnt = 0 for x in Q: cnt += ft.sum(x, N + 1) ft.add(x, 1) print(cnt)