rlcs

Two sequences of n, and respectively m positive integers are given. We know that a number can appear in a sequence no more than 100 times.

Task
Determine the length of the longest common subsequence of the two sequences.

Input Data
Input file rlcs.in has the following structure:
- line one contains positive integers n m separated by a space;
- line two contains n positive integers a1 a2
... an, representing the elements of the first sequence separated by spaces;
- line three contains m positive integers b1 b2 ... bm, representing the elements of the second sequence, separated by spaces.

Output Data
Output file rlcs.out will contain a single line with a positive integer representing the length of the longest common subsequence.

Restrictions
0 < n, m <= 10 000
0 <
ai, bi <= 1 000 000
We say that B is a subsequence of the sequence A = a1 a2 ... an if B =
ai(1) ai(2) ... ai(k) where 1 <= i(1) < i(2)
< ... < i(k) <= n and 1 <= k <= n.

Example
rlcs.in rlcs.out
4 5
10 20 30 10
30 20 10 20 10
3

Time limit: 0.3 seconds/test

Iolanda Popa
student - IT College, Iaşi
Contact: iolivp@gmail.com