#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;

int n;
int preorder[40], inorder[40];

void reconstruct(int fp, int lp, int fi, int li)
{
    int root;
    rep(i, n)
    {
        if (preorder[fp] == inorder[i])
            root = i;
    }
    if (root != fi)
    {
        reconstruct(fp + 1, fp + (root - fi) + 1, fi, root);
        cout << " ";
    }
    if (root != li - 1)
    {
        reconstruct(fp + (root - fi) + 1, lp, root + 1, li);
        cout << " ";
    }
    cout << inorder[root];
}

int main()
{
    cin >> n;
    rep(i, n) cin >> preorder[i];
    rep(i, n) cin >> inorder[i];
    reconstruct(0, n, 0, n);
    cout << endl;
    return 0;
}
