def recon(l, r)
  return if l > r
  c = @pre.shift
  m = @in.index(c)
  recon(l, m-1)
  recon(m+1, r)
  print "#{c} "
end

n = gets.to_i
@pre = gets.split.map { |i| i.to_i }
@in = gets.split.map { |i| i.to_i }
recon(0, n-1)