spoj#LCDS. Longest Common Difference Subsequence
Longest Common Difference Subsequence
GIven two sequences of integers, your task is to find the longest common subsequence where every two adjacent values differ the same.
For example, if the sequences are A = {1, 5, 8, 3} and B = {3, 10, 5}, then the common subsequence with adjacent values same are AL = {1, 8, 3} and BL = {3, 10, 5} since the differences in AL are 7 and -5 which is also the same in BL.
Input
First line of the input contains NA and NB, the sizes of the sequences A and B. Then follow two lines, the sequences A and B. (1 <= NA, NB <= 1000 and all values in the sequence will lie between -1e9 and 1e9).
Output
Print one line, the length of the LCDS as described above.
Example
Input:
4 3
1 5 8 3
3 10 5
Output:
3
Input:
1 2
5
6 8
Output:
1