#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

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

void rec(int left, int right){ //不包括right
	if(left>=right) return;
	int m = pre[pos++];

	int position = distance(in.begin(),find(in.begin(), in.end(), m));
	
	rec(left, position);
	rec(position+1, right);
	post.push_back(m);
}

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

int main(){
	int n;

	cin>>n;
	int tem1, tem2;
	for(int i=0; i<n; i++){
		cin>>tem1;
		pre.push_back(tem1);
	}
	for(int i=0; i<n; i++){
		cin>>tem2;
		in.push_back(tem2);
	}
	sovle();
	cout<<endl;
	return 0;
}
