n = gets.to_i
$pre = gets.split.map(&:to_i)
$in = gets.split.map(&:to_i)
$post = []

$pos = 0

class Node
  attr_accessor :id, :left, :right
  def initialize
    @id = nil
    @left = nil
    @right = nil
  end
end

def reconstruction(l, r)
  if l >= r
    return
  end

  c = $pre[$pos]
  $pos += 1

  m = $in.index(c)

  reconstruction(l, m)
  reconstruction(m+1, r)

  $post << c
end

reconstruction(0, n)

puts $post.join(" ")
