#include<bits/stdc++.h>
using namespace std;
#define rep(x,y,z) for(int x=(y);(x)<(z);x++)
const int maxn=200;
int n;
int post[maxn],ind[maxn];
vector<int> g[maxn];
vector<int> ans;
void build(int l1,int r1,int l2,int r2,int dep){
if(l1>r1) return ;
g[dep].push_back(post[r2]);
int i=l1;
while(ind[i]!=post[r2]) i++;
build(l1,i-1,l2,r2-r1+i-1,dep+1);
build(i+1,r1,r2-r1+i,r2-1,dep+1);
}
int main(){
cin>>n;
rep(i,1,n+1) cin>>ind[i];
rep(i,1,n+1) cin>>post[i];
build(1,n,1,n,0);
rep(i,0,maxn){
if((i&1)==0){
for(int j=g[i].size()-1;j>=0;j--)
ans.push_back(g[i][j]);
}else{
rep(j,0,g[i].size())
ans.push_back(g[i][j]);
}
}
rep(i,0,ans.size()){
cout<<ans[i];
if(i!=ans.size()-1) cout<<" ";
else cout<<"\n";
}
return 0;
}