def make_postorders pre_nodes, in_nodes, post_nodes
  m = pre_nodes.shift
  i = in_nodes.index(m)
  l_ins = (0 <= i - 1) ? in_nodes.slice(0..(i - 1)) : []
  r_ins = (i + 1 <= in_nodes.length - 1) ? in_nodes.slice((i + 1)..(in_nodes.length - 1)) : []

  make_postorders pre_nodes, l_ins, post_nodes unless l_ins.empty?
  make_postorders pre_nodes, r_ins, post_nodes unless r_ins.empty?
  post_nodes << m

  return post_nodes
end

n = gets.chomp.to_i
preorders = gets.chomp.split(' ').map(&:to_i)
inorders = gets.chomp.split(' ').map(&:to_i)
nodes = make_postorders preorders, inorders, []
puts nodes.join(' ')
