def reconstruct(preorder, inorder)
	return [] if !preorder || preorder.empty?
	return [] if !inorder || inorder.empty?

	root = preorder.shift
	separate_point = inorder.index(root)
	unless separate_point
		raise "Unexpected state #{preorder}, #{inorder}"
	end

	left = inorder.shift(separate_point) # 副作用でinorderは右部分木になる
	inorder.shift # separate_pointを取り除く

	result = []
	result.concat(reconstruct(preorder, left))
	result.concat(reconstruct(preorder, inorder))
	result << root
end

n = STDIN.gets.to_i
preorder = STDIN.gets.split[0...n].map(&:to_i)
inorder  = STDIN.gets.split[0...n].map(&:to_i)
puts reconstruct(preorder, inorder).join(" ")