/*
 * FileName:     fix
 * CreatedDate:  2020-07-12 20:45:35 +0900
 * LastModified: 2020-07-12 21:22:36 +0900
 */

#include <stdio.h>
#include <stdlib.h>
int c = 0;
void reconstruct(int *preorder, int *inorder, int left, int right, int *pos, int *postorder){
    if(left>=right)return;
    int root, root_pos;
    root = preorder[*pos];
    *pos = *pos+1;
    root_pos = left;
    for(int i=left; i<right; i++){
        if(inorder[i]==root){
            root_pos = i;
        }
    }
    reconstruct(preorder, inorder, left, root_pos, pos, postorder);
    reconstruct(preorder, inorder, root_pos + 1, right, pos, postorder);
    
    postorder[c++] = root;

}
int main(void){
    int n;scanf("%d", &n);
    int pos = 0;

    int *preorder = malloc(n*sizeof(int));
    int *inorder = malloc(n*sizeof(int));
    int *postorder = malloc(n*sizeof(int));
    for(int i=0; i<n; i++) scanf("%d", preorder+i);
    for(int i=0; i<n; i++) scanf("%d", inorder+i);
    reconstruct(preorder, inorder, 0, n, &pos, postorder);
    for(int i=0; i<n; i++){
        if(i==0){
            printf("%d", postorder[0]);
            continue;
        }
        printf(" %d", postorder[i]);
    }
    printf("\n");
    free(preorder);
    free(inorder);
    free(postorder);
    return 0;
}

