#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
using namespace std;
const int INF = 0x3f3f3f3f;

int n, pos;
vector<int > pre, in, post;

void rec(int l, int r){
	if(l >= r)	return ;
	int root = pre[pos++];
	int m = distance(in.begin(), find(in.begin(), in.end(), root));
	rec(l, m);
	rec(m + 1, r);
	post.push_back(root);
}

void solve(){
	pos = 0;
	rec(0, pre.size());
	for(int i = 0; i < n; i++){
		if(i)	printf(" ");
		cout << post[i];
	}
	printf("\n");
}

int main(){
	int temp;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> temp;
		pre.push_back(temp);
	}
	for(int i = 0; i < n; i++){
		cin >> temp;
		in.push_back(temp);
	}
	solve();
	return 0;
}