#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int a[1005],b[1005];
int c[1005],s;
struct node
{
int data;
struct node *l,*r;
};
struct node *build(int *a,int *b,int t)
{
struct node *root;
int i;
if(t<=0)
return NULL;
root=(struct node *)malloc(sizeof(struct node));
for(i=0; i<t; i++)
{
if(b[i]==*a)
break;
}
root->data=*a;
root->l=build(a+1,b,i);
root->r=build(a+1+i,b+1+i,t-1-i);
return root;
}
void last(struct node *root)
{
if(root!=NULL)
{
last(root->l);
last(root->r);
c[s++]=root->data;
}
}
int main()
{
int n,i;
struct node *root;
while(~scanf("%d",&n))
{
s=0;
for(i=0; i<n; i++)
scanf("%d",&a[i]);
for(i=0; i<n; i++)
scanf("%d",&b[i]);
root=build(a,b,n);
last(root);
for(i=0; i<s; i++)
{
printf("%d",c[i]);
if(i<s-1)
printf(" ");
}
printf("\n");
}
return 0;
}