#include <stdio.h>

int search(int arr[], int val, int n)
{
  int i;

  for (i = 0; i < n; i++)
    if (arr[i] == val)
      return i;
  return -1;
}

int postorder[45];

void po(int inorder[], int preorder[], int n) {

  int rootIndex = search(inorder, preorder[0], n);

  if (rootIndex > 0)
    po(inorder, preorder + 1, rootIndex);

  if (rootIndex != n - 1)
    po(inorder + rootIndex + 1, preorder + rootIndex + 1, n - rootIndex - 1);

  printf("%d ", preorder[0]);
}

int main() {
  int n, i;

  scanf("%d", &n);

  int preorder[n];
  int inorder[n];

  for (i = 0; i < n; i++)
    scanf("%d", &preorder[i]);

  for (i = 0; i < n; i++)
    scanf("%d", &inorder[i]);

  po(inorder, preorder, n);
  printf("\n");
}

