class TreeNode:
def __init__(self,x):
self.val = x
self.left=None
self.right=None
def preorderTravel(root):
if not root:
return
print(root.val)
preorderTravel(root.left)
preorderTravel(root.right)
def buildTree(pl,pr,il,ir,postorder,inorder,hash_table):
if pl>pr:
return
root = TreeNode(postorder[pr])
k = hash_table[root.val]
left_len = k-1-il+1
right_len = ir - (k+1)+1
root.left = buildTree(pl, pl+left_len-1, il, k-1, postorder, inorder, hash_table)
root.right = buildTree(pr-right_len, pr-1, k+1, ir, postorder, inorder, hash_table)
return root
if __name__=="__main__":
n=int(input())
postorder = [int(x) for x in input().split()]
inorder = [int(x) for x in input().split()]
hash_table = dict()
for i in range(0,n):
hash_table[inorder[i]] = i
root = buildTree(0,n-1,0,n-1,postorder,inorder,hash_table)
res = []
# preorderTravel(root)
q = [root]
while q :
p=q.pop(0)
res.append(str(p.val))
if p.left:
q.append(p.left)
if p.right:
q.append(p.right)
print(" ".join(res))