LCDS - 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.

Examples

Input:
4 3
1 5 8 3
3 10 5

Output:
3
Input:
1 2
5
6 8

Output:
1

Added by:Paranoid Android
Date:2011-05-09
Time limit:1s-8.649s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64

hide comments
2013-03-28 11:42:44 Pushkar Mishra
something wrong with the question. The judge is probably not assessing it properly. author please check.
2011-12-16 17:52:53 anubhav
what if length of both the sequence is 1 is the answer 1?
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.