def reconstruct(preorder_values, inorder_values, postorder_values, left, right)
  return unless left < right

  root = preorder_values.shift

  mid = inorder_values.find_index(root)

  reconstruct(preorder_values, inorder_values, postorder_values, left, mid)
  reconstruct(preorder_values, inorder_values, postorder_values, mid + 1, right)

  postorder_values << root
end

if $PROGRAM_NAME == __FILE__
  n = gets.to_i

  preorder_values = gets.chomp.split.map(&:to_i)
  inorder_values = gets.chomp.split.map(&:to_i)
  postorder_values = []

  reconstruct(preorder_values, inorder_values, postorder_values, 0, n)

  puts postorder_values.join(' ')
end