Medium Data Structures > Orthogonal Range Search

**IIT (DU)** has started it's journey just a few years ago. Although we are dedicated for software development, some of us are very interested in competitive programming. As a student of 3rd year, yesterday I took a class on Longest Common Subsequence for 1st year students. As you know the algorithm of finding the length of LCS has a high complexity one of them asked me if it is impossible to find the length of LCS of two arrays both of length 100000. I thought a little bit and answered that it is only possible if both the arrays only contain distinct elements. Now I set the same task for you. Input: ------ First line of input consists of two integers **N (1 <= N <= 100000)** and **M (1 <= M <= 100000)** separated by a space. Second line of input contains **N** distinct integers representing the first array. Third line of input contains **M** distinct integers representing the second array. Each number of both array is in range **[1, 1000000]**. Output: ------- You just need to print the length of LCS. Sample Input ------------ 5 5 1 2 3 4 5 2 3 4 5 1 Sample Output ------------- 4

Feroz Ahmmed