#include <stdio.h>
#include <stdlib.h>

#define MAX 40

typedef struct node_t {
	int key;
	struct node_t *parent;
	struct node_t *left;
	struct node_t *right;
} node;

node* newNode(int);
void reTree(int, int, int, node *, char);
void postorder(node *);

int pre[MAX], in[MAX];
int flag=0;

int main(void)
{
	int i, n;
	node *root;
	
	scanf("%d",&n);
	for (i=0; i<n; i++) {
		scanf("%d",&pre[i]);
	}
	for (i=0; i<n; i++) {
		scanf("%d",&in[i]);
	}
	
	root = newNode(0);
	
	reTree(n, 0, 0, root, 'l');
	
	postorder(root->left);
	printf("\n");
	
	return 0;
}

node* newNode(int key)
{
	node *tmp;
	
	tmp = (node *)malloc(sizeof(node));
	if (tmp == NULL) exit(0);
	
	tmp->key = key;
	tmp->parent = NULL;
	tmp->left = NULL;
	tmp->right = NULL;
	
	return tmp;
}

void reTree(int n, int phead, int ihead, node *parent, char ch)
{
	int cnt, key;
	node *node;
	
	if(n==0) return;
	
	key = pre[phead];
	cnt = 0;
	
	while (in[ihead + cnt] != key) {
		cnt++;
	}
	
	
	node = newNode(key);
	node->parent = parent;
	if(ch == 'l') parent->left = node;
	else if(ch == 'r') parent->right = node;
	
	reTree(cnt, phead+1, ihead, node, 'l');
	reTree(n-cnt-1, phead+cnt+1, ihead+cnt+1, node, 'r');
}

void postorder(node *node)
{
	
	if(node->left != NULL) postorder(node->left);
	if(node->right != NULL) postorder(node->right);
	if (flag==0) {
		printf("%d",node->key);
		flag = 1;
	} else {
		printf(" %d",node->key);
	}
}