def solve(left, right)
  return if left > right
  x = $preorder[$cur]
  $cur += 1
  solve(left, $postorder[x]-1)
  solve($postorder[x]+1, right)
  if $cur == 0 then print x, "\n"
  else print x, " "
  end
end
n = gets.to_i
$preorder = gets.split.map(&:to_i)
$inorder = gets.split.map(&:to_i)
$postorder = []
$cur = 0
n.times{ |i| $postorder[$inorder[i]] = i }
solve(0, n-1)