#include<stdio.h>
#define MAX 40
void A(int,int);
int baby;
int killme;
int n,i,P[40],I[40],O[40];
int main(){
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&P[i]);
  for(i=0;i<n;i++)scanf("%d",&I[i]);
  A(0,n-1);
  printf("%d",O[0]);
  for(i=1;i<n;i++)printf(" %d",O[i]);
  printf("\n");
  return 0;
}
void A(int a,int b){
  int i=killme++;
  int t;
  for(t=0;I[t]!=P[i];t++);
  if(a<b){
    if(a!=t)A(a,t-1);
    if(b!=t)A(t+1,b);
  }
  O[baby++]=I[t];
}

