/* ALDS1_7_D:Reconstruction of a Tree */
/* 20181125 AOJ */

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#define N 100
#define NIL -1

typedef struct {
	int parent;
	int left;
	int right;
} Tree;

int preOrder[N];
int inOrder[N];
int postOrder[N];
void TreeReconstruction(Tree *node, int left, int right);

int pos1, order[N], pos2; 

int main(void) {
	Tree *node = (Tree *)malloc(sizeof(Tree) * N);
	int i, n;

	scanf("%d", &n);
	for(i = 0; i < n; i++) scanf("%d", preOrder + i);
	for(i = 0; i < n; i++) scanf("%d", inOrder + i);
	
	for(i = 0; i < n; i++) order[inOrder[i]] = i;
	pos1 = 0;
	pos2 = 0;
	TreeReconstruction(node, 0, n);

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

	return 0;
}

void TreeReconstruction(Tree *node, int left, int right) {
	int root, temp;

	if(left >= right) return;
	root = preOrder[pos1++];
	temp = order[root];
	TreeReconstruction(node, left, temp);
	TreeReconstruction(node, temp + 1, right);
	postOrder[pos2++] = root;

}
