#include <stdio.h>          // printf(), scanf()
#define MAX_N 40

int n;
int preorder[MAX_N];
int inorder[MAX_N];
int post[MAX_N];
int n_post;
int pos;

int
distance(int x)
{
	int i;

	for (i = 0; i < n; ++i)
	{
		if (inorder[i] == x)
			return i;
	}

	return -1;
}

void
rec(int l, int r)
{
	if (l >= r)
		return;

	int root = preorder[pos++];
	int m = distance(root);
	rec(l, m);
	rec(m + 1, r);
	post[n_post++] = root;
}

void
solve()
{
	int i;

	pos = 0;
	rec(0, n);
	for (i = 0; i < n_post; ++i)
		printf("%d%c", post[i], (i != n_post - 1) ? ' ' : '\n');
}

int
main(int argc, char** argv)
{
	int i;

	n_post = 0;
	scanf("%d", &n);
	for (i = 0; i < n; ++i)
		scanf("%d", &preorder[i]);

	for (i = 0; i < n; ++i)
		scanf("%d", &inorder[i]);

	solve();
	return 0;
}