/** * @FileName a.cpp * @Author kanpurin * @Created 2020.06.07 15:41:33 **/ #include "bits/stdc++.h" using namespace std; typedef long long ll; int main() { int n;cin >> n; vector a(n),b(n); vector used(n,false); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> b[i]; } int t = n-1; vector ans; for (int i = n-1; i >= 0; i--){ if (used[a[i]-1]) continue; while(!used[a[i]-1]) { used[b[t]-1] = true; t--; } ans.push_back(a[i]); } sort(ans.begin(), ans.end()); for (int i = 0; i < ans.size(); i++) { cout << ans[i] << endl; } return 0; }