n = gets.to_i
preo, ino = 2.times.map{gets.split(' ').map(&:to_i)}

Tree = Hash.new([])

build = -> (i, t) do
  j = t.index i
  if j.nil?
    preo.unshift i
    return nil
  end
  Tree[i] = []
  Tree[i][0] = build.(preo.shift, t[0...j])
  Tree[i][1] = build.(preo.shift, t[j+1...t.size])
  i
end

postorder = -> (a, i) do
  l = Tree[i][0]
  r = Tree[i][1]
  postorder.(a, l) if !l.nil?
  postorder.(a, r) if !r.nil?
  a << i
end

root = preo.first
build.(preo.shift, ino)
puts postorder.([], root).join(' ')
