#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int,int> PII;
const int N = 55;
int a[N],b[N],p[N];
int n;
vector<int> q[N];
void build(int al,int ar,int ll,int lr,int d){
if(al>ar) return ;
int k=a[ar];
q[d].push_back(k);
int root=p[k];
build(al, root-1-ll+al, ll, k-1, d+1);
build(root-ll+al, ar-1, root+1, lr, d+1);
}
int main(){
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
}
for(int i=0;i<n;i++){
scanf("%d",&b[i]);
p[b[i]]=i;
}
build(0,n-1,0,n-1,0);
int count=1;
for(int i=0;i<n;i++){
for(auto x: q[i]){
if(count<n){
printf("%d ",x);
}
else{
printf("%d",x);
}
count+=1;
}
}
return 0;
}