class segtree: def __init__(self,_n): self.n=1 while self.n<_n: self.n<<=1 self.dat=[0]*(self.n<<1) for i in range(self.n-1,0,-1): self.dat[i]=self.dat[i<<1]+self.dat[i<<1|1] def update(self,k,a): k+=self.n self.dat[k]+=a while 1>=1 self.dat[k]=self.dat[k<<1]+self.dat[k<<1|1] def value(self,l,r): res=0 l+=self.n r+=self.n while l>=1 r>>=1 return res def main(): import sys input=sys.stdin.readline n=int(input()) a=(lambda x:[i-1 for i in x])(list(map(int,input().split()))) b=(lambda x:[i-1 for i in x])(list(map(int,input().split()))) p=[0]*n for i in range(n): p[b[i]]=i for i in range(n): a[i]=p[a[i]] ans=0 seg=segtree(n) for i in a: ans+=seg.value(i+1,n) seg.update(i,1) print(ans) if __name__ == '__main__': main()