#include<stdio.h>
#define N 40
int n,ptw;
int a[N];
int b[N];
 
void solve(int,int);                \
 
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]);
  ptw = 0;
  solve(0,n-1);
  printf("\n");
  return 0;
}
 
 
 
void solve(int l,int r){
  
  int x = a[ptw],i;
      
  if(l > r)return;
 
  if(l == r){
    if(b[l] == a[0])printf("%d",b[l]); 
    else printf("%d ",b[l]);
    ptw++;
    return;
  } 
  ptw++;
 
  for(i = l;i <= r;i++) if(b[i] == x)break; 
   
  solve(l,i-1);
  solve(i+1,r);
    
  if(x == a[0])   printf("%d",x);
 
  else printf("%d ",x);
}