C. Jury Marks
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain number of points (may be negative, i. e. points were subtracted). Initially the participant had some score, and each the marks were one by one added to his score. It is known that the i-th jury member gave ai points.

Polycarp does not remember how many points the participant had before this k marks were given, but he remembers that among the scores announced after each of the k judges rated the participant there were n (n ≤ k) values b1, b2, ..., bn (it is guaranteed that all values bj are distinct). It is possible that Polycarp remembers not all of the scores announced, i. e. n < k. Note that the initial score wasn't announced.

Your task is to determine the number of options for the score the participant could have before the judges rated the participant.

Input
The first line contains two integers k and n (1 ≤ n ≤ k ≤ 2 000) — the number of jury members and the number of scores Polycarp remembers.

The second line contains k integers a1, a2, ..., ak ( - 2 000 ≤ ai ≤ 2 000) — jury's marks in chronological order.

The third line contains n distinct integers b1, b2, ..., bn ( - 4 000 000 ≤ bj ≤ 4 000 000) — the values of points Polycarp remembers. Note that these values are not necessarily given in chronological order.

Output
Print the number of options for the score the participant could have before the judges rated the participant. If Polycarp messes something up and there is no options, print "0" (without quotes).

Examples
input
4 1
-5 5 0 20
10
output
3
input
2 2
-2000 -2000
3998000 4000000
output
1
Note
The answer for the first example is 3 because initially the participant could have  - 10, 10 or 15 points.

In the second example there is only one correct initial score equaling to 4 002 000.

这道题目的题意如下:
卡普看电视节目,K个评委组成员一一评判参与者,给出自己的分数,参数者的分数会在原来分数的基础,加入评委给的分数(可能是负的,如果是负的,相当于是扣分)。评判前,参与者有一个分数,然后评委给的每个分数都是一个一个按顺序加到他的分数上。众所周知,第i个陪审团成员给Ai个分数。
卡普不记得参赛者在被K个评委评分前的参赛者的分数是多少分了,但他记得,在K个评委组给出分数的期间,里有N个分数是参赛者曾经达到过的值 分别是B1,B2, …, BN(题目保证所有的B都不一样)。卡普记得该参赛者达到的某些分数,但就是不知道参赛者在K个评委评判前的原来得分。
你的任务是写出参赛者在这K个评委评判参与者原来的分数有几种可能。(N ≤ K)

看第一个例子,K=4表示评委评分了4次,N=1表示有参赛者在4个评委评分期间达到过某1个分数
然后评委的评分 分别是 -5 5 0 20
然后在评分期间达到 过10分
所以答案输出3,因为有3种可能

分别是-10 , 10 , 15

为什么 -10可以, 因为 -10 +(-5)+5 +0+20 = 10 ,因此,如果参数者最开始分数是-10分,第4次评分后达到10分的条件

为什么 10 可以,因为 10 + (-5)+5 = 10 在被第2次评判的时候,参数者达到过10分

15很明显是在被第一次判分的时候,就达到了10分

随便举个不行的例子,5为什么不可以,如果刚开始是5分,那么第一次判定后是0分,第二次判定后是5分,第三次判断后是5分,第四次判定后是25分,没有达到过10分,所以5不行,所以答案只有-10,10,15这3种情况。

如果你还是没有理解,请看第二个例子:

参赛者被评分了2次,在2次评判中达到过某2个分数

第一次评分-2000,第二次评分-2000(真惨- -||)

然后达到的分数分布是3998000分,4000000分

很显然,4002000是他开始的分数,所以输出1,表示只有一种可能

为什么,因为如果刚开始是4002000分,那么第一次评判时,达到4000000,第二次评判达到3998000,的确都是曾经达到的分数,与已知不矛盾。

有人问,为什么刚开始不能是4000000分,因为如此的话,第一次评判达到3998000,第二次评判达到3996000,达到3996000分无所谓,但是没有达到分数4000000,即在评委评分期间没有达到4000000分,与条件矛盾,所以不可以


如果你已经理解题意了,那么赶快去A了他吧。如果无从下手,接下来,我讲讲我的思路。
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

我们已经知道的是评委的评分,比如第一个样例,分别是-5,5,0,20
我们曾经达到的某次分数是10分。
但是我们不知道,这是第几次判分后得到的分数,如果是第一次评分,那么很明显,我们可以往回推出 10 - (-5) = 15,这就推出第一种情况了耶。
很好,按照这种思路,我们假设是 是第二次评分后产生的, 那么我们可以 倒推出 10 -5 - (-5)=10 ,第二种情况也出来了
然后是 10-5-(-5)-0 = 10,与第二种重复。
然后是 第3种,15分,是第三种情况

至此,第一个样例解决,然后是第二个样例。
我们曾经达到过4000000分,3998000分。
如果我们曾经达到4000000或3998000分是第一次评分后的结果,那么我们有可能得了4020000或400000
如果我们曾经达到4000000或3998000分是第二次评分后的结果,那么我们有可能得了4040000或402000
这里402000出现了两次。
而400000和4040000只出现了一次,排除掉,那么只剩下了402000这种情况了。

至此思路完成。

然后是我的代码
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include <queue>
#include <vector>
#include <cmath>
#include<map>
#include <set>
#include <ctime>
const int MAXN = (int)1e5+5;
const int MODN = (int)1e9+7;
typedef long long ll;
int inf=0x3f3f3f3f;
using namespace std;

char str[MAXN];
int num[MAXN];
int a[MAXN];
int dp[MAXN];
int b[MAXN];
int eql[MAXN];
int w[16000000];
map<int,int>mm;
int main(){

//freopen("D:\\example.txt","r",stdin);

int n,m;
scanf("%d%d",&n,&m);

int ans = 0;
for(int i=0;i<n;i++)scanf("%d",&a[i]);
for(int i=0;i<m;i++)scanf("%d",&b[i]);


dp[0]=a[0];
for(int i=1;i<n;i++){
dp[i]=dp[i-1]+a[i];
}
sort(dp,dp+n);
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(dp[i]==dp[j])eql[j]=1;
}
}

for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
if(eql[j]==0)w[b[i]-dp[j]+8000000]+=1;
}

}
for(int i=0;i<=16000000;i++){

ans+=w[i]==m?1:0;

}
printf("%d\n",ans);



}