#include <stdio.h>

int parent[40];
int left[40];
int right[40];
int pre[40];
int in[40];
int post[40];
int posthead;

void push(int node){
    post[posthead++] = node;
}

void postorder(int node){
    if(node == -1) return;
    postorder(left[node]);
    postorder(right[node]);
    push(node);
}

int find(int a[], int v, int b, int c){
    for(int i=b; i<c; i++)
        if(a[i] == v)
            return i;
    return -1;
}

int recon(int parent, int pa, int pb, int ia, int ib){
    int root = pre[pa];
    int i = find(in, root, ia, ib);
    int nl = i - ia;
    if(nl == 0)
        left[root] = -1;
    else
        left[root] = recon(root, pa + 1, pa + nl + 1, ia, ia + nl);
    int nr = ib - i - 1;
    if(nr == 0)
        right[root] = -1;
    else
        right[root] = recon(root, pa + nl + 1, pb, i + 1, ib);
    return root;
}

int main(void){
    int n;
    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]);
    int root = recon(-1, 0, n, 0, n);
    postorder(root);
    for(int i=0; i<n; i++){
        printf("%d", post[i]);
        putchar(i<n-1?' ':'\n');
    }
}

