#include<stdio.h>

int pre[50], in[50], post[50];
int k = 0, j = 0;

void rec(int left, int right)
{
	if (left >= right)
		return;
	int root, p;
	root = pre[j++];
	for (int i = left; i < right; i++)
		if (in[i] == root)
			p = i;

	rec(left, p);
	rec(p + 1, right);
	post[k++] = root;
}

int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &pre[i]);
	for (int i = 0; i < n; i++)
		scanf("%d", &in[i]);
	rec(0, n);
	for (int i = 0; i < n; i++)
	{
		if (i)
			printf(" ");
		printf("%d", post[i]);
	}
	printf("\n");
}

