#include <stdio.h>
#include <stddef.h>

int indent = 0;

int search(int *data, int left, int right, int x)
{
	for(int i = left; i <= right; ++i)
	{
		if(data[i] == x) { return i; }
	}
	return -1;
}

void reconstruct(int *pre, int pre_idx, int *in, int in_left, int in_right)
{
	if(in_left <= in_right)
	{
		int pos = search(in, in_left, in_right, pre[pre_idx]);
		if(pos != -1)
		{
			int pre_left  = pre_idx + 1;
			int pre_right = pre_idx + 1 + (pos - in_left);

			reconstruct(pre, pre_left,  in, in_left, pos - 1);
			reconstruct(pre, pre_right, in, pos + 1, in_right);
		}
		
		printf("%d", pre[pre_idx]);
		if(pre_idx != 0) { printf(" "); }
	}
}

int main()
{
	int n, pre[40], in[40];
	
	scanf("%d", &n);
	for(int i = 0; i < n; ++i)
	{
		scanf("%d", &pre[i]);
	}
	for(int i = 0; i < n; ++i)
	{
		scanf("%d", &in[i]);
	}

	reconstruct(pre, 0, in, 0, n-1);
	printf("\n");
}


