#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#define MAX 40
int n, preorder[MAX],inorder[MAX],post[MAX],n_post,pos;

void rec(int l, int r)
{
	if (l >= r){return;}
	int root = preorder[pos++];
	int m = distance(root);
	rec(l, m);
	rec(m+1,r);
	post[n_post++] = root;
}


int distance(int x)
{
	int i;
	for (i = 0; i < n; ++i){
		if (inorder[i] == x)
			return i;
	}
	return -1;
}


void solve()
{
	int i;
	rec(0, n);
	for (i = 0; i < n_post; ++i)
		printf("%d%c", post[i], (i != n_post - 1) ? ' ' : '\n');
}

int main(int argc, char** argv)
{
	int i;
	n_post = 0;
	scanf("%d", &n);
	for (i = 0; i < n; ++i){scanf("%d", &preorder[i]);}
	for (i = 0; i < n; ++i){scanf("%d", &inorder[i]);}
	solve();

	return 0;
}

