NN = 17 BIT = [0] * (2 ** NN + 1) def addbit(i, x=1): while i <= 2**NN: BIT[i] += x i += i & (-i) def getsum(i): ret = 0 while i != 0: ret += BIT[i] i -= i&(-i) return ret N = int(input()) A = [int(a) for a in input().split()] B = [int(a) for a in input().split()] D = {b: i for i, b in enumerate(B)} A = [D[a] for a in A] ans = 0 for a in A: ans += getsum(a + 1) addbit(a + 1) print(N * (N - 1) // 2 - ans)