#include <stdio.h>
#include <stdlib.h>

int c =0;

void func(int parr [] ,int iarr[], int len , int res[]){
  if (len == 0 ){return;}
  int root = parr[0];
  if (len >= 1){
    int i;
    for ( i = 0; i < len; i++){
      if (iarr[i] == root){break;}
    }
    int repre[i] , rein[i];
    for ( int j = 0; j <= i; j++){
      repre[j] = parr[ j +1];
      rein[j] = iarr[j];
    }
  
    func( repre,rein, i ,res);
  
    if (len - i - 1 > 0){
      int k = len - i -1;
      int rirepre[k] , rirein[k];
      for ( int j = 0; j < k; j++){
	rirepre[j ] = parr[i+ j +1];
	rirein[j] = iarr[j +i+1];
  
      }
      func( rirepre,rirein, k ,res);
    }
  }  
  //printf("%d " , root);
  res[c] = root;
  c++;
  return;
  
};



int main(){

  int n ;
  scanf ("%d\n",&n);
  int pre_arr[n];
  int in_arr[n];
  int resarr[n];
  for (int i = 0; i < n; i++){
    scanf("%d",&pre_arr[i]);
  }

    for (int i = 0; i < n; i++){
    scanf("%d",&in_arr[i]);
  }
    
    func(pre_arr , in_arr, n ,resarr);

   for (int i = 0; i < n; i++){
     printf("%d",resarr[i]);
     if (i != n-1){printf(" ");}
  }

  printf("\n");

  return 0;
}

