#include<stdio.h>
 
int n,p;
int a1[40],a2[40];
 
void solve(int l,int r){
  if(l>r)return;
  if(l==r){
    if(a2[l]==a1[0])printf("%d",a2[l]);
    else printf("%d ",a2[l]);
    p++;
    return;
  }
 
  int x=a1[p],i;
  p++;
  for(i=l;i<=r;i++){
    if(a2[i]==x)break;
  }
  solve(l,i-1);
  solve(i+1,r);
   
  if(x==a1[0])printf("%d",x);
  else printf("%d ",x);
}
 
int main(){
  int i;

  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&a1[i]);
  for(i=0;i<n;i++)scanf("%d",&a2[i]);
  p=0;
  solve(0,n-1);
  printf("\n");
  return 0;
}