#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<list>
#include<stack>
using namespace std;
template<class T>
class Queue{
private:
list<T>queue;
public:
Queue(){}
~Queue(){}
int Empty(){return queue.empty();}
int Size(){ return queue.size();}
void Push(const T&item){queue.push_back(item);}
T Pop(){T item=queue.front(); queue.pop_front(); return item;}
void Clear(){queue.clear();}
};
template<class T>
struct BTNode{
T data;
BTNode*left,*right;
BTNode(const T&item=T(),BTNode*lp=NULL,BTNode*rp=NULL):data(item),left(lp),right(rp){
}
};
template<class T>
BTNode<T>*GetNode(const T&item,BTNode<T>*lp=NULL,BTNode<T>*rp=NULL){
BTNode<T>*p;
p=new BTNode<T>(item,lp,rp);
if(p==NULL){
cout<<"the new is faliure"<<endl;
exit(1);
}
return p;
}
template<class T>
void level(const BTNode<T>*t,int n){
if(t==NULL)return ;
Queue<const BTNode<T>*>q;
q.Push(t);
int i=0;
while(!q.Empty()){
t=q.Pop();
i++;
if(i==n){
cout<<t->data;
}else{
cout<<t->data<<" ";
}
if(t->left)q.Push(t->left);
if(t->right)q.Push(t->right);
}
}
template<class T>
BTNode<T>*IOMAkeLinked(const T*postl,const T*il,int size)
{
if(size<=0)return 0;
BTNode<T>*left,*right,*t;
const T*rl;
int k;
for(rl=il;rl<il+size;rl++)
{
if(*rl==*(postl+size-1))
{
break;
}
}
k=rl-il;
left=IOMAkeLinked(postl,il,k);
right=IOMAkeLinked(postl+k,il+k+1,size-k-1);
t=GetNode(*(postl+size-1),left,right);
return t;
}
int main()
{
int n;
BTNode<int>*t3;
int pre[105];
int Inor[105];
memset(pre,0,sizeof(pre));
memset(Inor,0,sizeof(Inor));
cin>>n;
for(int i=0;i<n;i++){
cin>>pre[i];
}
for(int i=0;i<n;i++){
cin>>Inor[i];
}
t3=IOMAkeLinked(pre,Inor,n);
level(t3,n);
return 0;
}