#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

void rec(vi &pre, vi &in, vi &post, int l, int r, int &pos) {
  if (l >= r) return;

  int root = pre[pos++];
  int m = distance(in.begin(), find(in.begin(), in.end(), root));
  rec(pre, in, post, l, m, pos);
  rec(pre, in, post, m + 1, r, pos);
  post.push_back(root);
}

int main() {
  int n, pos = 0;
  cin >> n;

  vi pre(n), in(n), post;
  rep(i, n) cin >> pre[i];
  rep(i, n) cin >> in[i];
  
  rec(pre, in, post, 0, n, pos);

  rep(i, n) printf(i != n - 1 ? "%d " : "%d\n", post[i]);
}

