#include <stdio.h>
void Repair(int ,int );
int Preorder[100],Inorder[100],Postorder[100],postnode=0,nownode=0;
int main(void){
  int i,n;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&Preorder[i]);
  for(i=0;i<n;i++)
    scanf("%d",&Inorder[i]);

  Repair(0,n);

  for(i=0;i<n;i++){
    printf("%d",Postorder[i]);
    if(i!=n-1)printf(" ");
  }
  printf("\n");
  return 0;
}
void Repair(int left,int right){
  int rootnode,distance;
  if(left<right){
    rootnode=Preorder[nownode++];
    distance=0;
    while(distance<right){
      //search for element of root
      if(Inorder[distance]==rootnode)
        break;
      distance++;
    }
    Repair(left,distance);//left tree (include element of root)
    Repair(distance+1,right);//right tree
    Postorder[postnode++]=rootnode;
  }
}
