# ALDS1_7_D: Reconstruction of the Tree

class Walker
  attr_reader :post
  def initialize(preorder, inorder)
    @pre  = preorder
    @in   = inorder
    @post = []
    @pre_pos = 0
  end

  def reconstruct(left, right)
    return if right <= left
    root = @pre[ @pre_pos ]
    @pre_pos += 1
    in_pos = @in.index root
    reconstruct(left, in_pos)
    reconstruct(in_pos + 1, right)
    @post << root
  end
end

n_nodes  = gets.to_i
preorder = gets.split.map &:to_i
inorder  = gets.split.map &:to_i

walker = Walker.new(preorder, inorder)
walker.reconstruct 0, n_nodes

puts walker.post.join(' ')