#include <stdio.h>
#include <stdlib.h>


typedef struct{
	int left;
	int right;
}TREE_T;

typedef struct{
	int num;
	int h;
}STRUCT;


TREE_T *TREE;
STRUCT *IN_ORDER;
int *MEM;

int COUNT = 0;


void Make_tree(int left, int right)
{
	int id;
	int soeji;
	int l_max, l_pos, r_max, r_pos;
	int i;

	soeji = MEM[COUNT++];
	id = IN_ORDER[soeji].num;

	l_max = r_max = -1;
	for(i = left; i < soeji; i++){
		if(l_max < IN_ORDER[i].h){
			l_max = IN_ORDER[i].h;
			l_pos = i;
		}
	}
	if(l_max == -1)
		TREE[id].left = -1;
	else
		TREE[id].left = IN_ORDER[l_pos].num;

	for(i = soeji + 1; i <= right; i++){
		if(r_max < IN_ORDER[i].h){
			r_max = IN_ORDER[i].h;
			r_pos = i;
		}
	}
	if(r_max == -1)
		TREE[id].right = -1;
	else
		TREE[id].right = IN_ORDER[r_pos].num;

	// 左側の処理
	if(l_max != -1)
		Make_tree(left, soeji - 1);

	// 右側の処理
	if(r_max != -1)
		Make_tree(soeji + 1, right);
}


// 帰りがけなぞり
int WALK_COUNT = 0;
void Walk_tree(int soeji)
{
	if(TREE[soeji].left != -1)
		Walk_tree(TREE[soeji].left);

	if(TREE[soeji].right != -1)
		Walk_tree(TREE[soeji].right);


	printf("%d", soeji);
	WALK_COUNT++;
	if(WALK_COUNT != COUNT)
		printf(" ");
	else
		printf("\n");
}


int main()
{
	int n;
	int *pre_order;
	int i, j;

	scanf("%d", &n);

	// 初期化
	pre_order = (int *)malloc(sizeof(int) * n);
	IN_ORDER = (STRUCT *)malloc(sizeof(STRUCT) * n);

	TREE = (TREE_T *)malloc(sizeof(TREE_T) * (n + 1));
	MEM = (int *)malloc(sizeof(int) * n);

	// データ入力
	for(i = 0;i < n; i++)
		scanf("%d", &pre_order[i]);
	for(i = 0; i < n; i++)
		scanf("%d", &IN_ORDER[i].num);

	//　必要なデータの前準備
	for(i = 0; i < n; i++){
		for(j = 0; j < n; j++){
			if(pre_order[i] == IN_ORDER[j].num){
				//printf("●");
				MEM[i] = j;
				IN_ORDER[j].h = n - i;
			}//else
				//printf("×");
		}
		//printf("\n");
	}

	// 木の作成
	Make_tree(0, n - 1);

/*	for(i = 1; i < n + 1; i++)
		printf("%d l:%d r:%d\n", i, TREE[i].left, TREE[i].right);
*/
	// 帰りがけなぞり
	Walk_tree(IN_ORDER[MEM[0]].num);

	return 0;
}
