#include <stdio.h>

#define N 40

int pre[N],in[N],po[N];
int n,mark=0;
int j = 0;

void rec(int l, int r) {
	int i;
	int c,m;

	if (l >= r) return;
	c = pre[mark++];
	for (i = 0; i < n;i++) {
		if (in[i] == c) {
			m = i;
			break;
		}
	}

	rec(l, m);
	rec(m+1, r);
	po[j++] = c;
}

int main() {
	int i;

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

	rec(0,n);
	for (i = 0;i < n;i++) {
		if (i) printf(" ");
		printf("%d",po[i]);
	}
	printf("\n");

	return 0;
}