#include <stdio.h>

int Pre[40];
int In[40];

void walk(int begin, int end, int *pos) {
	int i;
	if (begin <= end){
		i = begin;
		while (In[i] != Pre[*pos]) i++;
		(*pos)++;
		walk(begin, i - 1, pos);
		(*pos)++;
		walk(i + 1, end, pos);
		printf("%d", In[i]);
		if (In[i] != Pre[0]) printf(" ");
	} else (*pos)--;
}

int main() {
	int i, n, pos;

	scanf("%d", &n);

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

	pos = 0;
	walk(0, n - 1, &pos);
	printf("\n");

	return 0;
}
