public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		n = cin.nextInt();
		for (int i=0; i < n; ++i) {
			post[i] = cin.nextInt(); 
		}
		for (int i=0; i < n; ++i) {
			in[i] = cin.nextInt();
		}
		
		Queue<Pair> queue = new LinkedList<Pair>();
		queue.add(new Pair(0, n-1, 0, n-1));
		boolean head = true;
		while (queue.size() != 0) {
			Pair p = queue.poll();
			if (p.ps > p.pe) continue;
			
			if (head) head = false;
			else System.out.print(" ");
			System.out.print(post[p.pe]);
			
			if (p.ps == p.pe) continue;
			
			int i;
			for (i = p.is; i < p.ie; ++i) {
				if (in[i] == post[p.pe]){
					break;
				}
			}
			queue.add(new Pair(p.ps, 
					p.ps + i - p.is -1, 
					p.is, 
					i - 1));
			queue.add(new Pair(p.ps + i - p.is,
					p.pe - 1, 
					i + 1, 
					p.ie));
		}
	}