import scala.io.StdIn.{readInt,readLine}
import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args:Array[String]) = {
    val n = readInt
    val pre = readLine.split(" ").map(_.toInt)
    val in = readLine.split(" ").map(_.toInt)
    val post = new ArrayBuffer[Int]

    var pos = 0
    def scan(l:Int, r:Int):Unit = {
      if(l<r) {
        val root = pre(pos)
        pos += 1
        val m = in.indexWhere(_==root)
        scan(l,m)
        scan(m+1,r)
        post += root
      }
    }

    scan(0, pre.length)
    println(post.toArray.mkString(" "))
  }
}