#include<iostream>
#include<cstring>
#include<cstdlib>
typedef struct node
{
struct node *left;
struct node *right;
int data;
}Node;
using namespace std;
Node *binarytree(int a[],int b[],int len)
{
int i;
if (len==0)
return NULL;
Node *tree;
tree=(Node *)malloc(sizeof(Node));
tree->data=a[len-1];
for (i=0;i<len;i++)
{
if (b[i]==a[len-1])
break;
}
tree->left=binarytree(a,b,i);
tree->right=binarytree(a+i,b+i+1,len-i-1);
return tree;
}
void printtree(Node *head)
{
if (head==NULL)
return ;
else
{
printtree(head->left);
printtree(head->right);
}
}
int main()
{
int n;
cin>>n;
int mid[n],next[n];
for (int i=0;i<n;i++)
cin>>next[i];
for (int i=0;i<n;i++)
cin>>mid[i];
Node *tree;
tree=binarytree(next,mid,n);
printtree(tree);
}