#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;
const int NIL = -1;

struct node {
	int parent;
	int left;
	int right;
};

vector<int> pre;
vector<int> ino;
int n;

void reconstruct(int l, int r)
{
	static int k = 0;
	if (l >= r) return;
	int c = pre[k];
	k++;
	int i = 0;
	for (i = 0; i < n; ++i) {
		if (ino[i] == c) break;
	}
	reconstruct(l, i);
	reconstruct(i + 1, r);
	static int m = 0;
	if (m++ > 0) printf(" ");
	printf("%d", c);

}

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		int v;
		scanf("%d", &v);
		pre.push_back(v);
	}
	for (int i = 0; i < n; ++i) {
		int v;
		scanf("%d", &v);
		ino.push_back(v);
	}
	reconstruct(0, n);
	printf("\n");
}