n = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) Price = [-1 for _ in range(n)] for i in range(n): Price[B[i] - 1] = i ANS = [] P = [False for _ in range(n)] idx = 0 for i in range(n): a = A[i] - 1 f = i l = Price[a] P[l] = True if idx == l: ANS.append(a + 1) while idx < n and P[idx]: idx += 1 ANS.sort() print(*ANS, sep='\n')