from bisect import bisect_left def count_inversion(sequence): count = 0 for i in range(1,len(sequence),1): for j in range(i,len(sequence),1): if sequence[i-1] > sequence[j]: count += 1 return count N = int(input()) A = list(map(int,input().split())) B = list(map(int,input().split())) b = [] for j in range(N): b.append((B[j],j)) b.sort() l = [] for i in range(N): j = bisect_left(b,(A[i],0)) l.append(b[j][1]) ans = count_inversion(l) print(ans)