//#include <bits/stdc++.h>
#include<algorithm>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stdio.h>
#include<string.h>
using namespace std;
const int maxn=50;
struct st
{
int data;
st* l;
st* r;
};
int pre[maxn];
int in[maxn];
int n;
st* create(int prel,int prer,int inl,int inr)
{
if(prel>prer)
{
return NULL;
}
st* root=new st;
root->data=pre[prel];
int k;
for(k=inl; k<=inr; k++)
{
if(in[k]==pre[prel])
break;
}
int numleft=k-inl;
root->l=create(prel+1,prel+numleft,inl,k-1);
root->r=create(prel+numleft+1,prer,k+1,inr);
return root;
}
void exchange(st* root)
{
st* node=root;
if(node!=NULL)
{
st* temp=node->l;
node->l=node->r;
node->r=temp;
}
}
st* invertTree(st* root)
{
st* node=root;
if(root==NULL)
{
return root;
}
invertTree(node->l);
invertTree(node->r);
exchange(node);
return root;
}
int num=0;
void bfs(st* root)
{
queue<st*>q;
q.push(root);
while(!q.empty())
{
st* now=q.front();
q.pop();
printf("%d",now->data);
num++;
if(num<n)
printf(" ");
if(now->l!=NULL)
q.push(now->l);
if(now->r!=NULL)
q.push(now->r);
}
}
int main()
{
scanf("%d",&n);
for(int i=0; i<n; i++)
{
scanf("%d",&in[i]);
}
for(int i=0; i<n; i++)
{
scanf("%d",&pre[i]);
}
st* root=create(0,n-1,0,n-1);
root=invertTree(root);
bfs(root);
return 0;
}