#include <iostream>
#include <stdio.h>#include <queue>
using namespace std;
struct node{
int data;
node* lchild;
node* rchild;
};
const int maxn=100;
int n;
int post[maxn],in[maxn];
node* create(int postl,int postr,int inl,int inr){
if(postl>postr){
return NULL;
}
node* root=new node;
root->data=post[postr];
int k;
for(int i=inl;i<=inr;i++){
if(post[postr]==in[i]){
k=i;
break;
}
}
int numleft=k-inl; //左子树的个数;
root->lchild=create(postl,postl+numleft-1,inl,k-1);
root->rchild=create(postl+numleft,postr-1,k+1,inr);
return root;
}
int num=0;
void bfs(node* root){
if(root==NULL) return;
queue<node*> Q;
while(!Q.empty()) Q.pop();
Q.push(root);
while(!Q.empty()){
node* now;
now=Q.front();
Q.pop();
printf("%d",now->data);
num++;
if(num<n) printf(" ");
if(now->lchild!=NULL) Q.push(now->lchild);
if(now->rchild!=NULL) Q.push(now->rchild);
}
}
int main(int argc, char** argv) {
// int n;
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",&post[i]);
}
for(int i=0;i<n;i++){
scanf("%d",&in[i]);
}
node* root=create(0,n-1,0,n-1);
bfs(root);
return 0;
}