#include<stdio.h>
#include<stdlib.h>
  
int preOrder[40],inOrder[40];
 
void solve(int x,int y){
  int i;
  static int p=0;
  if(x>y) return;
  if(x==y){
    if(inOrder[x]==preOrder[0]) printf("%d",inOrder[x]);  
    else printf("%d ",inOrder[x]);
    p++;
    return;
  }
  int x=preOrder[p];
  p++;
  for(i=x;i<=y;i++){
    if(inOrder[i]==x) break;
  }
  solve(x,i-1);
  solve(i+1,y);
  if(x==preOrder[0]) printf("%d",x);
  else printf("%d ",x);
}
  
int main(){
  int i,n;
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&preOrder[i]);
  for(i=0;i<n;i++) scanf("%d",&inOrder[i]);
  solve(0,n-1);
  printf("\n");
  return 0;
}