#include <bits/stdc++.h>
using namespace std;
struct node{
int date;
node* lchild;
node* rchild;
};
int post[30];
int in[30];
int n;
node* create(int postL, int postR, int inL, int inR){
if(postL >postR){
return NULL;
}
node* root = new node;
root->date = post[postR];
int k;
for(k = inL; k < inR; k++){
if(in[k] == post[postR]){
break;
}
}
int num = inR - k;
root->lchild = create(postL, postR-num-1, inL, k-1);
root->rchild = create(postR-num, postR-1, k+1, inR);
return root;
}
void levelOrder(node* tree){
queue<node*> q;
q.push(tree);
int num = 0;
while(!q.empty()){
num++;
node* root = q.front();
q.pop();
cout << root->date;
if(num < n) cout << " ";
if(root->lchild!=NULL) q.push(root->lchild);
if(root->rchild!=NULL) q.push(root->rchild);
}
}
int main(int argc, char** argv) {
cin >> n;
for(int i = 0; i < n; i++){
cin >> post[i];
}
for(int i = 0; i < n; i++){
cin >> in[i];
}
node* root = create(0,n-1, 0, n-1);
levelOrder(root);
return 0;
}