#include <bits/stdc++.h>
using namespace std;

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 < post.size(); i++){
		if (i) printf(" ");
		printf("%d", post[i]);
	}
	puts("");
}

int main()
{
	scanf("%d", &n);
	
	for (int i = 0; i < n; i++){
		int k;
		scanf("%d", &k);
		pre.push_back(k);
	}
	
	for (int i = 0; i < n; i++){
		int k;
		scanf("%d", &k);
		in.push_back(k);
	}
	
	solve();
	
	return 0;
}