#include<stdio.h>
#define MAX 50

struct NODE { int parent, left, right; };

struct NODE Tree[MAX];
int N;
int pre[MAX];
int ino[MAX];

int cnt = 0;

int Top(int sp, int ep) {
	int ans;
	for (int i = 0; i < 50; i++) {
		for (int j = sp; j < ep; j++) {
			if (pre[i] == ino[j]) {
				ans = j;
				return ans;
			}
		}
	}
}

void Hierarchy(int sp, int top, int ep) {
	int lTop, rTop;
	if (ep - sp != 1) {
		if (sp != top) {
			lTop = Top(sp, top);
			Tree[ino[top]].left = ino[lTop];
			Tree[ino[lTop]].parent = ino[top];
			Hierarchy(sp, lTop, top);
		}
		if (top + 1 != ep) {
			rTop = Top(top + 1, ep);
			Tree[ino[top]].right = ino[rTop];
			Tree[ino[rTop]].parent = ino[top];
			Hierarchy(top + 1, rTop, ep);
		}
	}

}

void Postorder(int id) {
	if (id == -1)return;
	Postorder(Tree[id].left);
	Postorder(Tree[id].right);
	printf("%d", id);
	cnt++;
	if (cnt != N)printf(" ");
}

int main() {
	int root;
	for (int i = 0; i < 50; i++) {
		Tree[i].parent = -1; Tree[i].left = -1; Tree[i].right = -1;
		pre[i] = -1; ino[i] = -1;
	}
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &pre[i]);
	}
	for (int i = 0; i < N; i++) {
		scanf("%d", &ino[i]);
	}
	root = ino[Top(0, N)];
	Hierarchy(0, Top(0, N), N);

	Postorder(root); printf("\n");

	return 0;
}
