# include <iostream>
# include <algorithm>
# include <vector>
using namespace std;
vector<int> a,b,ans;
int pos = 0;
void dfs(int l,int r)
{
	if(l >= r) return ;
	int root = a[pos++];
	int dis = distance(b.begin(),find(b.begin(),b.end(),root));
	dfs(l,dis); dfs(dis+1,r);
	ans.push_back(root); 
}
int main(void)
{
	int n,k;
	scanf("%d",&n);
	for(int i = 0;i < n;i++) scanf("%d",&k),a.push_back(k);
	for(int i = 0;i < n;i++) scanf("%d",&k),b.push_back(k);
	dfs(0,n);
	for(int i = 0;i < n;i++) printf("%d%c",ans[i],(i == n-1)?'\n':' ');
	return 0;
}
