def solve(left, right)
  return if left > right
  x = $preorder[$cur]
  y = $inorder.index(x)
  $cur += 1
  solve(left, y-1)
  solve(y+1, right)
  $postorder << x
end
n = gets.to_i
$preorder = gets.split.map(&:to_i)
$inorder = gets.split.map(&:to_i)
$postorder = []
$cur = 0
solve(0, n-1)
puts $postorder.join(" ")