#include<stdio.h>
#define N 40
   
int n,res,A[N],B[N];

void solve(int l,int r){
   
  int p,i;
 
  p=A[res];
   
  if(l>r)return;
  if(l==r){
    if(B[l]==A[0]) printf("%d",B[l]);
    else printf("%d ",B[l]);
    res++;
    return;
  }
   
  res++;
  for(i=l;i<=r;i++){
    if(B[i]==p)break;
  }
  solve(l,i-1);
  solve(i+1,r);
     
  if(p==A[0])printf("%d",p);
  else printf("%d ",p);
}
 
int main(){
   
  int i;
 
  scanf("%d",&n);
 
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
 
  for(i=0;i<n;i++){
    scanf("%d",&B[i]);
  }
   
  solve(0,n-1);
  printf("\n");
 
  return 0;
}

