#include<iostream>
#include<queue>
#include<unordered_map>
using namespace std;
typedef long long LL;
const int N=40;
int inorder[N],postorder[N];
unordered_map<int,int>l,r,pos;
int n;
int build(int il,int ir,int pl,int pr){
int root=postorder[pr];
int k=pos[root];
if(il<k) l[root]=build(il, k-1, pl, k-1-il+pl);
if(ir>k) r[root]=build(k+1, ir, k-il+pl, pr-1);
return root;
}
void bfs(){
queue<int>q;
q.push(postorder[n-1]);
while(!q.empty()){
int c=q.front();
q.pop();
cout<<c<<" ";
if(l.count(c)) q.push(l[c]);
if(r.count(c)) q.push(r[c]);
}
cout<<endl;
}
int main(){
cin>>n;
for(int i=0; i<n; i++)
cin>>postorder[i];
for(int i=0; i<n; i++){
cin>>inorder[i];
pos[inorder[i]]=i;
}
build(0,n-1,0,n-1);
bfs();
return 0;
}