#include<stdio.h>
#include<stdlib.h>

int *pre, *in, *post, pos, target, n;

int Lsearch(int);
void Rec(int, int);

int main(void)
{
  int i;
  scanf("%d", &n);
  pre = (int*)malloc(sizeof(int) * n);
  in = (int*)malloc(sizeof(int) * n);
  post = (int*)malloc(sizeof(int) * n);
  for (i = 0; i < n; i++) scanf("%d", &pre[i]);
  for (i = 0; i < n; i++) scanf("%d", &in[i]);
  Rec(0, n - 1);
  for (i = 0; i < n- 1; i++) printf("%d ", post[i]);
  printf("%d\n",post[i]);
  free(pre);
  free(in);
  free(post);
}

int Lsearch(int data)
{
  int i;
  for (i = 0; i < n; i++) {
    if (in[i] == data) return i;
  }
  return n;
}

void Rec(int left, int right)
{
  int root, dis;
  if (left > right) return;
  root = pre[pos++];
  dis = Lsearch(root);
  Rec(left, dis - 1);
  Rec(dis + 1, right);
  post[target++] = root;
}
