Rakib got the result of his previous English exam. But he did very poor in the exam, and went to his English teacher to increase his marks.
There was a question in the exam where Rakib had to rearrange sentences to make a valid story. The correct answer was the sequence but Rakib wrote the sequence . The teacher was supposed to give 1 mark for each such that . But because of Rakib's request, the teacher asked Rakib to find a common subsequence between his answer and the correct one. His marks will then be equal to the length of the common subsequence he finds.
As Rakib wants the highest marks possible, he has to find the longest common subsequence. Since he is really foolish, he wants you to help him.
First you will be given an integer () — the number of sentences in the sequence.The next line will contain integers (). Next line will also contain integers ().
Print a single integer which indicates the highest possible marks that Rakib can obtain.
8 2 4 3 5 6 1 8 7 2 8 4 3 5 6 7 1
5 1 2 3 4 5 3 4 1 2 5
Login to submit
First we need to observe that array AAA and BBB are permutations of 111 to nnn. So we can map AAA in...