#include "bits/stdc++.h" using namespace std; #define DEBUG(x) cout<<#x<<": "< #define vl vector #define vii vector< vector > #define vll vector< vector > #define vs vector #define pii pair #define pis pair #define psi pair #define pll pair const int inf = 1000000001; const ll INF = 1e18 * 2; #define MOD 1000000007 #define mod 1000000009 #define pi 3.14159265358979323846 #define Sp(p) cout<> n; vi a(n), b(n); for (i = 0; i < n; i++) { cin >> a[i]; a[i]--; } for (i = 0; i < n; i++) { cin >> b[i]; b[i]--; } vector > p(n); for (i = 0; i < n; i++) { p[a[i]].first.first = i; p[b[i]].first.second = i; p[i].second = i; } sort(p.begin(), p.end()); reverse(p.begin(), p.end()); int high = inf; vi ans; for (i = 0; i < n; i++) { if (p[i].first.second < high) { ans.push_back(p[i].second + 1); high = p[i].first.second; } } sort(ans.begin(), ans.end()); for (i = 0; i < ans.size(); i++) { cout << ans[i] << endl; } }