import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] before = new int[n]; for (int i = 0; i < n; i++) { before[i] = sc.nextInt(); } int idx = 0; HashSet used = new HashSet<>(); TreeSet ans = new TreeSet<>(); for (int i = 0; i < n; i++) { int x = sc.nextInt(); if (!used.contains(x)) { ans.add(x); while (before[idx] != x) { used.add(before[idx]); idx++; } } } StringBuilder sb = new StringBuilder(); for (int x : ans) { sb.append(x).append("\n"); } System.out.print(sb); } }