#include #include #include using namespace std; #define REP(i,n) for(int i = 0; i < n; i++) #define N 100000 int main(void){ int n; vector s(N),t(N),w(N),ans; 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 <