// @BEGIN_OF_SOURCE_CODE /* @JUDGE_ID: 17243NT 111 C++ */ // Send to judge@uva.es #include #include #ifdef ONLINE_JUDGE #define ins cin #define outs cout #else #define ins fin #define outs fout ifstream fin("myprog.in"); ofstream fout("myprog.out"); #endif int main() { int i, j, k, m; int chronology[20]; int events[20], n; int sequence[20]; while(ins >> n) { for(i = 0; i < n; i++) { ins >> j; chronology[j - 1] = i; } for(;;) { for(i = 0; i < n; i++) { if(ins >> j) { events[i] = j - 1; } else return 0; } m = 0; for(i = 0; i < n; i++) { k = 0; for(j = 0; j < i; j++) if(events[chronology[j]] < events[chronology[i]]) if(sequence[j] > k) k = sequence[j]; sequence[i] = 1 + k; if(sequence[i] > m) m = sequence[i]; } cout << m << endl; } } return 0; } // @END_OF_SOURCE_CODE