#include<stdio.h>

int n,pos;
int a[40],b[40];

void solve(int l,int r){
  if(l>r)return;
  if(l==r){
    if(b[l]==a[0])printf("%d",b[l]);
    else printf("%d ",b[l]);
    pos++;
    return;
  }

  int x=a[pos],i;
  pos++;
  for(i=l;i<=r;i++){
    if(b[i]==x)break;
  }
  solve(l,i-1);
  solve(i+1,r);
  
  if(x==a[0])printf("%d",x);
  else printf("%d ",x);
}

int main(){
  int i;
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&a[i]);
  for(i=0;i<n;i++)scanf("%d",&b[i]);
  pos=0;
  solve(0,n-1);
  printf("\n");
  return 0;
}