#include <bits/stdc++.h>
using namespace std;
#define MAX 102
#define NIL -1
int n, pos = 0;
int Pre[MAX], In[MAX];

vector<int> Post;

int find(int id){
    for(int i=0;i<n;++i){
        if(In[i]==id) return i;
    }
}

void rebuild(int l, int r){
    if(l>=r) return;
    int id = Pre[pos];
    pos++;
    int m = find(id);
    rebuild(l,m);
    rebuild(m+1,r);
    Post.push_back(id);
}

int main(){

    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]);
    }
    rebuild(0,n);
    vector<int>::iterator it;
    for(it=Post.begin();it!=Post.end()-1;++it){
        printf("%d ",*it);
    }
    printf("%d\n",*it);


    return 0;
}


