#include #include #include using namespace std; #define REP(i,n) for(int i = 0; i < n; i++) #define N 100005 typedef vector vi; int main(void){ int n; vi s(N); vi t(N); vi w(N); vi ans; cin.tie(0); ios::sync_with_stdio(false); cin >> n; REP(i,n) cin >> s[i]; REP(i,n) cin >> t[i]; REP(i,n) w[s[i]] = i; int j = -1; REP(i,n) { if(w[t[i]] > j){ ans.push_back(t[i]); j = w[t[i]]; } } sort(ans.begin(), ans.end()); for(vector::iterator it = ans.begin(); it != ans.end(); it++){ cout << *it << endl; } }