#include<iostream>
using namespace std;
int n,m,a[40],b[40],c[41];
void solve(int l,int r){
  //cout<<"l:"<<l<<",r:"<<r<<",m:"<<m<<endl;//確認用
  if(l>r)return;
  int x=a[m++];
  //cout<<"x:"<<x<<",c[x]-1:"<<c[x]-1<<",c[x]+1:"<<c[x]+1<<endl;//確認用
  solve(l,c[x]-1);
  solve(c[x]+1,r);
  cout<<x<<" \n"[x==a[0]];
}
int main(){
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<n;i++)cin>>b[i],c[b[i]]=i;
  solve(0,n-1);
  return 0;
}

