n = gets.chomp.to_i
preorderd = gets.chomp.split.map(&:to_i)
inorderd  = gets.chomp.split.map(&:to_i)


 
class Node
  attr_accessor :left, :right, :parent
  def initialize(parent, left, right)
    @parent = parent
    @left = left
    @right = right
  end
end

def postorder(u, tree, res)
  return if u == -1
  postorder(tree[u].left, tree, res)
  postorder(tree[u].right, tree, res)
  res << u
  res
end
 
tree = []
n.times do |i|
  tree[i] = Node.new(-1, -1, -1)
end

# solve it 
def make_tree(inorderd, preorderd)
  return [] if !preorderd or preorderd.empty?
  return [] if !inorderd or inorderd.empty?

  focus = preorderd.shift
  split = inorderd.index(focus)
  
  l = inorderd.shift(split)
  inorderd.shift

  res = []
  res.concat(make_tree(preorderd, l))
  res.concat(make_tree(preorderd, inorderd))
  res << focus
end



puts make_tree(inorderd, preorderd).join(' ')