n = int(input()) a = list(map(int,input().split())) b = list(map(int,input().split())) D = {v:i for i,v in enumerate(b)} bit = [0] * (n+1) def update(i,x): while i <= n: bit[i] += x i += i & -i def fold(i): ans = 0 while i > 0: ans += bit[i] i -= i & -i return ans ans = 0 for x in reversed(a): ans += fold(D[x]+1) update(D[x]+1,1) print(ans)