import sys input = sys.stdin.readline from collections import * class BIT: def __init__(self, n): self.n = n self.bit = [0]*(n+1) def add(self, i, x): i += 1 while i<=self.n: self.bit[i] += x i += i&(-i) def acc(self, i): s = 0 while i>0: s += self.bit[i] i -= i&(-i) return s n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) d = defaultdict(int) for i in range(n): d[b[i]] = i bit = BIT(n) ans = 0 for i in range(n): ans += i-bit.acc(d[a[i]]) bit.add(d[a[i]], 1) print(ans)