#include<stdio.h>
#define MAX 50



typedef struct cell{
 int id;
 struct cell *right;
 struct cell *left;
 struct cell *parent;
}cell;


void postorder(cell *root,cell N[],int x){
cell *p=root;
if(p->left!=NULL){postorder(p->left,N,x);}
if(p->right!=NULL){postorder(p->right,N,x);}

if(p->id!=x){printf("%d ",p->id);}
else{printf("%d",p->id);}

return;
}


int reconstruction(int A[],int B[],int start,int last,cell N[],int n){
int i,j;
int a,b;
int x;


if(start!=last){/*要素二つ以上*/

 for(i=0;i<n;i++){
  for(j=start;j<=last;j++){

   if(B[j]==A[i]){x=A[i];
    a=reconstruction(A,B,start,j-1,N,n);
    if(a!=-1){

     N[A[i]].left=&N[a];
     N[a].parent=&N[A[i]];
    }
    else{
     N[A[i]].left=NULL;
    }

    b=reconstruction(A,B,j+1,last,N,n);
    if(b!=-1){
     N[A[i]].right=&N[b];
     N[b].parent=&N[A[i]];
    }
    else{
     N[A[i]].right=NULL;
    }

    return x;
   }

  }/*for j end*/

 }/*for i end*/

}/*ifおわり*/


if(start==last){/*要素一つ*/
 N[B[start]].right=NULL;
 N[B[start]].left=NULL;
 return B[start];
}

if(start>last){
 return -1;
}




}




int main(){
int n,i;
int A[MAX];
int B[MAX];
cell N[MAX];
cell *root;
int x;

scanf("%d",&n);
for(i=0;i<n;i++)scanf("%d",&A[i]);
for(i=0;i<n;i++)scanf("%d",&B[i]);

for(i=0;i<=n;i++)N[i].id=i;


x=reconstruction(A,B,0,n-1,N,n);

root=&N[x];



postorder(root,N,x);
printf("\n");

return 0;
}
