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

#define NIL -1
#define N 41

typedef struct {
  int pid;
  int leftc;
  int rightc;  
} Node;

int findSubtreeRoot (Node*, int*, int*, int*, int, int);
void traverse (Node*, int);

int main () {
  int n;
  Node tree[N];
  int preorder[N];
  int inorderID[N];
  int inorderInfo[N];
  
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    tree[i].pid = NIL;
    tree[i].leftc = NIL;
    tree[i].rightc = NIL;
  }

  for (int i = 1; i <= n; i++) {
    scanf("%d", &preorder[i]);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &inorderID[i]);
    inorderInfo[inorderID[i]] = i;
  }
  
  int pid = findSubtreeRoot(tree, preorder, inorderID, inorderInfo, 1, n + 1);

  traverse(tree, pid);
  
  return 0;
}

int findSubtreeRoot (Node* tree, int* preorder, int* inorderID, int* inorderInfo, int left, int right) {
  static int cnt = 1;
  int length = right - left;

  if (length < 1) {
    return NIL;    
  }

  int pid    = preorder[cnt++];
  int pivot  = inorderInfo[pid];
  int leftc  = findSubtreeRoot(tree, preorder, inorderID, inorderInfo, left, pivot);
  int rightc = findSubtreeRoot(tree, preorder, inorderID, inorderInfo, pivot + 1, right);

  tree[pid].leftc  = leftc;
  tree[pid].rightc = rightc;
  tree[leftc].pid  = pid;
  tree[rightc].pid = pid;
  
  return pid;
}

void traverse (Node* tree, int id) {
  if (tree[id].leftc != NIL) {
    traverse(tree, tree[id].leftc);
  }
  if (tree[id].rightc != NIL) {
    traverse(tree, tree[id].rightc);
  }
  if (tree[id].pid != NIL) {
    printf("%d ", id);
  } else {
    printf("%d\n", id);
  }

  return;
}

