#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

class RootedNode{
public:
	vector<ll> parent;
	ll depth,dist;
	RootedNode():depth(0),dist(0){}
};

class ConnectNodeInfo{
	vector<vector<pair<ll,ll>>> graph;
public:
	map<int,int> input;
	ConnectNodeInfo(int node_num){
		graph.resize(node_num);
	}
	void AddNonDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
		graph[v].emplace_back(u,w);
	}
	void AddDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
		input[v]++;
	}
	vector<pair<ll,ll>>& operator[](ll index){
		return graph[index];
	}
	size_t size(){return graph.size();}
};

class RootedTree{
	int parent_size;

	void DFS(ConnectNodeInfo& connection,ll child,ll parent,ll dep,ll dist){
		node[child].parent[0] = parent;
		node[child].depth = dep;
		node[child].dist = dist;

		int num=0;
		for(int i = 0;i < connection[child].size();i++){
			int cn = connection[child][i].first;
			DFS(connection,connection[child][i].first,child,dep+1,dist+connection[child][i].second);
		}
		postorder.push_back(child);
	}
public:
	vector<RootedNode> node;
	vector<int> postorder;

	RootedTree(ConnectNodeInfo& connection,int root){
		auto connection_size = connection.size();
		parent_size = 1;
		while((1LL<<parent_size)<connection_size) parent_size++;

		node.resize(connection_size);
		for(auto& x:node) x.parent.resize(parent_size,-1);
		DFS(connection,root,-1,0,0);
		for(int k=0;k<parent_size-1;k++){
			for(int v=0,ev=connection_size;v<ev;v++){
				if(node[v].parent[k] < 0) node[v].parent[k+1] = -1;
				else node[v].parent[k+1] = node[node[v].parent[k]].parent[k];
			}
		}
	}
};

int DivideTree(ConnectNodeInfo& connect,vector<int>& preorder,vector<int> inorder){
	int root = preorder[0];
	auto pos = find(ALL(inorder),root);

	vector<int> left_inorder(inorder.begin(),pos);
	vector<int> left_preorder(preorder.begin()+1,preorder.begin()+1+left_inorder.size());

	if(!left_inorder.empty()){
		int left_node = DivideTree(connect,left_preorder,left_inorder);
		connect.AddDirectionalConnection(root-1,left_node-1,1);
	}

	vector<int> right_inorder(pos+1,inorder.end());
	vector<int> right_preorder(preorder.begin()+1+left_inorder.size(),preorder.end());

	if(!right_inorder.empty()){
		int right_node = DivideTree(connect,right_preorder,right_inorder);
		connect.AddDirectionalConnection(root-1,right_node-1,1);
	}

	return root;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N=in();
	auto preorder=vecin(N);
	auto inorder=vecin(N);
	ConnectNodeInfo connect(N);

	int root = DivideTree(connect,preorder,inorder);
	RootedTree tree(connect,root-1);

	REP(i,N-1){
		cout << tree.postorder[i]+1 << ' ';
	}
	out(tree.postorder.back()+1);
	
	return 0;
}



Measured memory_bytes: 3208