#include <bits/stdc++.h>
using namespace std;
const int N=110;
int inorder[N],postorder[N];
struct Node
{
int key;
Node *l,*r;
Node(){}
Node(int key):key(key),l(NULL),r(NULL){}
};
Node *build(int pl,int pr,int il,int ir)
{
if(pl>pr)
{
return NULL;
}
Node *root=new Node(postorder[pr]);
int k=il;
while(inorder[k]!=root->key)
{
k++;
}
root->l=build(pl,pl+k-1-il,il,k-1);
root->r=build(pl+k-il,pr-1,k+1,ir);
return root;
}
Node *pre_order_traverse(Node *root)
{
if(root==NULL)
{
return NULL;
}
cout<<root->key<<" ";
if(root->l) pre_order_traverse(root->l);
if(root->r) pre_order_traverse(root->r);
}
int main()
{
int n;
cin>>n;
for(int i=0;i<=n-1;i++)
{
cin>>inorder[i];
}
for(int i=0;i<=n-1;i++)
{
cin>>postorder[i];
}
Node *root=build(0,n-1,0,n-1);
pre_order_traverse(root);
return 0;
}