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

int nn = 0 , pos;

int find( int a[] , int n , int s ){
	
	int i;
	for( i = 0; i < n; i++ ){
		if( a[i] == s ){
			return i;
		}
	}
	return -1;
}

void rec( int l , int r , int n , int pre[] , int in[] , int post[] ){
	
	if( l >= r ){
		return;
	}
	int root = pre[pos++];
	int m = find( in , n , root );
	rec( l , m , n , pre , in , post );
	rec( m+1 , r , n , pre , in , post );
	post[nn++] = root;
}

void solve( int n , int pre[] , int in[] , int post[] ){
	
	pos = 0;
	rec( 0 ,n , n , pre , in , post );
	printf( "%d" , post[0] );
	
	for( int i = 1; i < n; i++ ){
		printf( " %d" , post[i] );
	}
	printf( "\n" );
} 

int main( void ){
	
	int n;
	
	scanf( "%d" , &n );
	
	int *pre,*in,*post;
	pre = ( int* )malloc( sizeof(int)*n );
	in = ( int* )malloc( sizeof(int)*n );
	post = ( int* )malloc( sizeof(int)*n );
	
	for( int i = 0; i < n; i++ ){
 		scanf( "%d" , &pre[i] );
	}
	for( int i = 0; i < n; i++ ){
		scanf( "%d" , &in[i] );
	}
	
	solve( n , pre , in , post );
	
	return 0;
}
	
