import java.util.*;
public class Main {
static Map<Integer, Integer> map = new HashMap<>();
static int[] postorder;
static int[] inorder;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
postorder = new int[n];
inorder = new int[n];
for (int i = 0; i < n; i++) {
postorder[i] = scanner.nextInt();
}
for (int i = 0; i < n; i++) {
inorder[i] = scanner.nextInt();
map.put(inorder[i], i);
}
Node root = build(0, n - 1, 0, n - 1);
bfs(root);
}
private static void bfs(Node root) {
Queue<Node> queue = new LinkedList<>();
queue.add(root);
while (!queue.isEmpty()) {
Node node = queue.poll();
if (node.left != null) {
queue.add(node.left);
}
if (node.right != null) {
queue.add(node.right);
}
System.out.print(node.val + " ");
}
}
private static Node build(int pl, int pr, int il, int ir) {
if (pl > pr || il > ir) {
return null;
}
int rootVal = postorder[pr];
int rootIndex = map.get(rootVal);
Node root = new Node(rootVal);
root.left = build(pl, pl + rootIndex - il - 1, il, rootIndex - 1);
root.right = build(pl + rootIndex - il, pr - 1, rootIndex + 1, ir);
return root;
}
static class Node {
int val;
Node left;
Node right;
Node() {}
Node(int x) { val = x; }
}
}