#include<stdio.h>
#define NUL -1
const int N_MAX = 45;
int root;
struct Node{
    int parent, left, right;
};
Node tree[N_MAX];
int pre[N_MAX], in[N_MAX];

void reConstruct(int parent, int * preP, int * inP, int n, bool isLeft){
    if(n==0) return;
    int nowRoot = preP[0];
    tree[nowRoot].parent = parent;
    //getchar();
    //cout<<"-- nowRoot: "<<nowRoot<<endl;
    if(parent==NUL){
        root=nowRoot;
    }else if(isLeft){
        tree[parent].left=nowRoot;
    }else{
        tree[parent].right=nowRoot;
    }
    if(n==1)return;
    int flag = 0;
    for(;flag<n;flag++){
        if(inP[flag]==nowRoot) break;
    }
    //cout<<"nowRoot: "<<nowRoot<<" flag: "<<flag<<endl;
    reConstruct(nowRoot, preP+1, inP, flag, true);
    reConstruct(nowRoot, preP+1+flag, inP+1+flag, n-flag-1, false);
}

void post(int id){
    if(id==NUL) return;
    if(tree[id].left==NUL&&tree[id].right==NUL&&id!=root){
        printf("%d ", id);
        //cout<<id<<" ";
        return;
    }
    post(tree[id].left);
    post(tree[id].right);
    if(id==root){
        printf("%d", id);
        //cout<<id<<endl;
    }else{
        printf("%d ", id);
        //cout<<id<<" ";
    }
}

int main(){
    int n;
    scanf("%d", &n);
    //cin>>n;
    for(int i=0;i<n;i++){
        scanf("%d", &pre[i]);
        //cin>>pre[i];
        tree[i].parent=tree[i].left=tree[i].right=NUL;
    }
    tree[n].parent=tree[n].left=tree[n].right=NUL;
    for(int i=0;i<n;i++){
        scanf("%d", &in[i]);
        //cin>>in[i];
    }
    reConstruct(NUL, pre, in, n, true);
    /*//Debugging/
    for(int i=1;i<=n;i++){
        cout<<"node"<<i<<": p: "<<tree[i].parent<<"  l: "<<tree[i].left<<"  r: "<<tree[i].right<<endl;
    }
    ///Debugging*/
    post(root);
    //cout<<"root: "<<root<<endl;
    return 0;
}

