import sys from itertools import combinations, permutations, product, accumulate, groupby from collections import defaultdict, deque, Counter from functools import reduce import heapq import bisect import math import copy sys.setrecursionlimit(10 ** 9) input = lambda: sys.stdin.readline().rstrip() INF = float("inf") MOD = 10 ** 9 + 7 # DFS # import pypyjit # pypyjit.set_param('max_unroll_recursion=-1') #https://tjkendev.github.io/procon-library/python/sequence/number_of_inversions.html N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) d = {} for i in range(N): d[B[i]] = i + 1 adjustedA = [] for i in range(N): adjustedA.append(d[A[i]]) # BIT data = [0]*(N+1) def add(k, x): while k <= N: data[k] += x k += k & -k def get(k): s = 0 while k: s += data[k] k -= k & -k return s ans = 0 for i, a in enumerate(adjustedA): ans += (N - 1 - i) - get(a) add(a, 1) print(ans)