#include<stdio.h>
#define MAX 40
int distance(int start,int key);
int solve(int l,int r);

int n,pos=0,cout = 0;
int P[MAX],I[MAX],A[MAX];
 
int distance(int start,int key){
  int i,count=0;
  for(i=start;i<MAX;i++){
    if(I[i]!=key)
      count++;
    else break;
  }
  return count;
}
   
int solve(int l,int r){
  int root,d;
  if(l-r>=0)return -1;
  root=P[pos];
  pos++;
  d=distance(0,root);
  if(d>n)return -1;
  solve(l, d);
  solve(d+1, r);
  A[cout++]=root;
  return 0;
}
 
int main(){
  int k,i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&k);
    P[i]=k;
  }
  for(i=0;i<n;i++){
      scanf("%d",&k);
      I[i]=k;
  }
  solve(0,n);

  for(i=0;i<n;i++){
    if(i<n-1)printf("%d ",A[i]);
    else printf("%d\n",A[i]);
  }
  return 0;
}