#include <stdio.h>

typedef struct {
	int parent;
	int left, right;
}Node;

int linear_search(int* xs, int size, int x)
{
	int i;
	for (i = 0; i < size; i++) {
		if (xs[i] == x) {
			return i;
		}
	}
	return -1;
}

Node tree[50];

int prewalked[50];
int inwalked[50];

int n;

int reconstruction_tree(int from, int to, int root_pos, int parent)
{
	int i;
	int v;

	for (i = from; i < to; i++) {
		if ((v = inwalked[i]) == prewalked[root_pos]) {
			tree[v].parent = parent;

			tree[v].left = reconstruction_tree(from, i, root_pos + 1, v);
			tree[v].right = reconstruction_tree(i+1, to, root_pos +  (i - from) + 1, v);

			return v;
		}
	}

	return -1;
}

int result[50];
int resultcnt;

void postorder_walk(int p)
{
	if (p > n || p < 0) {
		return;
	}
	postorder_walk(tree[p].left);
	postorder_walk(tree[p].right);

	result[resultcnt++] = p;
}

int main()
{
	int i;
	int root;

	for (i = 0; i < 50; i++) {
		tree[i].parent = -1;
	}

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%d", &(prewalked[i]));
	}
	for (i = 0; i < n; i++) {
		scanf("%d", &(inwalked[i]));
	}

	root = reconstruction_tree(0, n, 0, -1);

	postorder_walk(root);

	for (i = 0; i < resultcnt; i++) {
		if (i == 0) {
			printf("%d", result[i]);
		}
		else {
			printf(" %d", result[i]);
		}
	}


	return 0;
}