#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

vector<int> pre, in, post;
int pos;

void reconstruction(int l, int r)
{
	if (l >= r) return;
	int root = pre[pos++];
	int m = distance(in.begin(), find(in.begin(), in.end(), root));

	reconstruction(l, m);
	reconstruction(m + 1, r);

	post.push_back(root);
}

int main()
{
	int n, x;
	scanf("%d", &n);

	for (int i = 0; i < n; i++) {
		scanf("%d", &x);
		pre.push_back(x);
	}
	for (int i = 0; i < n; i++) {
		scanf("%d", &x);
		in.push_back(x);
	}
	pos = 0;
	reconstruction(0, n);

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