from collections import deque N = int(input()) A = list(map(lambda x: int(x) - 1, input().split())) B = list(map(lambda x: int(x) - 1, input().split())) atoi = [-1] * N btoi = [-1] * N for i, a in enumerate(A): atoi[a] = i for i, b in enumerate(B): btoi[b] = i task = [] for i in range(N): s = atoi[i] t = btoi[i] if s >= t: i += 1 task.append((s, i)) task.append((t, -i)) task.sort(reverse=True) que = deque() ans = [] seen = set() for _, x in task: if x > 0: que.append(x) else: x = -x seen.add(x) if que[0] == x: ans.append(x) que.popleft() while que and que[0] in seen: que.popleft() while que and que[-1] in seen: que.pop() ans.sort() print(*ans, sep="\n")