#ABC255E. [ABC255E] Lucky Numbers

[ABC255E] Lucky Numbers

Score : 500500 points

Problem Statement

You are given a sequence of N1N-1 integers S=(S1,S2,,SN1)S = (S_1, S_2, \ldots, S_{N-1}), and MM distinct integers X1,X2,,XMX_1, X_2, \ldots, X_M, which are called lucky numbers.

A sequence of NN integers A=(A1,A2,,AN)A = (A_1, A_2, \ldots, A_N) satisfying the following condition is called a good sequence.

Ai+Ai+1=SiA_i + A_{i+1} = S_i holds for every i=1,2,,N1i = 1, 2, \ldots, N-1.

Find the maximum possible number of terms that are lucky numbers in a good sequence AA, that is, the maximum possible number of integers ii between 11 and NN such that Ai{X1,X2,,XM}A_i \in \lbrace X_1, X_2, \ldots, X_M \rbrace.

Constraints

  • 2N1052 \leq N \leq 10^5
  • 1M101 \leq M \leq 10
  • 109Si109-10^9 \leq S_i \leq 10^9
  • 109Xi109-10^9 \leq X_i \leq 10^9
  • X1<X2<<XMX_1 \lt X_2 \lt \cdots \lt X_M
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM

S1S_1 S2S_2 \ldots SN1S_{N-1}

X1X_1 X2X_2 \ldots XMX_M

Output

Print the maximum possible number of terms that are lucky numbers in a good sequence AA.

9 2
2 3 3 4 -4 -7 -4 -1
-1 5
4

A good sequence A=(3,1,4,1,5,9,2,6,5)A = (3, -1, 4, -1, 5, -9, 2, -6, 5) contains four terms that are lucky numbers: A2,A4,A5,A9A_2, A_4, A_5, A_9, which is the maximum possible count.

20 10
-183260318 206417795 409343217 238245886 138964265 -415224774 -499400499 -313180261 283784093 498751662 668946791 965735441 382033304 177367159 31017484 27914238 757966050 878978971 73210901
-470019195 -379631053 -287722161 -231146414 -84796739 328710269 355719851 416979387 431167199 498905398
8