#include <stdio.h>
#include <iostream>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <complex>
#include <ctime>
#include <iomanip>
#include <cassert>
#include <sstream>
#include <iterator>

using namespace std;

#define file "file"
#define mp make_pair
#define pb push_back
#define xx real()
#define yy imag()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef complex<double> point;

const int MAXN = 2e6 + 5;

ll a[MAXN],b[MAXN];
int z[MAXN];
ll s[MAXN];
int top = 0;

void solve(){
	int n,w;
	scanf("%d%d",&n,&w);
	for(int i = 0;i < n;i++){
		scanf("%I64d",&a[i]);
	}
	for(int i = 0;i < w;i++){
		scanf("%I64d",&b[i]);
	}
	if(w == 1){
		cout << n;
		return;
	}
	for(int i = 1;i < w;i++){
		s[top++] = b[i] - b[i - 1];
	}
	int n2 = top;
	for(int i = 1;i < n;i++){
		s[top++] = a[i] - a[i - 1];
	}
	n = top;
	for(int i = 1,l = 0,r = 0;i < n;i++){
		if(i <= r){
			z[i] = min(r - i + 1,z[i - l]);
		}
		while(i + z[i] < n && s[i + z[i]] == s[z[i]]){
			z[i]++;
		}
		if(i + z[i] - 1 > r){
			l = i;
			r = i + z[i] - 1;
		}
	}
	int ans = 0;
	for(int i = n2;i < n;i++){
		if(z[i] >= n2){
			ans++;
		}
	}
	cout << ans;
}

int main()
{
	#ifndef ONLINE_JUDGE
	assert(freopen("input.txt","r",stdin));
	assert(freopen("output.txt","w",stdout));
	#else
	//assert(freopen(file".in","r",stdin)); assert(freopen(file".out","w",stdout));
	#endif
	int t = 1;
	while(t--){
		solve();
	}
	return 0;
}


#include <stdio.h>
#include <iostream>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <complex>
#include <ctime>
#include <iomanip>
#include <cassert>
#include <sstream>
#include <iterator>

using namespace std;

#define file "file"
#define mp make_pair
#define pb push_back
#define xx real()
#define yy imag()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef complex<double> point;

const int MAXN = 2e6 + 5;

ll a[MAXN],b[MAXN];
int z[MAXN];
ll s[MAXN];
int top = 0;

void solve(){
	int n,w;
	scanf("%d%d",&n,&w);
	for(int i = 0;i < n;i++){
		scanf("%I64d",&a[i]);
	}
	for(int i = 0;i < w;i++){
		scanf("%I64d",&b[i]);
	}
	for(int i = 1;i < w;i++){
		s[top++] = b[i] - b[i - 1];
	}
	int n2 = top;
	for(int i = 1;i < n;i++){
		s[top++] = a[i] - a[i - 1];
	}
	n = top;
	for(int i = 1,l = 0,r = 0;i < n;i++){
		if(i <= r){
			z[i] = min(r - i + 1,z[i - l]);
		}
		while(i + z[i] < n && s[i + z[i]] == s[z[i]]){
			z[i]++;
		}
		if(i + z[i] - 1 > r){
			l = i;
			r = i + z[i] - 1;
		}
	}
	int ans = 0;
	for(int i = n2;i < n;i++){
		if(z[i] >= n2){
			ans++;
		}
	}
	cout << ans;
}

int main()
{
	#ifndef ONLINE_JUDGE
	assert(freopen("input.txt","r",stdin));
	assert(freopen("output.txt","w",stdout));
	#else
	//assert(freopen(file".in","r",stdin)); assert(freopen(file".out","w",stdout));
	#endif
	int t = 1;
	while(t--){
		solve();
	}
	return 0;
}


//In the name of Allah
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<iterator>
#include<cmath>
#include<string>
#include<sstream>
#include<cstring>
#include<ctype.h>
#include<iomanip>
#include<functional>
#include<bitset>
#include<stdio.h>
#include<fstream>
#include<stdlib.h>
#include<math.h>
#include<ctime>
#include<string>
#include<cstdio>
#include<locale>
#include<codecvt>
using namespace std;
#define lop(i,a,n) for(int i=a;i<n;++i)
#define loop(i,n,a)for(int i=n-1;i>=a;--i)
#define R_(s)      freopen(s, "r", stdin)
#define W_(s)      freopen(s, "w", stdout)
#define R_W        R_("in.txt"),W_("out.txt")
#define ll         long long
#define ld         long double
#define ii         pair<ll,ll>
#define vii        vector<ii>
#define vi         vector<int>
#define vll        vector<ll>
#define vs         vector<string>
#define vvii       vector<vector<ii>>
#define vvi        vector<vector<int>>
#define vvll       vector<vector<ll>>
#define sz(v)      (ll)v.size()
#define all(v)     v.begin(),v.end()
#define sc(n)      scanf("%d",&n)
#define scl(n)     scanf("%lld",&n)
#define pr1(n)     printf("%d\n",n)
#define pr2(n)     printf("%d " ,n)
#define pr4(n)     printf("%lld\n",n)
#define pr3(n)     cout<<fixed<<setprecision(4)<<n<<endl
#define endl       "\n"
#define PI         2*acos(0.0)
#define DFS_GRAY  -1
#define DFS_WHITE  0
#define DFS_BLACK  1
#define oo  1e9
#define OO  1e18
#define EPS 1e-9
int dr[] = { 1, 0, -1, 0, -1, -1, 1, 1 };
int dc[] = { 0, -1, 0, 1, -1, 1, -1, 1 };
const int MAX = 1e6 + 7;
const int MOD = 1e9 + 7;
ll a[MAX], tmp[MAX];
void Z_Algrothim(int n,int m)
{
	vi Z(n,0);
	for(int i=1,L=0,R=0;i<n;i++)
	{
		if(i<=R)Z[i]=min(Z[i-L],R-i+1);
		while(i+Z[i]<n&&a[Z[i]]==a[i+Z[i]])Z[i]++;
		if(i+Z[i]-1>R)L=i,R=i+Z[i]-1;
	}
	int ans = 0;
	lop(i, m, n)if (Z[i] >= m-2)ans++;
	cout << ans << endl;
}
int main()
{
	int n, m; cin >> n >> m;
	lop(i, m+1, n+m+1)cin >> a[i];
	lop(i, m+1, n+m)a[i] -= a[i + 1];
	a[m] = -OO;
	lop(i, 0, m) { cin >> a[i]; tmp[i] = a[i]; }
	lop(i, 0, m - 1)a[i] -= a[i + 1];
	Z_Algrothim(n + m + 1, m+1);
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <cstdio>
using namespace std;

#define pb push_back
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define eps 1e-12
 const int Mint = 1000000000;
typedef long long ll;
typedef long double ld;
typedef vector < ll > vll;
typedef vector < int > vi;
typedef pair < ll, ll > pll;
typedef int huint;

int n,m,p[200020],f[200020],d[600000];

vector<ll> a;

int main(){
   //     std::ios_base::sync_with_stdio(false);
//    freopen("input.txt", "r", stdin);
 //  freopen("output.txt", "w", stdout);
   cin >> n >> m;

   for(int i(0);i<n;i++)
	   scanf("%d",&p[i]);
   for(int i(0);i<m;i++)
	   scanf("%d",&f[i]);
   if(m == 1) { cout << n;return 0;}
   if(m > n) { cout << 0;return 0;}
   for(int i(1);i<m;i++)
	   a.push_back(f[i]-f[i-1]);
   a.push_back(1000000000000000);
   for(int i(1);i<n;i++)
	   a.push_back(p[i]-p[i-1]);
   int ans = 0;d[0] = 0;
   for(int i(1);i<a.size();i++)
   {
	   int x = d[i-1];
	   while(x > 0 && a[i] != a[x]) x = d[x-1];
	   if(a[i] == a[x] ) x++;
	   d[i] = x;
	   if(x == m-1) ans++;
   }
   cout << ans;
}


#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <stdlib.h>
#include <sstream>
#include <assert.h>

#include <time.h>
#pragma comment(linker, "/STACK:20000000")

#define fr(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define fd(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define mp make_pair
#define pb push_back
#define ll long long

using namespace std;

int ri(){int x;scanf("%d",&x);return x;}
ll rll(){ll x;scanf("%lld",&x);return x;}

int a[2 * 100500];
int b[2 * 100500];
int all[4 * 100500];
int pre[4 * 100500];

void solve()
{
	int n = ri(),w = ri();
	if (w == 1)
	{
		cout << n << endl;
		return;
	}
	if (n < w)
	{
		cout << 0 << endl;
		return;
	}
	fr(i,1,n)
		a[i] = ri();
	fr(i,1,w)
		b[i] = ri();
	reverse(b + 1,b + 1 + w);
	reverse(a + 1,a + 1 + n);
	int cnt = 0;
	fr(i,1,w - 1)
		all[cnt++] = b[i + 1] - b[i];
	all[cnt++] = 2e9;
	fr(i,1,n - 1)
		all[cnt++] = a[i + 1] - a[i];
	fr(i,0,w - 2)
		pre[i] = i;
	fr(i,w ,cnt - 1)
	{
		int j = pre[i - 1];
		while(j > 0 && all[i] != all[j])
			j = pre[j - 1];
		if (all[i] == all[j])
			j++;
		pre[i] = j;
	}
	int res = 0;
	fr(i,w,cnt - 1)
		res += pre[i] == w - 1;
	cout << res << endl;
}

int main()
{
	#ifndef ONLINE_JUDGE
		freopen("C:/Users/CleRIC/Desktop/Универ/acm.timus.ru/input.txt","rt",stdin);
		freopen("C:/Users/CleRIC/Desktop/Универ/acm.timus.ru/output.txt","wt",stdout);
	#else
		//freopen("input.in","rt",stdin);
		//freopen("output.out","wt",stdout);
	#endif

	solve();

	#ifndef ONLINE_JUDGE
		printf("\n\ntime-%.3lf",clock()*1e-3);
	#endif

	return 0;
}


#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <stdlib.h>
#include <sstream>
#include <assert.h>

#include <time.h>
#pragma comment(linker, "/STACK:20000000")

#define fr(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define fd(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define mp make_pair
#define pb push_back
#define ll long long

using namespace std;

int ri(){int x;scanf("%d",&x);return x;}
ll rll(){ll x;scanf("%lld",&x);return x;}

int a[2 * 100500];
int b[2 * 100500];
int all[4 * 100500];
int pre[4 * 100500];

void solve()
{
	int n = ri(),w = ri();
	if (w == 1)
	{
		cout << n << endl;
		return;
	}
	if (n < w)
	{
		cout << 0 << endl;
		return;
	}
	fr(i,1,n)
		a[i] = ri();
	fr(i,1,w)
		b[i] = ri();
	//reverse(b + 1,b + 1 + w);
	//reverse(a + 1,a + 1 + n);
	int cnt = 0;
	fr(i,1,w - 1)
		all[cnt++] = b[i + 1] - b[i];
	all[cnt++] = 2e9;
	fr(i,1,n - 1)
		all[cnt++] = a[i + 1] - a[i];
	//fr(i,0,w - 2)
//		pre[i] = i;
	fr(i,1,cnt - 1)
	{
		int j = pre[i - 1];
		while(j > 0 && all[i] != all[j])
			j = pre[j - 1];
		if (all[i] == all[j])
			j++;
		pre[i] = j;
	}
	int res = 0;
	fr(i,w,cnt - 1)
		res += pre[i] == w - 1;
	cout << res << endl;
}

int main()
{
	#ifndef ONLINE_JUDGE
		freopen("C:/Users/CleRIC/Desktop/Универ/acm.timus.ru/input.txt","rt",stdin);
		freopen("C:/Users/CleRIC/Desktop/Универ/acm.timus.ru/output.txt","wt",stdout);
	#else
		//freopen("input.in","rt",stdin);
		//freopen("output.out","wt",stdout);
	#endif

	solve();

	#ifndef ONLINE_JUDGE
		printf("\n\ntime-%.3lf",clock()*1e-3);
	#endif

	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<map>
#include<cmath>
using namespace std;

typedef unsigned long long ll;

int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
int n, w;
cin>>n>>w;
vector <ll> a(n), b(w);
ll  H_el=0, k=0, used=0, cur=0, kol=0;
vector <ll> H(n+1);
const ll h=37;
ll step=1;
H[0]=0;
for (int i=0; i<n; i++){
    cin>>a[i];
    H[i+1]=(H[i]+a[i]*step)/*%m*/;
    step*=h;
}
step=1;
for (int i=0; i<w; i++){
    cin>>b[i];
    H_el=(H_el+b[i]*step)/*%m*/;
    used=(used+step);
    step*=h;
}
step=1;
for (int i=1; i<=n-w+1; i++){
    k=a[i-1]-b[0];
    cur=((H[i+w-1]-H[i-1])/step-used*k)/*%m*/;
    if (cur==H_el)
        kol++;
    step*=h;
}
cout<<kol;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
typedef double db;
typedef long long ll;
typedef pair<int, int> P;
const int mod1=1e9+7, mod2=1e6+9, d1=37, d2=41;
int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    vector<int>a(n), b(m);
    for(int i=0; i<n; i++) scanf("%d", &a[i]);
    for(int i=0; i<m; i++) scanf("%d", &b[i]);
    for(int i=0; i<n-1; i++){ a[i]-=a[i+1]; a[i]+=mod1;}
    for(int i=0; i<m-1; i++){ b[i]-=b[i+1]; b[i]+=mod1;}
    n--, m--;
    if(m>n){
        puts("0");
        return 0;
    }
    a.pop_back(), b.pop_back();
    vector<P> hash(n+1);
    int h1=1, h2=1;
    for(int i=0; i<=n; i++){
        hash[i].first=h1;
        h1=(h1*1ll*d1)%mod1;
        hash[i].second=h2;
        h2=(h2*1ll*d2)%mod2;
    }
    P hash_b;
    hash_b.first=hash_b.second=0;
    for(int i=0; i<m; i++){
        hash_b.first=(hash_b.first+(b[i]*1ll*hash[i].first)%mod1)%mod1;
        hash_b.second=(hash_b.second+(b[i]*1ll*hash[i].second)%mod2)%mod2;
    }
    hash_b.first=(hash_b.first*1ll*hash[n-m].first)%mod1;
    hash_b.second=(hash_b.second*1ll*hash[n-m].second)%mod2;
    int kol=0;
    P hash_a;
    hash_a.first=hash_a.second=0;
    for(int i=0; i<m; i++){
        hash_a.first=(hash_a.first+(a[i]*1ll*hash[i].first)%mod1)%mod1;
        hash_a.second=(hash_a.second+(a[i]*1ll*hash[i].second)%mod2)%mod2;
    }
    for(int i=m; i<=n; i++){
        int hp1=hash_a.first, hp2=hash_a.second;
        hp1=(hp1*1ll*hash[n-i].first)%mod1;
        hp2=(hp2*1ll*hash[n-i].second)%mod2;
        kol+=(hp1==hash_b.first&&hp2==hash_b.second);
        if(n==i) break;
        hash_a.first=(hash_a.first-(hash[i-m].first*1ll*a[i-m])%mod1+mod1)%mod1;
        hash_a.second=(hash_a.second-(hash[i-m].second*1ll*a[i-m])%mod2+mod2)%mod2;
        hash_a.first=(hash_a.first+(a[i]*1ll*hash[i].first)%mod1)%mod1;
        hash_a.second=(hash_a.second+(a[i]*1ll*hash[i].second)%mod2)%mod2;
    }
    printf("%d", kol);
}
/*
13 5
2 4 5 5 4 3 2 2 2 3 3 2 1
3 4 4 3 2
*/


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
vector<int> p_fun(string s){
    int n=s.size();
    vector<int>pi(n);
    for(int i=1; i<n; i++){
        int j=pi[i-1];
        while(j>0&&s[i]!=s[j])
            j=pi[j-1];
        if(s[i]==s[j])
            j++;
        pi[i]=j;
    }
    return pi;
}
vector<int> z_fun(string s){
    int n=s.size();
    vector<int>z(n);
    for(int i=1, l=0, r=0; i<n; i++){
        int k;
        if(i<=r)
            z[i]=min(r-i+1, z[i-l]);
        k=s[z[i]+i]-s[z[i]];
        while(i+z[i]<n&&s[z[i]]+k==s[z[i]+i])
            z[i]++;
        if(z[i])
            l=i, r-i+z[i];
    }
    return z;
}
int main(){
    int n, m;
    cin>>n>>m;
    string a, b, s="#";
    while(n--){
        char f;
        cin>>f;
        a+=f;
    }
    while(m--){
        char f;
        cin>>f;
        b+=f;
    }
    s=b+s+a;
    vector<int>pi=z_fun(s);
    long long kol=0;
    for(int i=b.size()+1; i<s.size(); i++)
        if(pi[i]==b.size())
            kol++;
    cout<<kol;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
typedef double db;
typedef long long ll;
const int mod=1e9+7, d=37;
int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    vector<int>a(n), b(m);
    for(int i=0; i<n; i++) scanf("%d", &a[i]);
    for(int i=0; i<m; i++) scanf("%d", &b[i]);
    for(int i=0; i<n-1; i++){ a[i]-=a[i+1]; a[i]+=mod1;}
    for(int i=0; i<m-1; i++){ b[i]-=b[i+1]; b[i]+=mod1;}
    n--, m--;
    if(m>n){
        puts("0");
        return 0;
    }
    a.pop_back(), b.pop_back();
    vector<int>hash(n+1);
    int h=1;
    for(int i=0; i<=n; i++){
        hash[i]=h;
        h=(h*1ll*d)%mod;
    }
    int hash_b=0;
    for(int i=0; i<m; i++)
        hash_b=(hash_b+(b[i]*1ll*hash[i])%mod)%mod;
    hash_b=(hash_b*1ll*hash[n-m])%mod;
    int kol=0;
    int hash_a=0;
    for(int i=0; i<m; i++)
        hash_a=(hash_a+(a[i]*1ll*hash[i])%mod)%mod;
    for(int i=m; i<=n; i++){
        int hp=hash_a;
        hp=(hp*1ll*hash[n-i])%mod;
        kol+=hp==hash_b;
        if(n==i) break;
        hash_a=(hash_a-(hash[i-m]*1ll*a[i-m])%mod+mod)%mod;
        hash_a=(hash_a+(a[i]*1ll*hash[i])%mod)%mod;
    }
    printf("%d", kol);
}


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
vector<int> p_fun(string s){
    int n=s.size();
    vector<int>pi(n);
    for(int i=1; i<n; i++){
        int j=pi[i-1];
        while(j>0&&s[i]!=s[j])
            j=pi[j-1];
        if(s[i]==s[j])
            j++;
        pi[i]=j;
    }
    return pi;
}
vector<int> z_fun(vector<int>s){
    int n=s.size();
    vector<int>z(n);
    for(int i=1, l=0, r=0; i<n; i++){
        int k;
        if(i<=r)
            z[i]=min(r-i+1, z[i-l]);
        k=s[z[i]+i]-s[z[i]];
        while(i+z[i]<n&&s[z[i]]+k==s[z[i]+i])
            z[i]++;
        if(z[i])
            l=i, r-i+z[i];
    }
    return z;
}
int main(){
    int n, m;
    cin>>n>>m;
    vector<int> a(n), b(m);
    for(int i=0; i<n; i++)
        scanf("%d", &a[i]);
    for(int i=0; i<m; i++)
        scanf("%d", &b[i]);
    b.push_back(0);
    b.resize(n+m);
    for(int i=0; i<n; i++)
        b[m+i]=a[i];
    vector<int>pi=z_fun(b);
    long long kol=0;
    for(int i=m; i<b.size(); i++)
        if(pi[i]==m)
            kol++;
    cout<<kol;
}


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
vector<int> p_fun(string s){
    int n=s.size();
    vector<int>pi(n);
    for(int i=1; i<n; i++){
        int j=pi[i-1];
        while(j>0&&s[i]!=s[j])
            j=pi[j-1];
        if(s[i]==s[j])
            j++;
        pi[i]=j;
    }
    return pi;
}
vector<int> z_fun(vector<int>s){
    int n=s.size();
    vector<int>z(n);
    for(int i=1, l=0, r=0; i<n; i++){
        int k;
        if(i<=r)
            z[i]=min(r-i+1, z[i-l]);
        k=s[z[i]+i]-s[z[i]];
        while(i+z[i]<n&&s[z[i]]+k==s[z[i]+i])
            z[i]++;
        if(z[i])
            l=i, r-i+z[i];
    }
    return z;
}
int main(){
    int n, m;
    cin>>n>>m;
    vector<int> a(n), b(m);
    for(int i=0; i<n; i++)
        cin>>a[i];
    for(int i=0; i<m; i++)
        cin>>b[i];
    b.push_back(0);
    b.resize(n+m);
    for(int i=0; i<n; i++)
        b[m+i]=a[i];
    vector<int>pi=z_fun(b);
    long long kol=0;
    for(int i=m; i<b.size(); i++)
        if(pi[i]==m)
            kol++;
    cout<<kol;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<map>
#include<cmath>
using namespace std;

typedef unsigned long long ll;

int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
int n, w;
cin>>n>>w;
vector <ll> a(n), b(w);
ll  H_el=0, k=0, used=0, cur=0, kol=0;
vector <ll> H(n+1);
const ll h=37;
ll step=1;
H[0]=0;
for (int i=0; i<n; i++){
    cin>>a[i];
    H[i+1]=(H[i]+a[i]*step)/*%m*/;
    step*=h;
}
step=1;
for (int i=0; i<w; i++){
    cin>>b[i];
    H_el=(H_el+b[i]*step)/*%m*/;
    used=(used+step)%m;
    step*=h;
}
step=1;
for (int i=1; i<=n-w+1; i++){
    k=a[i-1]-b[0];
    cur=((H[i+w-1]-H[i-1])/step-used*k)/*%m*/;
    if (cur==H_el)
        kol++;
    step*=h;
}
cout<<kol;
}

    /*
    13 5
    2 4 5 5 4 3 2 2 2 3 3 2 1
    3 4 4 3 2

    */


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
vector<int> p_fun(string s){
    int n=s.size();
    vector<int>pi(n);
    for(int i=1; i<n; i++){
        int j=pi[i-1];
        while(j>0&&s[i]!=s[j])
            j=pi[j-1];
        if(s[i]==s[j])
            j++;
        pi[i]=j;
    }
    return pi;
}
vector<int> z_fun(vector<int>&s){
    int n=s.size();
    vector<int>z(n);
    for(int i=1, l=0, r=0; i<n; i++){
        int k;
        if(i<=r)
            z[i]=min(r-i+1, z[i-l]);
        k=s[z[i]+i]-s[z[i]];
        while(i+z[i]<n&&s[z[i]]+k==s[z[i]+i])
            z[i]++;
        if(z[i])
            l=i, r-i+z[i];
    }
    return z;
}
int main(){
    int n, m;
    cin>>n>>m;
    vector<int> a(n), b(m);
    for(int i=0; i<n; i++)
        scanf("%d", &a[i]);
    for(int i=0; i<m; i++)
        scanf("%d", &b[i]);
    b.push_back(0);
    b.resize(n+m);
    for(int i=0; i<n; i++)
        b[m+i]=a[i];
    vector<int>pi=z_fun(b);
    long long kol=0;
    for(int i=m; i<b.size(); i++)
        if(pi[i]==m)
            kol++;
    cout<<kol;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
typedef double db;
typedef long long ll;
const int mod=1e9+7, d=37;
int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    vector<int>a(n), b(m);
    for(int i=0; i<n; i++) scanf("%d", &a[i]);
    for(int i=0; i<m; i++) scanf("%d", &b[i]);
    for(int i=0; i<n-1; i++){ a[i]-=a[i+1]; a[i]+=mod;}
    for(int i=0; i<m-1; i++){ b[i]-=b[i+1]; b[i]+=mod;}
    n--, m--;
    if(m>n){
        puts("0");
        return 0;
    }
    a.pop_back(), b.pop_back();
    vector<int>hash(n+1);
    int h=1;
    for(int i=0; i<=n; i++){
        hash[i]=h;
        h=(h*1ll*d)%mod;
    }
    int hash_b=0;
    for(int i=0; i<m; i++)
        hash_b=(hash_b+(b[i]*1ll*hash[i])%mod)%mod;
    hash_b=(hash_b*1ll*hash[n-m])%mod;
    int kol=0;
    int hash_a=0;
    for(int i=0; i<m; i++)
        hash_a=(hash_a+(a[i]*1ll*hash[i])%mod)%mod;
    for(int i=m; i<=n; i++){
        int hp=hash_a;
        hp=(hp*1ll*hash[n-i])%mod;
        kol+=hp==hash_b;
        if(n==i) break;
        hash_a=(hash_a-(hash[i-m]*1ll*a[i-m])%mod+mod)%mod;
        hash_a=(hash_a+(a[i]*1ll*hash[i])%mod)%mod;
    }
    printf("%d", kol);
}


#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<iterator>
#include<vector>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> P;
int m;
int p_fun(vector<int>s){
	if(m==1) return s.size();
	int n=s.size(), kol=0;
	vector<int>pi(n);
	pi[0]=0;
	for(int i=1; i<n; i++){
		int j=pi[i-1];
		while(j>0&&s[i]!=s[j]) j=pi[j-1];
		if(s[i]==s[j]) j++;
		pi[i]=j;
		if(j==m-1) kol++;
	}
	return kol;
}
int main(){
	int n;
	scanf("%d%d", &n, &m);
	vector<int>a(n), b(m);
	for(int i=0; i<n; i++)
		scanf("%d", &a[i]);
	for(int i=0; i<n-1; i++)
		a[i]-=a[i+1];
	for(int i=0; i<m; i++)
		scanf("%d", &b[i]);
	for(int i=0; i<m-1; i++)
		b[i]-=b[i+1];
	a.pop_back(); b.pop_back();
	b.push_back(INT_MAX);
	for(int i=0; i<a.size(); i++)
		b.push_back(a[i]);
	printf("%d", p_fun(b));
}


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
vector<int> p_fun(string s){
    int n=s.size();
    vector<int>pi(n);
    for(int i=1; i<n; i++){
        int j=pi[i-1];
        while(j>0&&s[i]!=s[j])
            j=pi[j-1];
        if(s[i]==s[j])
            j++;
        pi[i]=j;
    }
    return pi;
}
vector<int> z_fun(vector<int>s){
    int n=s.size();
    vector<int>z(n);
    for(int i=1, l=0, r=0; i<n; i++){
        int k;
        if(i<=r)
            z[i]=min(r-i+1, z[i-l]);
        k=s[z[i]+i]-s[z[i]];
        while(i+z[i]<n&&s[z[i]]+k==s[z[i]+i])
            z[i]++;
        if(z[i])
            l=i, r-i+z[i];
    }
    return z;
}
int main(){
    int n, m;
    cin>>n>>m;
    vector<int> a(n), b(m);
    for(int i=0; i<n; i++)
        cin>>a[i];
    for(int i=0; i<m; i++)
        cin>>b[i];
    b.push_back(0);
    b.resize(n+m+1);
    for(int i=0; i<n; i++)
        b[m+i]=a[i];
    vector<int>pi=z_fun(b);
    long long kol=0;
    for(int i=m+1; i<b.size(); i++)
        if(pi[i]==m)
            kol++;
    cout<<kol;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
typedef double db;
typedef long long ll;
const int mod=1e9+7, d=37;
int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    vector<int>a(n), b(m);
    for(int i=0; i<n; i++) scanf("%d", &a[i]);
    for(int i=0; i<m; i++) scanf("%d", &b[i]);
    for(int i=0; i<n-1; i++){ a[i]-=a[i+1]; a[i]+=11;}
    for(int i=0; i<m-1; i++){ b[i]-=b[i+1]; b[i]+=11;}
    n--, m--;
    if(m>n){
        puts("0");
        return 0;
    }
    a.pop_back(), b.pop_back();
    vector<int>hash(n+1);
    int h=1;
    for(int i=0; i<=n; i++){
        hash[i]=h;
        h=(h*1ll*d)%mod;
    }
    int hash_b=0;
    for(int i=0; i<m; i++)
        hash_b=(hash_b+(b[i]*1ll*hash[i])%mod)%mod;
    hash_b=(hash_b*1ll*hash[n-m])%mod;
    int kol=0;
    int hash_a=0;
    for(int i=0; i<m; i++)
        hash_a=(hash_a+(a[i]*1ll*hash[i])%mod)%mod;
    for(int i=m; i<=n; i++){
        int hp=hash_a;
        hp=(hp*1ll*hash[n-i])%mod;
        kol+=hp==hash_b;
        if(n==i) break;
        hash_a=(hash_a-(hash[i-m]*1ll*a[i-m])%mod+mod)%mod;
        hash_a=(hash_a+(a[i]*1ll*hash[i])%mod)%mod;
    }
    printf("%d", kol);
}
/*
13 5
2 4 5 5 4 3 2 2 2 3 3 2 1
3 4 4 3 2
*/


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
vector<int> p_fun(string s){
	int n=s.size();
	vector<int>pi(n);
	for(int i=1; i<n; i++){
		int j=pi[i-1];
		while(j>0&&s[i]!=s[j])
			j=pi[j-1];
		if(s[i]==s[j])
			j++;
		pi[i]=j;
	}
	return pi;
}
long long kol=0;
int n, m;
vector<int> z_fun(vector<int>&s){
	int n=s.size();
	vector<int>z(n);
	for(int i=1, l=0, r=0; i<n; i++){
		int k;
		if(i<=r)
			z[i]=min(r-i+1, z[i-l]);
		k=s[z[i]+i]-s[z[i]];
		while(i+z[i]<n&&s[z[i]]+k==s[z[i]+i])
			z[i]++;
		if(z[i])
			l=i, r-i+z[i];
		if(z[i]==m)
			kol++;
	}
	return z;
}
int main(){
	cin>>n>>m;
	vector<int> a(n), b(m);
	for(int i=0; i<n; i++)
		scanf("%d", &a[i]);
	for(int i=0; i<m; i++)
		scanf("%d", &b[i]);
	b.push_back(0);
	b.resize(n+m);
	for(int i=0; i<n; i++)
		b[m+i]=a[i];
	vector<int>pi=z_fun(b);
	cout<<kol;
}


#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int n, m;
    cin>>n>>m;
    vector<int>a(n), b(m);
    for(int i=0; i<n; i++)
        cin>>a[i];
    for(int i=0; i<m; i++)
        cin>>b[i];
    int sum=0;
    for(int i=0; i<n-m+1; i++){
        int r=a[i]-b[0];
        int z=0;
        for(int j=0; j<m; j++)
            if(a[i+j]!=b[j]+r)
                z=1;
        if(z==0)
            sum++;
        z=0;
    }
    cout<<sum;
}


#include "iostream"
#include "string"
#define SIZE 100005

using namespace std;

string str1, str2;
int n, m;
int num1[SIZE * 2], num2[SIZE * 2];

char ch[20];

int main()
{
	cin >> n >> m;
	if (m == 1) cout << n << endl;
	else
	{
		for (int i = 0; i < n; i++){
			//cin >> num1[i];
			scanf("%d", &num1[i]);
			if (i > 0) { sprintf(ch, "%d", (num1[i] - num1[i - 1]) + 1); str1 += ch; }
		}
		for (int j = 0; j < m; j++)
		{
			//cin >> num2[j];
			scanf("%d", &num2[j]);
			if (j > 0) { sprintf(ch, "%d", (num2[j] - num2[j - 1]) + 1); str2 += ch; }
		}
		int ans = 0, flag = -1;
		while ((flag = str1.find(str2, flag + 1)) != -1) ans++;
		cout << ans << endl;
	}
	return 0;
}


#include "iostream"
#define SIZE 10005

using namespace std;

typedef int ElemType;
ElemType S[2 * SIZE], T[2 * SIZE];
ElemType Next[2 * SIZE];
int n, m;
int flag1 = 0, flag2 = 0;

void Get_NextVal()
{
	int i = 0, j = -1;
	Next[i] = j;
	while (m - 1 > i)
	{
		if (j == -1 || T[i] == T[j])
		{
			i++;
			j++;
			Next[i] = j;
		}
		else
			j = Next[j];
	}
}

int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> S[i];
	for (int j = 0; j < m; j++)
		cin >> T[j];
	Get_NextVal();
	int ans = 0;
	int p1 = 0, p2 = 0;
	int ok = 1, tmp = 0;

	for (int k = 0; k < n - 1; k++)
	if (S[k] != S[k + 1]) {
		flag1 = 1; break;
	}
	for (int h = 0; h < m - 1; h++)
	if (T[h] != T[h + 1]){
		flag2 = 1; break;
	}

	if (!flag1 && !flag2)
	{
		ans = n - m + 1;
		cout << ans << endl;
	}
	else
	{
		while (p1 < n)
		{
			if (p2 == -1 || (S[p1]) == (T[p2] + tmp) || ok)
			{
				tmp = S[p1] - T[p2];
				p1++;
				p2++;
				ok = 0;
			}
			else
			{
				p2 = Next[p2];
				ok = 1;
				tmp = 0;
			}
			if (p2 == m)
			{
				ans++;
				p2 = 0;
				p1 = p1 - m + 1;
				ok = 1;
				tmp = 0;
			}
		}
	 cout << ans << endl;
	}
	return 0;
}


#include "iostream"
#include "string"
#define SIZE 100005

using namespace std;

string str1, str2;
int n, m;
int num1[SIZE * 2], num2[SIZE * 2];

char ch[20];

int main()
{
	cin >> n >> m;
	if (m == 1) cout << n << endl;
	else
	{
		for (int i = 0; i < n; i++){
			//cin >> num1[i];
			scanf("%d", &num1[i]);
			if (i > 0) { sprintf(ch, "%d", (num1[i] - num1[i - 1])); str1 += ch; }
		}
		for (int j = 0; j < m; j++)
		{
			//cin >> num2[j];
			scanf("%d", &num2[j]);
			if (j > 0) { sprintf(ch, "%d", (num2[j] - num2[j - 1])); str2 += ch; }
		}
		int ans = 0, flag = -1;
		while ((flag = str1.find(str2, flag + 1)) != -1) ans++;
		cout << ans << endl;
	}
	return 0;
}


#include "iostream"

#define SIZE 100005
#define LL long long

using namespace std;

LL S[SIZE * 2][2], T[SIZE * 2];

int n, m;
int cnt;

void RE_Deal()
{
	int sum = 0;
	int d = 0;
	for (int i = n - 1; i >= 0; i--)
	{
		d++;
		if (d >= m)
		{
			S[i][1] = sum + S[i][0] - S[i + m][0];
			sum = S[i][1];
		}
		else
		    sum += S[i][0];
	}
}

int solve()
{
	int ans = 0;
	int p1 = 0, p2 = 0;
	int tmp = 0;
	while (p1 < n)
	{
		tmp = S[p1][0] - T[0];
		if (S[p1][1] == (cnt + (tmp * m)))
		{
			int p = p1, ok = 0;
			for (int i = 0; i < m; i++)
			{
				if ( S[p++][0] != (T[i] + tmp) ) { ok = 1; break; }
			}
			if (!ok) ans++;
		}
		p1++;
	}
	return ans;
}

int judge()
{
	int flag1 = 0, flag2 = 0;
	for (int i = 0; i < n - 1; i++)
	{
		if (S[i][0] != S[i + 1][0]) { flag1 = 1; break; }
	}
	for (int j = 0; j < m - 1; j++)
	{
		if (T[j] != T[j + 1]) { flag2 = 1; break; }
	}
	if (!flag1 && !flag2) return 1;
	return 0;
}

int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> S[i][0];
	for (int j = 0; j < m; j++)
	{
		cin >> T[j];
		cnt += T[j];
	}
	if (judge())
	{
		cout << n - m + 1 << endl;
	}
	else
	{
		RE_Deal();
		int ans = solve();
		cout << ans << endl;
	}
	return 0;
}


#include "iostream"
#define SIZE 10005

using namespace std;

typedef int ElemType;
ElemType S[2 * SIZE], T[2 * SIZE];
ElemType Next[2 * SIZE];
int n, m;
int flag1 = 0, flag2 = 0;

void Get_NextVal()
{
	int i = 0, j = -1;
	Next[i] = j;
	while (m - 1 > i)
	{
		if (j == -1 || T[i] == T[j])
		{
			i++;
			j++;
			Next[i] = j;
		}
		else
			j = Next[j];
	}
}

int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> S[i];
	for (int j = 0; j < m; j++)
		cin >> T[j];
	Get_NextVal();
	int ans = 0;
	int p1 = 0, p2 = 0;
	int ok = 1, tmp = 0;
	while (p1 < n)
	{
		if (p2 == -1 || (S[p1]) == (T[p2] + tmp) || ok)
		{
			tmp = S[p1] - T[p2];
			p1++;
			p2++;
			ok = 0;
		}
		else
		{
			p2 = Next[p2];
			ok = 1;
		}
		if (p2 == m)
		{
			ans++;
			p2 = 0;
			ok = 1;
		}
	}
	for (int k = 0; k < n - 1; k++)
	if (S[k] != S[k + 1]) {
		flag1 = 1; break;
	}
	for (int h = 0; h < m - 1; h++)
	if (T[h] != T[h + 1]){
		flag2 = 1; break;
	}
	if (!flag1 && !flag2)
	{
		ans = n - m + 1;
		cout << ans << endl;
	}
	else  cout << ans << endl;
	return 0;
}


#include "iostream"

#define SIZE 100005
#define LL long long

using namespace std;

LL S[SIZE * 2][2], T[SIZE * 2];

int n, m;
int cnt;

void RE_Deal()
{
	int sum = 0;
	int d = 0;
	for (int i = n - 1; i >= 0; i--)
	{
		d++;
		if (d >= m)
		{
			S[i][1] = sum + S[i][0] - S[i + m][0];
			sum = S[i][1];
		}
		else
		    sum += S[i][0];
	}
}

int solve()
{
	int ans = 0;
	int p1 = 0, p2 = 0;
	int tmp = 0;
	while (p1 < n)
	{
		tmp = S[p1][0] - T[0];
		if (S[p1][1] == (cnt + (tmp * m)))
		{
			int p = p1, ok = 0;
			for (int i = 0; i < m; i++)
			{
				if ( S[p++][0] != (T[i] + tmp) ) { ok = 1; break; }
			}
			if (!ok) ans++;
		}
		p1++;
	}
	return ans;
}

int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> S[i][0];
	for (int j = 0; j < m; j++)
	{
		cin >> T[j];
		cnt += T[j];
	}
	RE_Deal();
	int ans = solve();
	cout << ans << endl;
}


#include "iostream"
#include "string"

#define SIZE 100005
#define LL long long

using namespace std;

LL S[SIZE * 2][2], T[SIZE * 2];

int n, m;
LL cnt;

string str1, str2;

void help()
{
	getline(cin, str1);
	getline(cin, str2);
	int d = 0;
	int key = 0, sum = 0;
	for (int i = 0; str1[i]; i++)
	{
		if (str1[i] == ' ')
		{
			S[d++][0] = sum;
			sum = 0;
			continue;
		}
		sum = sum * 10 + (str1[i] - '0');
	}
	S[d][0] = sum;
	d = 0; sum = 0;

	for (int j = 0; str2[j]; j++)
	{
		if (str2[j] == ' ')
		{
			T[d++] = sum;
			cnt += sum;
			sum = 0;
			continue;
		}
		sum = sum * 10 + (str2[j] - '0');
	}
	T[d] = sum;
	cnt += sum;
}

void RE_Deal()
{
	LL sum = 0;
	int d = 0;
	for (int i = n - 1; i >= 0; i--)
	{
		d++;
		if (d >= m)
		{
			S[i][1] = sum + S[i][0] - S[i + m][0];
			sum = S[i][1];
		}
		else
		    sum += S[i][0];
	}
}

int solve()
{
	int ans = 0;
	int p1 = 0, p2 = 0;
	LL tmp = 0;
	while (p1 < n)
	{
		tmp = S[p1][0] - T[0];
		if (S[p1][1] == (cnt + (tmp * m)))
		{
			int p = p1, ok = 0;
			for (int i = 0; i < m; i++)
			{
				if ( S[p++][0] != (T[i] + tmp) ) { ok = 1; break; }
			}
			if (!ok) ans++;
		}
		p1++;
	}
	return ans;
}

int judge()
{
	int flag1 = 0, flag2 = 0;
	for (int i = 0; i < n - 1; i++)
	{
		if (S[i][0] != S[i + 1][0]) { flag1 = 1; break; }
	}
	for (int j = 0; j < m - 1; j++)
	{
		if (T[j] != T[j + 1]) { flag2 = 1; break; }
	}
	if (!flag1 && !flag2) return 1;
	return 0;
}

int main()
{
	cin >> n >> m;
	/*for (int i = 0; i < n; i++)
		cin >> S[i][0];
	for (int j = 0; j < m; j++)
	{
		cin >> T[j];
		cnt += T[j];
	}*/
	getchar();
	help();
	if (judge())
	{
		cout << n - m + 1 << endl;
	}
	else
	{
		RE_Deal();
		int ans = solve();
		cout << ans << endl;
	}
	return 0;
}


#include "iostream"
#define SIZE 10005

using namespace std;

typedef int ElemType;
ElemType S[2 * SIZE], T[2 * SIZE];
ElemType Next[2 * SIZE];
int n, m;

void Get_NextVal()
{
	int i = 0, j = -1;
	Next[i] = j;
	while (m - 1 > i)
	{
		if (j == -1 || T[i] == T[j])
		{
			i++;
			j++;
			Next[i] = j;
		}
		else
			j = Next[j];
	}
}

int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> S[i];
	for (int j = 0; j < m; j++)
		cin >> T[j];
	Get_NextVal();
	int ans = 0;
	int p1 = 0, p2 = 0;
	int ok = 1, tmp = 0;
	while (p1 < n)
	{
		if (p2 == -1 || (S[p1]) == (T[p2] + tmp) || ok)
		{
			tmp = S[p1] - T[p2];
			p1++;
			p2++;
			ok = 0;
		}
		else
		{
			p2 = Next[p2];
			ok = 1;
		}
		if (p2 == m)
		{
			ans++;
			p2 = 0;
			ok = 1;
		}
	}
	cout << ans << endl;
	return 0;
}


#include "iostream"
#define SIZE 10005

using namespace std;

typedef int ElemType;
ElemType S[2 * SIZE], T[2 * SIZE];
ElemType Next[2 * SIZE];
int n, m;
int flag1 = 0, flag2 = 0;

void Get_NextVal()
{
	int i = 0, j = -1;
	Next[i] = j;
	while (m - 1 > i)
	{
		if (j == -1 || T[i] == T[j])
		{
			i++;
			j++;
			Next[i] = j;
		}
		else
			j = Next[j];
	}
}

int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> S[i];
	for (int j = 0; j < m; j++)
		cin >> T[j];
	Get_NextVal();
	int ans = 0;
	int p1 = 0, p2 = 0;
	int ok = 1, tmp = 0;
	while (p1 < n)
	{
		if (p2 == -1 || (S[p1]) == (T[p2] + tmp) || ok)
		{
			tmp = S[p1] - T[p2];
			p1++;
			p2++;
			ok = 0;
		}
		else
		{
			p2 = Next[p2];
			ok = 1;
		}
		if (p2 == m)
		{
			ans++;
			p2 = 0;
			p1 = p1 - m + 1;
			ok = 1;
		}
	}
	for (int k = 0; k < n - 1; k++)
	if (S[k] != S[k + 1]) {
		flag1 = 1; break;
	}
	for (int h = 0; h < m - 1; h++)
	if (T[h] != T[h + 1]){
		flag2 = 1; break;
	}
	if (!flag1 && !flag2)
	{
		ans = n - m + 1;
		cout << ans << endl;
	}
	else  cout << ans << endl;
	return 0;
}


#include "iostream"
#define SIZE 100005

using namespace std;

typedef int ElemType;
ElemType S[2 * SIZE], T[2 * SIZE];
ElemType Next[2 * SIZE];
int n, m;
int flag1 = 0, flag2 = 0;

void Get_NextVal()
{
	int i = 0, j = -1;
	Next[i] = j;
	while (m - 1 > i)
	{
		if (j == -1 || T[i] == T[j])
		{
			i++;
			j++;
			Next[i] = j;
		}
		else
			j = Next[j];
	}
}

int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> S[i];
	for (int j = 0; j < m; j++)
		cin >> T[j];
	Get_NextVal();
	int ans = 0;
	int p1 = 0, p2 = 0;
	int ok = 1, tmp = 0;

	for (int k = 0; k < n - 1; k++)
	if (S[k] != S[k + 1]) {
		flag1 = 1; break;
	}
	for (int h = 0; h < m - 1; h++)
	if (T[h] != T[h + 1]){
		flag2 = 1; break;
	}

	if (!flag1 && !flag2)
	{
		ans = n - m + 1;
		cout << ans << endl;
	}
	else
	{
		while (p1 < n)
		{
			if (p2 == -1 || (S[p1]) == (T[p2] + tmp) || ok)
			{
				tmp = S[p1] - T[p2];
				p1++;
				p2++;
				ok = 0;
			}
			else
			{
				p2 = Next[p2];
				ok = 1;
				tmp = 0;
			}
			if (p2 == m)
			{
				ans++;
				p2 = 0;
				p1 = p1 - m + 1;
				ok = 1;
				tmp = 0;
			}
		}
	 cout << ans << endl;
	}
	return 0;
}


#include "iostream"
#define SIZE 100005

using namespace std;

typedef int ElemType;
ElemType S[2 * SIZE], T[2 * SIZE];
ElemType Next[2 * SIZE];
int n, m;
int flag1 = 0, flag2 = 0;

void Get_NextVal()
{
	int i = 0, j = -1;
	Next[i] = j;
	while (m - 1 > i)
	{
		if (j == -1 || T[i] == T[j])
		{
			i++;
			j++;
			Next[i] = j;
		}
		else
			j = Next[j];
	}
}

int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> S[i];
	for (int j = 0; j < m; j++)
		cin >> T[j];
	Get_NextVal();
	int ans = 0;
	int p1 = 0, p2 = 0;
	int ok = 1, tmp = 0;
	while (p1 < n)
	{
		if (p2 == -1 || (S[p1]) == (T[p2] + tmp) || ok)
		{
			tmp = S[p1] - T[p2];
			p1++;
			p2++;
			ok = 0;
		}
		else
		{
			p2 = Next[p2];
			ok = 1;
		}
		if (p2 == m)
		{
			ans++;
			p2 = 0;
			ok = 1;
		}
	}
	for (int k = 0; k < n - 1; k++)
	if (S[k] != S[k + 1]) {
		flag1 = 1; break;
	}
	for (int h = 0; h < m - 1; h++)
	if (T[h] != T[h + 1]){
		flag2 = 1; break;
	}
	if (!flag1 && !flag2)
	{
		ans = n - m + 1;
		cout << ans << endl;
	}
	else  cout << ans << endl;
	return 0;
}


#include "iostream"
#define SIZE 100005

using namespace std;

typedef int ElemType;
ElemType S[2 * SIZE], T[2 * SIZE];
ElemType Next[2 * SIZE];
int n, m;
int flag1 = 0, flag2 = 0;

void Get_NextVal()
{
	int i = 0, j = -1;
	Next[i] = j;
	while (m - 1 > i)
	{
		if (j == -1 || T[i] == T[j])
		{
			i++;
			j++;
			Next[i] = j;
		}
		else
			j = Next[j];
	}
}

int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> S[i];
	for (int j = 0; j < m; j++)
		cin >> T[j];
	Get_NextVal();
	int ans = 0;
	int p1 = 0, p2 = 0;
	int ok = 1, tmp = 0;
	while (p1 < n)
	{
		if (p2 == -1 || (S[p1]) == (T[p2] + tmp) || ok)
		{
			tmp = S[p1] - T[p2];
			p1++;
			p2++;
			ok = 0;
		}
		else
		{
			p2 = Next[p2];
			ok = 1;
		}
		if (p2 == m)
		{
			ans++;
			p2 = 0;
			p1 = p1 - m + 1;
			ok = 1;
		}
	}
	for (int k = 0; k < n - 1; k++)
	if (S[k] != S[k + 1]) {
		flag1 = 1; break;
	}
	for (int h = 0; h < m - 1; h++)
	if (T[h] != T[h + 1]){
		flag2 = 1; break;
	}
	if (!flag1 && !flag2)
	{
		ans = n - m + 1;
		cout << ans << endl;
	}
	else  cout << ans << endl;
	return 0;
}


#include "iostream"

#define SIZE 100005
#define LL long long

using namespace std;

LL S[SIZE * 2][2], T[SIZE * 2];

int n, m;
LL cnt;

void RE_Deal()
{
	LL sum = 0;
	int d = 0;
	for (int i = n - 1; i >= 0; i--)
	{
		d++;
		if (d >= m)
		{
			S[i][1] = sum + S[i][0] - S[i + m][0];
			sum = S[i][1];
		}
		else
		    sum += S[i][0];
	}
}

int solve()
{
	int ans = 0;
	int p1 = 0, p2 = 0;
	LL tmp = 0;
	while (p1 < n)
	{
		tmp = S[p1][0] - T[0];
		if (S[p1][1] == (cnt + (tmp * m)))
		{
			int p = p1, ok = 0;
			for (int i = 0; i < m; i++)
			{
				if ( S[p++][0] != (T[i] + tmp) ) { ok = 1; break; }
			}
			if (!ok) ans++;
		}
		p1++;
	}
	return ans;
}

int judge()
{
	int flag1 = 0, flag2 = 0;
	for (int i = 0; i < n - 1; i++)
	{
		if (S[i][0] != S[i + 1][0]) { flag1 = 1; break; }
	}
	for (int j = 0; j < m - 1; j++)
	{
		if (T[j] != T[j + 1]) { flag2 = 1; break; }
	}
	if (!flag1 && !flag2) return 1;
	return 0;
}

int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> S[i][0];
	for (int j = 0; j < m; j++)
	{
		cin >> T[j];
		cnt += T[j];
	}
	if (judge())
	{
		cout << n - m + 1 << endl;
	}
	else
	{
		RE_Deal();
		int ans = solve();
		cout << ans << endl;
	}
	return 0;
}


#include "iostream"
#include "string"
#define SIZE 100005

using namespace std;

string str1, str2;
int n, m;
int num1[SIZE * 2], num2[SIZE * 2];

char ch[20];

int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; i++){
	//	cin >> num1[i];
		scanf("%d", &num1[i]);
		if (i > 0) { sprintf(ch, "%d", (num1[i] - num1[i - 1])); str1 += ch; }
	}
	for (int j = 0; j < m; j++)
	{
	//	cin >> num2[j];
		scanf("%d", &num2[j]);
		if (j > 0) { sprintf(ch, "%d", (num2[j] - num2[j - 1])); str2 += ch; }
	}
	int ans = 0, flag = -1;
	while ((flag = str1.find(str2, flag + 1)) != -1) ans++;
	cout << ans << endl;
	return 0;
}


#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;

const int N = 4e+5 +5;
int a[N], z[N];

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,w,x,y;
	cin >> w >> n;
	cin >> x;
	for (int i = 0; i < w-1; ++i) {
		cin >> y;
		a[i + n-1] = y - x;
		x = y;
	}
	cin >> x;
	for (int i = 0; i < n-1; ++i) {
		cin >> y;
		a[i] = y - x;
		x = y;
	}
	int ans = 0;
	int l = 0, r = 0, h = w - 1 + n - 1;
	/*for (int i = 0; i < h; ++i) {
		//cout << a[i] << " ";
		printf("%+05d ",a[i]);
	}
	cout << endl;*/
	for (int i = 1; i < h; ++i) {
		if (i<=r) {
			z[i] = min(r-i+1, z[i-l]);
		}
		while (a[i+z[i]] == a[z[i]] && i+z[i] < h) ++z[i];
		if (i+z[i] > r) {
			l = i;
			r = i + z[i];
		}
		if (z[i] >= n-1) ans++;
		//cout << z[i] << " ";
		//printf("%+05d ",z[i]);
	}
	cout << /*endl <<*/ ans << endl;
	return 0;
}


#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;

const int N = 4e+5 +5;
int a[N], z[N];

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,w,x,y;
	cin >> w >> n;
	cin >> x;
	for (int i = 0; i < w-1; ++i) {
		cin >> y;
		a[i + n-1] = y - x;
		x = y;
	}
	cin >> x;
	for (int i = 0; i < n-1; ++i) {
		cin >> y;
		a[i] = y - x;
		x = y;
	}
	int ans = 0;
	int l = 0, r = 0, h = w - 1 + n - 1;
	/*for (int i = 0; i < h; ++i) {
		//cout << a[i] << " ";
		printf("%+05d ",a[i]);
	}
	cout << endl;*/
	for (int i = 1; i < h; ++i) {
		if (i<=r) {
			z[i] = min(r-i+1, z[i-l]);
		}
		while (a[i+z[i]] == a[z[i]] && i+z[i] < h) ++z[i];
		if (i+z[i] > r) {
			l = i;
			r = i + z[i];
		}
		if (z[i] >= n-1) ans++;
		//cout << z[i] << " ";
		//printf("%+05d ",z[i]);
	}
	if (n == 1) ans = w;
	cout << /*endl <<*/ ans << endl;
	return 0;
}


#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;

const int N = 4e+5 +5;
int a[N], z[N];

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,w,x,y;
	cin >> w >> n;
	cin >> x;
	for (int i = 0; i < w-1; ++i) {
		cin >> y;
		a[i + n-1] = y - x;
		x = y;
	}
	cin >> x;
	for (int i = 0; i < n-1; ++i) {
		cin >> y;
		a[i] = y - x;
		x = y;
	}
	int ans = 0;
	int l = 0, r = 0, h = w - 1 + n - 1;
	/*for (int i = 0; i < h; ++i) {
		//cout << a[i] << " ";
		printf("%+05d ",a[i]);
	}
	cout << endl;*/
	z[0] = 0;
	for (int i = 1; i < h; ++i) {
		if (i<=r) {
			z[i] = min(r-i+1, z[i-l]);
		}
		while (a[i+z[i]] == a[z[i]] && i+z[i] < h) ++z[i];
		if (i+z[i]-1 > r) {
			l = i;
			r = i + z[i]-1;
		}
		if (z[i] >= n-1 && i > n-2) ans++;
		//cout << z[i] << " ";
		//printf("%+05d ",z[i]);
	}
	if (n == 1) ans = w;
	cout << /*endl <<*/ ans << endl;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:128000000")
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <cmath>
#include <functional>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef long double ld;
const ll size = 400007;
const ll modulo = 1000000007;
const int oo = 1e9;
const double EPS = 1e-12;
const double PI = 3.14159;

int main()
{
	int n, w;
	cin >> n >> w;
	if (w == 1)
	{
		cout << n << endl;
		return 0;
	}
	vector<ll> a(n), b(w), da(n), db(w);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (i > 0) da[i] = a[i] - a[i - 1];
	}
	for (int i = 0; i < w; i++)
	{
		cin >> b[i];
		if (i > 0) db[i] = b[i] - b[i - 1];
	}
	vector<int> d(n + w - 1), pref(n + w - 1);
	for (int i = 0; i < w-1; i++)
		d[i] = db[i+1];
	d[w-1] = 2000000007;
	for (int i = 1; i < n; i++)
		d[w + i-1] = da[i];
	int ans = 0;
	for (int i = 1; i < n + w - 1; i++)
	{
		int j = pref[i - 1];
		while (j > 0 && d[j] != d[i])
			j = pref[j - 1];
		pref[i] = j + (d[j] == d[i]);
		if (pref[i] == w - 1)
			++ans;
	}
	cout << ans << endl;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:128000000")
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <cmath>
#include <functional>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef long double ld;
const ll size = 400007;
const ll modulo = 1000000007;
const int oo = 1e9;
const double EPS = 1e-12;
const double PI = 3.14159;

int main()
{
	int n, w;
	cin >> n >> w;
	if (w == 1)
	{
		cout << n << endl;
		return 0;
	}
	vector<ll> a(n), b(w), da(n), db(w);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (i > 0) da[i] = a[i] - a[i - 1];
		da[i] += 1000000000;
	}
	for (int i = 0; i < w; i++)
	{
		cin >> b[i];
		if (i > 0) db[i] = b[i] - b[i - 1];
		db[i] += 1000000000;
	}
	ll p = 3000000007LL;
	vector<ll> pp(n,1);
	for (int i = 1; i < n; i++)
		pp[i] = pp[i - 1] * p;
	vector<ll> ha(n), hb(w);
	for (int i = 1; i < n; i++)
		ha[i] = ha[i - 1] + da[i] * pp[i];
	for (int i = 1; i < w; i++)
		hb[i] = hb[i - 1] + db[i] * pp[i];
	int ans = 0;
	ll needed = hb[w - 1];
	for (int i = w - 1; i < n; i++)
	{
		if (ha[i] - ha[i - w + 1] == needed)
			++ans;
		needed *= p;
	}
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <functional>
#include <queue>
#include <set>
#include <string>

using namespace std;

const long long inf = 1e9 + 1;

vector <long long> ar;
vector <int> Z;
int n, w;

void incZ() {
    int l = 0, r = 0;
    int nn = ar.size();
    for (int i = 1; i < nn; ++i) {
        if (i <= r){
            Z[i] = min(r - i + 1, Z[i - l]);
        }
        while (i + Z[i] < nn && ar[Z[i]] == ar[i + Z[i]]){
            Z[i]++;
        }
        if (i + Z[i] > r){
            l = i;
            r = i + Z[i];
        }
    }
}

int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("input.txt", "w", stdout);
    /*for (int i = 0; i < 300000; ++i){
        cout << "1 ";
    }
    cout << endl;
    */

    cin >> n >> w;
    if (w == 1){
        cout << n << endl;
        return 0;
    }
    if (n < w){
        cout << 0 << endl;
        return 0;
    }
    vector <int> ar1(n);
    for (int i = 0; i < n; ++i){
        cin >> ar1[i];
    }
    vector <int> ar2(w);
    for (int i = 0; i < w; ++i){
        cin >> ar2[i];
    }

    ar.reserve(n + w - 1);
    for (int i = 1; i < ar2.size(); ++i){
        ar.push_back(ar2[i] - ar2[i - 1]);
    }
    ar.push_back(inf);
    for (int i = 1; i < ar1.size(); ++i){
        ar.push_back(ar1[i] - ar1[i - 1]);
    }

    Z.resize(ar.size());
    incZ();
    int cnt = 0;
    for (int i = 1; i < Z.size(); ++i){
        if (Z[i] == w - 1){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <functional>
#include <queue>
#include <set>
#include <string>

using namespace std;

const long long inf = 1e10;

vector <long long> ar;
vector <int> Z;
int n, w;

void incZ() {
    int l = 0, r = 0;
    int nn = ar.size();
    for (int i = 0; i < nn; ++i) {
        if (i <= r){
            Z[i] = min(r - i + 1, Z[i - l]);
        }

        while (i + Z[i] < nn && ar[Z[i]] == ar[i + Z[i]]){
            Z[i]++;
        }
        if (i + Z[i] > r){
            l = i;
            r = i + Z[i];
        }
    }
}

int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    cin >> n >> w;
    vector <int> ar1(n);
    for (int i = 0; i < n; ++i){
        cin >> ar1[i];
    }
    vector <int> ar2(w);
    for (int i = 0; i < w; ++i){
        cin >> ar2[i];
    }
    Z.resize(n + w + 1);
    for (int i = 1; i < ar2.size(); ++i){
        ar.push_back(ar2[i] - ar2[i - 1]);
    }
    ar.push_back(-inf);
    for (int i = 1; i < n; ++i){
        ar.push_back(ar1[i] - ar1[i - 1]);
    }

    incZ();
    int cnt = 0;
    for (int i = w + 1; i <= n + w; ++i){
        if (Z[i] == w - 1){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <functional>
#include <queue>
#include <set>
#include <string>

using namespace std;

const long long inf = 1e9 + 1;

vector <long long> ar;
vector <int> Z;
int n, w;

void incZ() {
    int l = 0, r = 0;
    int nn = ar.size();
    for (int i = 0; i < nn; ++i) {
        if (i <= r){
            Z[i] = min(r - i + 1, Z[i - l]);
        }
        while (i + Z[i] < nn && ar[Z[i]] == ar[i + Z[i]]){
            Z[i]++;
        }
        if (i + Z[i] > r){
            l = i;
            r = i + Z[i];
        }
    }
}

int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    cin >> n >> w;
    if (w == 1){
        cout << n << endl;
        return 0;
    }
    if (n < w){
        cout << 0 << endl;
        return 0;
    }
    vector <int> ar1(n);
    for (int i = 0; i < n; ++i){
        cin >> ar1[i];
    }
    vector <int> ar2(w);
    for (int i = 0; i < w; ++i){
        cin >> ar2[i];
    }

    ar.reserve(n + w - 1);
    for (int i = 1; i < ar2.size(); ++i){
        ar.push_back(ar2[i] - ar2[i - 1]);
    }
    ar.push_back(inf);
    for (int i = 1; i < ar1.size(); ++i){
        ar.push_back(ar1[i] - ar1[i - 1]);
    }

    Z.resize(ar.size());
    incZ();
    int cnt = 0;
    for (int i = 1; i < Z.size(); ++i){
        if (Z[i] == w - 1){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <functional>
#include <queue>
#include <set>
#include <string>

using namespace std;

const long long inf = 1e10;

vector <long long> ar;
vector <pair <int, long long> > Z;

void incZ() {
    int l = 0, r = 0;
    for (int i = 1; i < ar.size(); ++i) {
        if (i <= r){
            if (ar[i] - ar[0] == Z[i - l].second - ar[0]){
                Z[i].first = min(r - i + 1, Z[i - l].first);
                Z[i].second = ar[i] - ar[0];
            }
            else{
                Z[i].first = 1;
                Z[i].second = ar[i] - ar[0];
            }
        }
        else{
            Z[i].first = 1;
            Z[i].second = ar[i] - ar[0];
        }
        while (i + Z[i].first < ar.size() && ar[Z[i].first] + Z[i].second == ar[i + Z[i].first]){
            Z[i].first++;
        }
        if (i + Z[i].first - 1 > r){
            l = i;
            r = i + Z[i].first - 1;
        }
    }
}

int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n, w;
    cin >> n >> w;
    Z.resize(n + w + 1);
    ar.resize(n + w + 1);
    ar[w] = -inf;
    for (int i = w + 1; i <= n + w; ++i){
        cin >> ar[i];
    }
    for (int i = 0; i < w; ++i){
        cin >> ar[i];
    }
    incZ();
    int cnt = 0;
    for (int i = w + 1; i <= n + w; ++i){
        if (Z[i].first == w){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <functional>
#include <queue>
#include <set>
#include <string>

using namespace std;

const long long inf = 1e10;

vector <long long> ar;
vector <int> Z;
vector <long long> dl;
int n, w;

void incZ() {
    int l = 0, r = 0;
    for (int i = w + 1; i < ar.size(); ++i) {
        if (i <= r){

                Z[i] = min(r - i + 1, Z[i - l]);
                dl[i] = ar[i] - ar[0];

        }
        else{
            Z[i] = 1;
            dl[i] = ar[i] - ar[0];
        }
        while (i + Z[i] < ar.size() && ar[Z[i]] + dl[i] == ar[i + Z[i]]){
            Z[i]++;
        }
        if (i + Z[i] - 1 > r){
            l = i;
            r = i + Z[i] - 1;
        }
    }
}

int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    cin >> n >> w;
    Z.resize(n + w + 1);
    dl.resize(n + w + 1);
    ar.resize(n + w + 1);
    ar[w] = -inf;
    for (int i = w + 1; i <= n + w; ++i){
        cin >> ar[i];
    }
    for (int i = 0; i < w; ++i){
        cin >> ar[i];
    }
    incZ();
    int cnt = 0;
    for (int i = w + 1; i <= n + w; ++i){
        if (Z[i] == w){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <functional>
#include <queue>
#include <set>
#include <string>

using namespace std;

const long long inf = 1e9 + 1;

vector <long long> ar;
vector <int> Z;
int n, w;

void incZ() {
    int l = 0, r = 0;
    int nn = ar.size();
    for (int i = 0; i < nn; ++i) {
        if (i <= r){
            Z[i] = min(r - i + 1, Z[i - l]);
        }
        while (i + Z[i] < nn && ar[Z[i]] == ar[i + Z[i]]){
            Z[i]++;
        }
        if (i + Z[i] > r){
            l = i;
            r = i + Z[i] - 1;
        }
    }
}

int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    cin >> n >> w;
    if (w == 1){
        cout << n << endl;
        return 0;
    }
    if (n < w){
        cout << 0 << endl;
        return 0;
    }
    vector <int> ar1(n);
    for (int i = 0; i < n; ++i){
        cin >> ar1[i];
    }
    vector <int> ar2(w);
    for (int i = 0; i < w; ++i){
        cin >> ar2[i];
    }

    ar.reserve(n + w - 1);
    for (int i = 1; i < ar2.size(); ++i){
        ar.push_back(ar2[i] - ar2[i - 1]);
    }
    ar.push_back(inf);
    for (int i = 1; i < ar1.size(); ++i){
        ar.push_back(ar1[i] - ar1[i - 1]);
    }

    Z.resize(ar.size());
    incZ();
    int cnt = 0;
    for (int i = 1; i < Z.size(); ++i){
        if (Z[i] == w - 1){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <functional>
#include <queue>
#include <set>
#include <string>

using namespace std;

const long long inf = 1e10;

vector <long long> ar;
vector <int> Z;
vector <long long> dl;
int n, w;

void incZ() {
    int l = 0, r = 0;
    for (int i = w + 1; i < ar.size(); ++i) {
        if (i <= r){
            if (ar[i] - ar[0] == dl[i - l] - ar[0]){
                Z[i] = min(r - i + 1, Z[i - l]);
                dl[i] = ar[i] - ar[0];
            }
            else{
                Z[i] = 1;
                dl[i] = ar[i] - ar[0];
            }
        }
        else{
            Z[i] = 1;
            dl[i] = ar[i] - ar[0];
        }
        while (i + Z[i] < ar.size() && ar[Z[i]] + dl[i] == ar[i + Z[i]]){
            Z[i]++;
        }
        if (i + Z[i] - 1 > r){
            l = i;
            r = i + Z[i] - 1;
        }
    }
}

int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    cin >> n >> w;
    Z.resize(n + w + 1);
    dl.resize(n + w + 1);
    ar.resize(n + w + 1);
    ar[w] = -inf;
    for (int i = w + 1; i <= n + w; ++i){
        cin >> ar[i];
    }
    for (int i = 0; i < w; ++i){
        cin >> ar[i];
    }
    incZ();
    int cnt = 0;
    for (int i = w + 1; i <= n + w; ++i){
        if (Z[i] == w){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <functional>
#include <queue>
#include <set>
#include <string>

using namespace std;

const long long inf = 1e9 + 1;

vector <long long> ar;
vector <int> Z;
int n, w;

void incZ() {
    int l = 0, r = 0;
    int nn = ar.size();
    for (int i = 1; i < nn; ++i) {
        if (i <= r){
            Z[i] = min(r - i + 1, Z[i - l]);
        }
        while (i + Z[i] < nn && ar[Z[i]] == ar[i + Z[i]]){
            Z[i]++;
        }
        if (i + Z[i] > r){
            l = i;
            r = i + Z[i] - 1;
        }
    }
}

int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    cin >> n >> w;
    if (w == 1){
        cout << n << endl;
        return 0;
    }
    if (n < w){
        cout << 0 << endl;
        return 0;
    }
    vector <int> ar1(n);
    for (int i = 0; i < n; ++i){
        cin >> ar1[i];
    }
    vector <int> ar2(w);
    for (int i = 0; i < w; ++i){
        cin >> ar2[i];
    }

    ar.reserve(n + w - 1);
    for (int i = 1; i < ar2.size(); ++i){
        ar.push_back(ar2[i] - ar2[i - 1]);
    }
    ar.push_back(inf);
    for (int i = 1; i < ar1.size(); ++i){
        ar.push_back(ar1[i] - ar1[i - 1]);
    }

    Z.resize(ar.size());
    incZ();
    int cnt = 0;
    for (int i = 1; i < Z.size(); ++i){
        if (Z[i] == w - 1){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <functional>
#include <queue>
#include <set>
#include <string>

using namespace std;

const long long inf = 1e10;

vector <long long> ar;
vector <int> Z;
int n, w;

void incZ() {
    int l = 0, r = 0;
    int nn = ar.size();
    for (int i = 0; i < nn; ++i) {
        if (i <= r){
            Z[i] = min(r - i + 1, Z[i - l]);
        }

        while (i + Z[i] < nn && ar[Z[i]] == ar[i + Z[i]]){
            Z[i]++;
        }
        if (i + Z[i] > r){
            l = i;
            r = i + Z[i];
        }
    }
}

int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    cin >> n >> w;
    if (w == 1){
        cout << n << endl;
        return 0;
    }
    if (n < w){
        cout << 0 << endl;
        return 0;
    }
    vector <int> ar1(n);
    for (int i = 0; i < n; ++i){
        cin >> ar1[i];
    }
    vector <int> ar2(w);
    for (int i = 0; i < w; ++i){
        cin >> ar2[i];
    }
    Z.resize(n + w + 1);
    for (int i = 1; i < ar2.size(); ++i){
        ar.push_back(ar2[i] - ar2[i - 1]);
    }
    ar.push_back(-inf);
    for (int i = 1; i < n; ++i){
        ar.push_back(ar1[i] - ar1[i - 1]);
    }

    incZ();
    int cnt = 0;
    for (int i = w + 1; i <= n + w; ++i){
        if (Z[i] == w - 1){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <functional>
#include <queue>
#include <set>
#include <string>

using namespace std;

const long long inf = 1e9 + 1;

vector <long long> ar;
vector <int> Z;
int n, w;

void incZ() {
    int l = 0, r = 0;
    int nn = ar.size();
    for (int i = 1; i < nn; ++i) {
        if (i <= r){
            Z[i] = min(r - i + 1, Z[i - l]);
        }
        while (i + Z[i] < nn && ar[Z[i]] == ar[i + Z[i]]){
            Z[i]++;
        }
        if (i + Z[i] > r){
            l = i;
            r = i + Z[i];
        }
    }
}

int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    cin >> n >> w;
    if (w == 1){
        cout << n << endl;
        return 0;
    }
    if (n < w){
        cout << 0 << endl;
        return 0;
    }
    vector <int> ar1(n);
    for (int i = 0; i < n; ++i){
        cin >> ar1[i];
    }
    vector <int> ar2(w);
    for (int i = 0; i < w; ++i){
        cin >> ar2[i];
    }

    ar.reserve(n + w - 1);
    for (int i = 1; i < ar2.size(); ++i){
        ar.push_back(ar2[i] - ar2[i - 1]);
    }
    ar.push_back(inf);
    for (int i = 1; i < ar1.size(); ++i){
        ar.push_back(ar1[i] - ar1[i - 1]);
    }

    Z.resize(ar.size());
    incZ();
    int cnt = 0;
    for (int i = 1; i < Z.size(); ++i){
        if (Z[i] == w - 1){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <functional>
#include <queue>
#include <set>
#include <string>

using namespace std;

const long long inf = 1e10;

vector <long long> ar;
vector <int> Z;
int n, w;

void incZ() {
    int l = 0, r = 0;
    int nn = ar.size();
    for (int i = 0; i < nn; ++i) {
        if (i <= r){
            Z[i] = min(r - i + 1, Z[i - l]);
        }

        while (i + Z[i] < nn && ar[Z[i]] == ar[i + Z[i]]){
            Z[i]++;
        }
        if (i + Z[i] > r){
            l = i;
            r = i + Z[i];
        }
    }
}

int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    cin >> n >> w;
    if (w == 1){
        cout << n << endl;
        return 0;
    }
    if (n < w){
        cout << 0 << endl;
        return 0;
    }
    vector <int> ar1(n);
    for (int i = 0; i < n; ++i){
        cin >> ar1[i];
    }
    vector <int> ar2(w);
    for (int i = 0; i < w; ++i){
        cin >> ar2[i];
    }
    Z.resize(n + w - 1);
    for (int i = 1; i < ar2.size(); ++i){
        ar.push_back(ar2[i] - ar2[i - 1]);
    }
    ar.push_back(-inf);
    for (int i = 1; i < n; ++i){
        ar.push_back(ar1[i] - ar1[i - 1]);
    }

    incZ();
    int cnt = 0;
    for (int i = w; i < Z.size(); ++i){
        if (Z[i] == w - 1){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>

using namespace std;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size()))
#define pb push_back
#define mp make_pair
#define X first
#define Y second

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

const int INF = (int)(1e9);
const li INF64 = (li)(INF) * (li)(INF);
const ld eps = 1e-9;
const ld PI = (ld)(3.1415926535897932384626433832795);

const int N = 3e5;

li a[N], b[N];
int n, m;
li pref[N];
li dif[N];
li pows[N];
const li base = 2 * INF + 11;

int main()
{
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif;

    srand(int(time(NULL)));

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

    forn(i, n)
        scanf("%I64d", &a[i + 1]);
    forn(i, m)
        scanf("%I64d", &b[i + 1]);

    if(m == 1)
    {
        cout << n << endl;
        return 0;
    }

    if(m > n)
    {
        cout << 0 << endl;
        return 0;
    }

    for(int i = 1; i < m; i++)
        dif[i] = b[i + 1] - b[i];

    pows[0] = 1LL;
    for(int i = 1; i < N; i++)
        pows[i] = pows[i - 1] * base;

    li need = 0;
    for(int i = 1; i < m; i++)
        need += dif[i] * pows[i];

    need *= pows[N - 1 - (m - 1)];

    for(int i = 1; i < n; i++)
        a[i] = a[i + 1] - a[i];

    li H = 0;
    for(int i = 1; i < n; i++)
    {
        H += a[i] * pows[i];
        pref[i] = H;
    }

    int ans = 0;
    for(int i = 1; i <= n - m + 1; i++)
    {
        int idx = i + m - 1 - 1;
        li curH = pref[idx];
        curH -= pref[i - 1];
        curH *= pows[N - 1 - idx];
        if(curH == need)
            ans++;
    }

    cout << ans << endl;

    return 0;
}


#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>

using namespace std;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size()))
#define pb push_back
#define mp make_pair
#define X first
#define Y second

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

const int INF = (int)(1e9);
const li INF64 = (li)(INF) * (li)(INF);
const ld eps = 1e-9;
const ld PI = (ld)(3.1415926535897932384626433832795);

const int N = 3e5;

li a[N], b[N];
int n, m;
li pref[N];
li dif[N];
li pows[N];
const li base = INF + 9;

int main()
{
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif;

    srand(int(time(NULL)));

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

    forn(i, n)
        scanf("%I64d", &a[i + 1]);
    forn(i, m)
        scanf("%I64d", &b[i + 1]);

    if(m == 1)
    {
        cout << n << endl;
        return 0;
    }

    if(m > n)
    {
        cout << 0 << endl;
        return 0;
    }

    for(int i = 1; i < m; i++)
        dif[i] = b[i + 1] - b[i];

    pows[0] = 1LL;
    for(int i = 1; i < N; i++)
        pows[i] = pows[i - 1] * base;

    li need = 0;
    for(int i = 1; i < m; i++)
        need += dif[i] * pows[i];

    need *= pows[N - 1 - (m - 1)];

    for(int i = 1; i < n; i++)
        a[i] = a[i + 1] - a[i];

    li H = 0;
    for(int i = 1; i < n; i++)
    {
        H += a[i] * pows[i];
        pref[i] = H;
    }

    int ans = 0;
    for(int i = 1; i <= n - m + 1; i++)
    {
        int idx = i + m - 1 - 1;
        li curH = pref[idx];
        curH -= pref[i - 1];
        curH *= pows[N - 1 - idx];
        if(curH == need)
            ans++;
    }

    cout << ans << endl;

    return 0;
}


#include<iostream>
#include<set>
#include<string>
#include<map>
#include<vector>
#include<unordered_set>
#include<math.h>
#include<algorithm>
#include<math.h>
#include<cassert>
using namespace std;
double ans;
double sum2;
const int MAX = 3333333;
int z[MAX];
const int INF = INT_MAX;

void z_func(vector<int> &s){
    for (int i=1, l=0, r=0; i<s.size(); i++){
        if (i<=r)
            z[i]=min(z[i-l],r-i+1);
        while (i+z[i]<s.size() && s[z[i]] == s[i+z[i]] )
            z[i]++;
        if (i+z[i]-1>r)
            l=i; r=i+z[i]-1;
    }
}

int main(){
    int n, w;
    cin>> n>> w;
    vector<int> qq;
    vector<int> bb;

    if (w==1){
        cout<<n;
        return 0;
    }
    if (n==1){
        cout<<0;
        return 0;
    }

    for (int i=0; i<n; i++)
    {
        int x;
        scanf("%d", &x);
        qq.push_back(x);
    }

        int x;
        cin>>x;

    for (int i=1; i<w; i++)
    {
        int y;
        scanf("%d", &y);
        bb.push_back(y-x);
        x = y;
    }
    bb.push_back(INF);
    for (int i=1; i<n; i++)
        bb.push_back(qq[i]-qq[i-1]);
    z_func(bb);
    int ans = 0;
    for (int i = w; i<bb.size(); i++){
        if (z[i] == w-1) {
            ans++;
        }
    }
    cout<<ans;
}


#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>

using namespace std;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size()))
#define pb push_back
#define mp make_pair
#define X first
#define Y second

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

const int INF = (int)(1e9);
const li INF64 = (li)(INF) * (li)(INF);
const ld eps = 1e-9;
const ld PI = (ld)(3.1415926535897932384626433832795);

const int N = 3e5;

li a[N], b[N];
int n, m;
li pref[N];
li dif[N];
li pows[N];
const li base = INF + 7;

int main()
{
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif;

    srand(int(time(NULL)));

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

    forn(i, n)
        scanf("%I64d", &a[i + 1]);
    forn(i, m)
        scanf("%I64d", &b[i + 1]);

    if(m == 1)
    {
        cout << n << endl;
        return 0;
    }

    if(m > n)
    {
        cout << 0 << endl;
        return 0;
    }

    for(int i = 1; i < m; i++)
        dif[i] = b[i + 1] - b[i];

    pows[0] = 1LL;
    for(int i = 1; i < N; i++)
        pows[i] = pows[i - 1] * base;

    li need = 0;
    for(int i = 1; i < m; i++)
        need += dif[i] * pows[i];

    need *= pows[N - 1 - (m - 1)];

    for(int i = 1; i < n; i++)
        a[i] = a[i + 1] - a[i];

    li H = 0;
    for(int i = 1; i < n; i++)
    {
        H += a[i] * pows[i];
        pref[i] = H;
    }

    int ans = 0;
    for(int i = 1; i <= n - m + 1; i++)
    {
        int idx = i + m - 1 - 1;
        li curH = pref[idx];
        curH -= pref[i - 1];
        curH *= pows[N - 1 - idx];
        if(curH == need)
            ans++;
    }

    cout << ans << endl;

    return 0;
}


#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>

using namespace std;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size()))
#define pb push_back
#define mp make_pair
#define X first
#define Y second

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

const int INF = (int)(1e9);
const li INF64 = (li)(INF) * (li)(INF);
const ld eps = 1e-9;
const ld PI = (ld)(3.1415926535897932384626433832795);

const int N = 3e5;

li a[N], b[N];
int n, m;
li pref[N];
li dif[N];
li pows[N];
const li base = INF * 1LL * 11LL + 11111111LL + 111LL + 11LL;

int main()
{
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif;

    srand(int(time(NULL)));

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

    forn(i, n)
        scanf("%I64d", &a[i + 1]);
    forn(i, m)
        scanf("%I64d", &b[i + 1]);

    if(m == 1)
    {
        cout << n << endl;
        return 0;
    }

    if(m > n)
    {
        cout << 0 << endl;
        return 0;
    }

    for(int i = 1; i < m; i++)
        dif[i] = b[i + 1] - b[i];

    pows[0] = 1LL;
    for(int i = 1; i < N; i++)
        pows[i] = pows[i - 1] * base;

    li need = 0;
    for(int i = 1; i < m; i++)
        need += dif[i] * pows[i];

    need *= pows[N - 1 - (m - 1)];

    for(int i = 1; i < n; i++)
        a[i] = a[i + 1] - a[i];

    li H = 0;
    for(int i = 1; i < n; i++)
    {
        H += a[i] * pows[i];
        pref[i] = H;
    }

    int ans = 0;
    for(int i = 1; i <= n - m + 1; i++)
    {
        int idx = i + m - 1 - 1;
        li curH = pref[idx];
        curH -= pref[i - 1];
        curH *= pows[N - 1 - idx];
        if(curH == need)
            ans++;
    }

    cout << ans << endl;

    return 0;
}


#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>

using namespace std;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size()))
#define pb push_back
#define mp make_pair
#define X first
#define Y second

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

const int INF = (int)(1e9);
const li INF64 = (li)(INF) * (li)(INF);
const ld eps = 1e-9;
const ld PI = (ld)(3.1415926535897932384626433832795);

const int N = 3e5;

li a[N], b[N];
int n, m;
li pref[N];
li dif[N];
li pows[N];
const li base = INF + 7;

int main()
{
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif;

    srand(int(time(NULL)));

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

    forn(i, n)
        scanf("%I64d", &a[i + 1]);
    forn(i, m)
        scanf("%I64d", &b[i + 1]);

    if(m == 1)
    {
        cout << n << endl;
        return 0;
    }

    if(m > n)
    {
        cout << 0 << endl;
        return 0;
    }

    map<int, int> idx;
    int sz = 0;

    for(int i = 1; i < m; i++)
    {
        int val = b[i + 1] - b[i];
        if(idx.count(val) > 0)
            val = idx[val];
        else
        {
            idx[val] = ++sz;
            val = idx[val];
        }

        dif[i] = val;
    }

    pows[0] = 1LL;
    for(int i = 1; i < N; i++)
        pows[i] = pows[i - 1] * base;

    li need = 0;
    for(int i = 1; i < m; i++)
        need += dif[i] * pows[i];

    need *= pows[N - 1 - (m - 1)];

    for(int i = 1; i < n; i++)
    {
        int val = a[i + 1] - a[i];
        if(idx.count(val) > 0)
            val = idx[val];
        else
        {
            idx[val] = ++sz;
            val = idx[val];
        }

        a[i] = val;
    }

    li H = 0;
    for(int i = 1; i < n; i++)
    {
        H += a[i] * pows[i];
        pref[i] = H;
    }

    int ans = 0;
    for(int i = 1; i <= n - m + 1; i++)
    {
        int idx = i + m - 1 - 1;
        li curH = pref[idx];
        curH -= pref[i - 1];
        curH *= pows[N - 1 - idx];
        if(curH == need)
            ans++;
    }

    cout << ans << endl;

    return 0;
}


#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>

using namespace std;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size()))
#define pb push_back
#define mp make_pair
#define X first
#define Y second

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

const int INF = (int)(1e9);
const li INF64 = (li)(INF) * (li)(INF);
const ld eps = 1e-9;
const ld PI = (ld)(3.1415926535897932384626433832795);

const int N = 3e5;

li a[N], b[N];
int n, m;
li pref[N];
li dif[N];
li pows[N];
const li base = 113;

int main()
{
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif;

    srand(int(time(NULL)));

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

    forn(i, n)
        scanf("%I64d", &a[i + 1]);
    forn(i, m)
        scanf("%I64d", &b[i + 1]);

    if(m == 1)
    {
        cout << n << endl;
        return 0;
    }

    if(m > n)
    {
        cout << 0 << endl;
        return 0;
    }

    for(int i = 1; i < m; i++)
        dif[i] = b[i + 1] - b[i];

    pows[0] = 1LL;
    for(int i = 1; i < N; i++)
        pows[i] = pows[i - 1] * base;

    li need = 0;
    for(int i = 1; i < m; i++)
        need += dif[i] * pows[i];

    need *= pows[N - 1 - (m - 1)];

    for(int i = 1; i < n; i++)
        a[i] = a[i + 1] - a[i];

    li H = 0;
    for(int i = 1; i < n; i++)
    {
        H += a[i] * pows[i];
        pref[i] = H;
    }

    int ans = 0;
    for(int i = 1; i <= n - m + 1; i++)
    {
        int idx = i + m - 1 - 1;
        li curH = pref[idx];
        curH -= pref[i - 1];
        curH *= pows[N - 1 - idx];
        if(curH == need)
            ans++;
    }

    cout << ans << endl;

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <ctime>
#include <memory.h>
#include <assert.h>
#include <complex>
#include <ctime>
#include <cstdlib>
using namespace std;

#pragma comment(linker, "/STACK:100000000")

#define mp make_pair
#define pb push_back
#define sz(x) (int)(x).size()
#define ll long long
#define ull unsigned long long

int mas1[200200];
int mas2[200200];

int h1[200200];
int h2[200200];

int f[400400];

int p[400400];

void pre_f(int n) {
    p[0] = 0;
    for(int i = 1; i < n; i++) {
        int j = p[i-1];
        while(j > 0 && f[i] != f[j]) j = p[j-1];
        if(f[i] == f[j]) j++;
        p[i] = j;
    }
}

int main() {
    //freopen("input.txt", "rt", stdin);
    //freopen("cycle2.out", "wt", stdout);

    int n, w;
    scanf("%d %d", &n, &w);
    if(w == 1) {
        printf("%d\n", n);
        return 0;
    }
    if(w > n) {
        printf("0\n");
        return 0;
    }

    for(int i = 0; i < n; i++) scanf("%d", &mas1[i]);
    for(int i = 0; i < w; i++) scanf("%d", &mas2[i]);
    n--;
    w--;

    for(int i = 0; i < n; i++) h1[i] = mas1[i+1] - mas1[i] + 1000000000;
    for(int i = 0; i < w; i++) h2[i] = mas2[i+1] - mas2[i] + 1000000000;

    for(int i = 0; i < w; i++) f[i] = h2[i];
    f[w] = -1;
    for(int i = w + 1; i <= n + w; i++) f[i] = h1[i-w-1];

    pre_f(n + w + 1);
    int cnt = 0;
    for(int i = 0; i <= n + w; i++) {
        if(p[i] == w) {
            cnt++;
        }
    }
    printf("%d", cnt);

    return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <string>
#include <cstring>
#include <set>
using namespace std;

const int MAXN = 4 * 100000 + 5;
long long a[MAXN];

vector<int> prefix(int n, int m)
{
	vector<int> p(n + m);
	for (int i = 1; i < n + m; i++)
	{
		int j = p[i - 1];
		while (j > 0 && a[j] != a[i])
		{
			j = p[j - 1];
		}
		if (a[j] == a[i])
		{
			j++;
		}
		p[i] = j;
	}
	return p;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	//freopen("file.in", "r", stdin); freopen("file.out", "w", stdout);
	//freopen("palindrome.in", "r", stdin); freopen("palindrome.out", "w", stdout);

	int n, m;
	cin >> n >> m;

	if (m == 1)
	{
		cout << n;
		return 0;
	}

	long long f, s;
	cin >> f;
	for (int i = 0; i < n - 1; i++)
	{
		cin >> s;
		a[i + m] = s - f;
		f = s;
	}
	a[m - 1] = 100000000000;

	cin >> f;
	for (int i = 0; i < m - 1; i++)
	{
		cin >> s;
		a[i] = s - f;
		f = s;
	}
	n--;

	vector<int> p = prefix(n, m);

	long long res = 0;
	for (int i = m; i < n + m; i++)
	{
		if (p[i] == m - 1)
		{
			res++;
		}
	}
	cout << res;
	return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <string>
#include <cstring>
#include <set>
using namespace std;

const int MAXN = 4 * 100000 + 5;
long long a[MAXN];

vector<int> prefix(int n, int m)
{
	vector<int> p(n + m);
	for (int i = 1; i < n + m; i++)
	{
		int j = p[i - 1];
		while (j > 0 && a[j] != a[i])
		{
			j = p[j - 1];
		}
		if (a[j] == a[i] && i != m)
		{
			j++;
		}
		p[i] = j;
	}
	return p;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	//freopen("file.in", "r", stdin); freopen("file.out", "w", stdout);
	//freopen("palindrome.in", "r", stdin); freopen("palindrome.out", "w", stdout);

	int n, m;
	cin >> n >> m;

	long long f, s;
	cin >> f;
	for (int i = 0; i < n - 1; i++)
	{
		cin >> s;
		a[i + m] = s - f;
		f = s;
	}
	a[m - 1] = 100000000000;

	cin >> f;
	for (int i = 0; i < m - 1; i++)
	{
		cin >> s;
		a[i] = s - f;
		f = s;
	}

	vector<int> p = prefix(n, m);

	long long res = 0;
	for (int i = m; i < n + m; i++)
	{
		if (p[i] == m - 1)
		{
			res++;
		}
	}
	cout << res;
	return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <string>
#include <cstring>
#include <set>
using namespace std;

const int MAXN = 4 * 100000 + 5;
long long a[MAXN];

vector<int> prefix(int n, int m)
{
	vector<int> p(n + m);
	for (int i = 1; i < n + m; i++)
	{
		int j = p[i - 1];
		while (j > 0 && a[j] != a[i])
		{
			j = p[j - 1];
		}
		if (a[j] == a[i] && i != m)
		{
			j++;
		}
		p[i] = j;
	}
	return p;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	//freopen("file.in", "r", stdin); freopen("file.out", "w", stdout);
	//freopen("palindrome.in", "r", stdin); freopen("palindrome.out", "w", stdout);

	int n, m;
	cin >> n >> m;

	long long f, s;
	cin >> f;
	for (int i = 0; i < n - 1; i++)
	{
		cin >> s;
		a[i + m] = s - f;
		f = s;
	}
	a[m - 1] = 100000000000;

	cin >> f;
	for (int i = 0; i < m - 1; i++)
	{
		cin >> s;
		a[i] = s - f;
		f = s;
	}

	vector<int> p = prefix(n, m);

	long long res = 0;
	for (int i = 0; i < n + m; i++)
	{
		if (p[i] == m - 1)
		{
			res++;
		}
	}
	cout << res;
	return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <string>
#include <cstring>
#include <set>
using namespace std;

const int MAXN = 4 * 100000 + 5;
long long a[MAXN];

vector<int> prefix(int n, int m)
{
	vector<int> p(n + m);
	for (int i = 1; i < n + m; i++)
	{
		int j = p[i - 1];
		while (j > 0 && a[j] != a[i])
		{
			j = p[j - 1];
		}
		if (a[j] == a[i])
		{
			j++;
		}
		p[i] = j;
	}
	return p;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	//freopen("file.in", "r", stdin); freopen("file.out", "w", stdout);
	//freopen("palindrome.in", "r", stdin); freopen("palindrome.out", "w", stdout);

	int n, m;
	cin >> n >> m;

	long long f, s;
	cin >> f;
	for (int i = 0; i < n - 1; i++)
	{
		cin >> s;
		a[i + m] = s - f;
		f = s;
	}
	a[m - 1] = 100000000000;

	cin >> f;
	for (int i = 0; i < m - 1; i++)
	{
		cin >> s;
		a[i] = s - f;
		f = s;
	}

	vector<int> p = prefix(n, m);

	long long res = 0;
	for (int i = m; i < n + m; i++)
	{
		if (p[i] == m - 1)
		{
			res++;
		}
	}
	cout << res;
	return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <string>
#include <cstring>
#include <set>
using namespace std;

const int MAXN = 4 * 100000 + 5;
long long a[MAXN];

vector<int> prefix(int n, int m)
{
	vector<int> p(n + m);
	for (int i = 1; i < n + m; i++)
	{
		int j = p[i - 1];
		while (j > 0 && a[j] != a[i])
		{
			j = p[j - 1];
		}
		if (a[j] == a[i])
		{
			j++;
		}
		p[i] = j;
	}
	return p;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	//freopen("file.in", "r", stdin); freopen("file.out", "w", stdout);
	//freopen("palindrome.in", "r", stdin); freopen("palindrome.out", "w", stdout);

	int n, m;
	cin >> n >> m;

	long long f, s;
	cin >> f;
	for (int i = 0; i < n - 1; i++)
	{
		cin >> s;
		a[i + m] = s - f;
		f = s;
	}
	a[m - 1] = 100000000000;

	cin >> f;
	for (int i = 0; i < m - 1; i++)
	{
		cin >> s;
		a[i] = s - f;
		f = s;
	}
	n--;

	vector<int> p = prefix(n, m);

	long long res = 0;
	for (int i = m; i < n + m; i++)
	{
		if (p[i] == m - 1)
		{
			res++;
		}
	}
	cout << res;
	return 0;
}


#pragma comment(linker,"/STACK:102400000,102400000")
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<cstdio>
#include<queue>
#include<map>
#include<set>
#include<time.h>
#include<cstdlib>
#include<list>
#include<cstring>
#include<iterator>
#include<fstream>
#include<sstream>
using namespace std;
#define inf 1888888888
#define PI acos(-1.0)
#define FIR 1,n,1
#define LEFT l,mid,dq<<1
#define RIGHT mid+1,r,dq<<1|1
#define L (dq<<1)
#define R (dq<<1|1)
#define DQ l,r,dq
#define MID (l+r)>>1
#define LL __int64
template<class _T> inline _T low(_T n){return n&(-n);}
template<class _T> inline void swapp(_T &x,_T &y){_T t;t=x,x=y,y=t;}
template<class _T> inline _T minn(_T i,_T j){return i>j?j:i;}
template<class _T> inline _T maxx(_T i,_T j){return i>j?i:j;}
template<class _T> inline _T gcd(_T b,_T c){return b&&c?(c?gcd(c,b%c):b):b|c;}
template<class _T> inline _T abss(_T b){return b>0?b:-b;}
int n,m;
void get_nextval(const int *T, int next[])
{
       int j = 0, k = -1;
       next[0] = -1;
       while ( j<m-1 )
       {
              if (k == -1 || T[j] == T[k])
              {
                     ++j; ++k;
                     if (T[j]!=T[k])
                            next[j] = k;
                     else
                            next[j] = next[k];
              }
              else
                     k = next[k];
       }
}
const int N=200005;
int init[N],nex[N];
int str[N],c[N];
int main(){
	int i,j,s=0;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++)
		scanf("%d",&init[i]);
	for(i=0;i<n-1;i++)
		c[i]=init[i+1]-init[i];
	for(i=0;i<m;i++)
		scanf("%d",&init[i]);
	for(i=0;i<m-1;i++)
		str[i]=init[i+1]-init[i];
	str[m-1]=-inf;
	if(m==1){printf("%d\n",n);return 0;}
	get_nextval(str,nex);
	i=0;j=0;
	while(i<n-1){
		if(j==-1){
			i++;j++;
		}
		else if(c[i]==str[j]){
			i++;j++;
		}
		else
			j=nex[j];
		if(j==m-1)
			s++;
	}
	printf("%d\n",s);
	return 0;
}


#pragma comment(linker,"/STACK:102400000,102400000")
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<cstdio>
#include<queue>
#include<map>
#include<set>
#include<time.h>
#include<cstdlib>
#include<list>
#include<cstring>
#include<iterator>
#include<fstream>
#include<sstream>
using namespace std;
#define inf (1ll<<50)
#define PI acos(-1.0)
#define FIR 1,n,1
#define LEFT l,mid,dq<<1
#define RIGHT mid+1,r,dq<<1|1
#define L (dq<<1)
#define R (dq<<1|1)
#define DQ l,r,dq
#define MID (l+r)>>1
#define LL __int64
template<class _T> inline _T low(_T n){return n&(-n);}
template<class _T> inline void swapp(_T &x,_T &y){_T t;t=x,x=y,y=t;}
template<class _T> inline _T minn(_T i,_T j){return i>j?j:i;}
template<class _T> inline _T maxx(_T i,_T j){return i>j?i:j;}
template<class _T> inline _T gcd(_T b,_T c){return b&&c?(c?gcd(c,b%c):b):b|c;}
template<class _T> inline _T abss(_T b){return b>0?b:-b;}
int n,m;
void get_nextval(const int *T, int next[])
{
       int j = 0, k = -1;
       next[0] = -1;
       while ( j<m-1 )
       {
              if (k == -1 || T[j] == T[k])
              {
                     ++j; ++k;
                     if (T[j]!=T[k])
                            next[j] = k;
                     else
                            next[j] = next[k];
              }
              else
                     k = next[k];
       }
}
const int N=200005;
int init[N],nex[N];
int str[N],c[N];
int main(){
	int i,j,s=0;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++)
		scanf("%d",&init[i]);
	for(i=0;i<n-1;i++)
		c[i]=init[i+1]-init[i];
	for(i=0;i<m;i++)
		scanf("%d",&init[i]);
	for(i=0;i<m-1;i++)
		str[i]=init[i+1]-init[i];
	if(m==1){printf("%d\n",n);return 0;}
	get_nextval(str,nex);
	i=0;j=0;
	while(i<n-1){
		if(j==-1){
			i++;j++;
		}
		else if(j==m-2){
			s++;
			j=nex[j];
		}
		else if(c[i]==str[j]){
			i++;j++;
		}
		else
			j=nex[j];
	}
	printf("%d\n",s);
	return 0;
}


#pragma comment(linker,"/STACK:102400000,102400000")
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<cstdio>
#include<queue>
#include<map>
#include<set>
#include<time.h>
#include<cstdlib>
#include<list>
#include<cstring>
#include<iterator>
#include<fstream>
#include<sstream>
using namespace std;
#define inf (1ll<<50)
#define PI acos(-1.0)
#define FIR 1,n,1
#define LEFT l,mid,dq<<1
#define RIGHT mid+1,r,dq<<1|1
#define L (dq<<1)
#define R (dq<<1|1)
#define DQ l,r,dq
#define MID (l+r)>>1
#define LL __int64
template<class _T> inline _T low(_T n){return n&(-n);}
template<class _T> inline void swapp(_T &x,_T &y){_T t;t=x,x=y,y=t;}
template<class _T> inline _T minn(_T i,_T j){return i>j?j:i;}
template<class _T> inline _T maxx(_T i,_T j){return i>j?i:j;}
template<class _T> inline _T gcd(_T b,_T c){return b&&c?(c?gcd(c,b%c):b):b|c;}
template<class _T> inline _T abss(_T b){return b>0?b:-b;}
int n,m;
void get_nextval(const int *T, int next[])
{
       int j = 0, k = -1;
       next[0] = -1;
       while ( j<m-1 )
       {
              if (k == -1 || T[j] == T[k])
              {
                     ++j; ++k;
                     if (T[j]!=T[k])
                            next[j] = k;
                     else
                            next[j] = next[k];
              }
              else
                     k = next[k];
       }
}
const int N=200005;
int init[N],nex[N];
int str[N],c[N];
int main(){
	int i,j,s=0;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++)
		scanf("%d",&init[i]);
	for(i=0;i<n-1;i++)
		c[i]=init[i+1]-init[i];
	for(i=0;i<m;i++)
		scanf("%d",&init[i]);
	for(i=0;i<m-1;i++)
		str[i]=init[i+1]-init[i];
	get_nextval(str,nex);
	i=0;j=0;
	while(i<n-1){
		if(j==-1){
			i++;j++;
		}
		else if(j==m-2){
			s++;
			j=nex[j];
		}
		else if(c[i]==str[j]){
			i++;j++;
		}
		else
			j=nex[j];
	}
	printf("%d\n",s);
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <stdio.h>
#include <math.h>
#include <string>
#include <vector>
#include <time.h>
#include <stack>
#include <queue>
#include <set>
#include <map>

using namespace std;

vector<int> z_function (vector<int> s) {
    int n = (int) s.size();
    vector<int> z (n);
    for (int i=1, l=0, r=0; i<n; ++i) {
        if (i <= r)
            z[i] = min (r-i+1, z[i-l]);
        while (i+z[i] < n && s[z[i]] == s[i+z[i]])
            ++z[i];
        if (i+z[i]-1 > r)
            l = i,  r = i+z[i]-1;
    }
    return z;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen ( "input.txt", "r", stdin );
#endif

    int n, w;

    scanf ( "%d%d", &n, &w );

    if ( w > n )
    {
        cout << 0;
        return 0;
    }
    else if ( w == 1 )
    {
        cout << n;
        return 0;
    }

    vector<int> A(n), B(w);
    vector<int> da(n - 1), db(w - 1);

    for ( int i = 0; i < n; i++ ) scanf ( "%d", &A[i] );
    for ( int i = 0; i < w; i++ ) scanf ( "%d", &B[i] );

    for ( int i = 0; i < n - 1; i++ ) da[i] = A[i+1] - A[i];
    for ( int i = 0; i < w - 1; i++ ) db[i] = B[i+1] - B[i];

    vector<int> as;
    as = db;
    as.push_back(2e9+100);
    as.insert(as.end(), da.begin(), da.end());

    vector<int> xs = z_function(as);

    int ans =  0;

    for ( int i = w; i < xs.size(); i++ )
        ans += xs[i] == w - 1;

    cout << ans;

    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <stdio.h>
#include <math.h>
#include <string>
#include <vector>
#include <time.h>
#include <stack>
#include <queue>
#include <set>
#include <map>

using namespace std;

vector<int> z_function (vector<int> s) {
    int n = (int) s.size();
    vector<int> z (n);
    for (int i=1, l=0, r=0; i<n; ++i) {
        if (i <= r)
            z[i] = min (r-i+1, z[i-l]);
        while (i+z[i] < n && s[z[i]] == s[i+z[i]])
            ++z[i];
        if (i+z[i]-1 > r)
            l = i,  r = i+z[i]-1;
    }
    return z;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen ( "input.txt", "r", stdin );
#endif

    int n, w;

    scanf ( "%d%d", &n, &w );

    if ( w > n )
    {
        cout << 0;
        return 0;
    }

    vector<int> A(n), B(w);
    vector<int> da(n - 1), db(w - 1);

    for ( int i = 0; i < n; i++ ) scanf ( "%d", &A[i] );
    for ( int i = 0; i < w; i++ ) scanf ( "%d", &B[i] );

    for ( int i = 0; i < n - 1; i++ ) da[i] = A[i+1] - A[i];
    for ( int i = 0; i < w - 1; i++ ) db[i] = B[i+1] - B[i];

    vector<int> as;
    as = db;
    as.push_back(2e9+100);
    as.insert(as.end(), da.begin(), da.end());

    vector<int> xs = z_function(as);

    int ans =  0;

    for ( int i = w + 1; i < xs.size(); i++ )
        ans += xs[i] == w - 1;

    cout << ans;

    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <stdio.h>
#include <math.h>
#include <string>
#include <vector>
#include <time.h>
#include <stack>
#include <queue>
#include <set>
#include <map>

using namespace std;

vector<int> z_function (vector<int> s) {
    int n = (int) s.size();
    vector<int> z (n);
    for (int i=1, l=0, r=0; i<n; ++i) {
        if (i <= r)
            z[i] = min (r-i+1, z[i-l]);
        while (i+z[i] < n && s[z[i]] == s[i+z[i]])
            ++z[i];
        if (i+z[i]-1 > r)
            l = i,  r = i+z[i]-1;
    }
    return z;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen ( "input.txt", "r", stdin );
#endif

    int n, w;

    scanf ( "%d%d", &n, &w );

    if ( w > n )
    {
        cout << 0;
        return 0;
    }

    if ( w == 1 )
    {
        cout << n;
        return 0;
    }

    vector<int> A(n), B(w);
    vector<int> da(n - 1), db(w - 1);

    for ( int i = 0; i < n; i++ ) scanf ( "%d", &A[i] );
    for ( int i = 0; i < w; i++ ) scanf ( "%d", &B[i] );

    for ( int i = 0; i < n - 1; i++ ) da[i] = A[i+1] - A[i];
    for ( int i = 0; i < w - 1; i++ ) db[i] = B[i+1] - B[i];

    vector<int> as;
    as = db;
    as.push_back(2e9+100);
    as.insert(as.end(), da.begin(), da.end());

    vector<int> xs = z_function(as);

    int ans =  0;

    for ( int i = w + 1; i < xs.size(); i++ )
        ans += xs[i] == w - 1;

    cout << ans;

    return 0;
}


// In the Name of Allah
// AD13
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef unsigned long long  ull;
typedef pair <int, int> pii;
const double eps = 1e-14; // 15 is also used!
const int INF = 2147483647;
//#define For(i, a, b) for (int i = (a); i < (b); i++)
#define debug(x) { cerr << #x << " = _" << (x) << "_" << endl; }
void Error(string err) { cout << err; cerr << err; while(1); }
/*-------------------------------------------------------------------------------------*/

const int SZ = 212345;
int n, w;
int a[SZ], b[SZ],  t[SZ];

/*_____________________________________________________________________________________*/

int main () {
	//freopen("a.in", "r", stdin); 	freopen("a.out", "w", stdout);

	cin >> n >> w;
	for (int i=0; i<n; i++) cin >> a[i];
	for (int i=0; i<w; i++) cin >> b[i];
	if (n < w) {
		cout << 0 << endl;
		return 0;
	}
	if (w == 1) {
		cout << n << endl;
		return 0;
	}

	n--;
	for (int i=0; i<n; i++) a[i] = a[i+1]-a[i];
	w--;
	for (int i=0; i<w; i++) b[i] = b[i+1]-b[i];

	int next, cnt = 0;

	// table
	t[0] = -1; t[1] = 0;
	int pos = 2, cnd = 0;
	while (pos < w) {
		if (b[pos-1] == b[cnt]) {
			cnd++;
			t[pos] = cnd;
			pos++;
		}
		else if (cnd > 0) cnd = t[cnd];
		else t[pos++] = 0;
	}

	for (int m=0, i=0; m+i < n; ) {
		if (a[m+i] == b[i]) {
			if (i == w-1) {
				cnt++;
			}
			else {
				i++;
				continue;
			}
		}

		if (t[i] > -1) {
			m = m + i - t[i];
			i = t[i];
		}
		else {
			i = 0;
			m++;
		}
	}
	/*for (int i=0; i+w <= n; i=max(i+1, next)) {
		next = 0;
		bool good = true;
		if (a[i] != b[0]) continue;
		for (int j=1; j<w; j++) {
			if (a[i+j] != b[j]) {
				good = false;
				break;
			}
			if (a[i+j] == b[0] && next == 0) next = i+j;
		}
		if (good) cnt++;
	}*/

	cout << cnt << endl;

	return 0;
}
/*
13 5
2 4 5 5 4 3 2 2 2 3 3 2 1
3 4 4 3 2

5 1
1 2 1 3 2
1

5 2
1 2 1 3 2
2 3

2
5
1
*/


// In the Name of Allah
// AD13
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef unsigned long long  ull;
typedef pair <int, int> pii;
const double eps = 1e-14; // 15 is also used!
const int INF = 2147483647;
//#define For(i, a, b) for (int i = (a); i < (b); i++)
#define debug(x) { cerr << #x << " = _" << (x) << "_" << endl; }
void Error(string err) { cout << err; cerr << err; while(1); }
/*-------------------------------------------------------------------------------------*/

void f () {

}

const int SZ = 212345;
ll n, w, cnt = 0;
ll nn[SZ], ww[SZ];
ll a[SZ], b[SZ], bhsh[SZ];

/*_____________________________________________________________________________________*/

int main () {
	//freopen("a.in", "r", stdin); 	freopen("a.out", "w", stdout);

	cin >> n >> w;
	for (int i=0; i<n; i++) cin >> nn[i];
	for (int i=0; i<w; i++) cin >> ww[i];
	if (n < w) {
		cout << cnt << endl;
		return 0;
	}
	if (w == 1) {
		cout << n << endl;
		return 0;
	}

	for (int i=1; i<n; i++)
		a[i-1] = nn[i]-nn[i-1];
	n--;
	for (int i=1; i<w; i++)
		b[i-1] = ww[i]-ww[i-1];
	w--;

	const ll hval = 10000007;
	bhsh[0] = a[0]*hval;
	for (int i=1; i<n; i++) {
		bhsh[i] = a[i]*hval + bhsh[i-1];
	}
	ll hsh = 0;
	for (int i=0; i<w; i++) hsh += b[i]*hval;

	for (int i=0; i+w <= n; i++) {
		ll x = 0;
		if (i > 0) x = bhsh[i-1];
		if (hsh != bhsh[i+w-1] - x) continue;
		if (a[i] != b[0]) continue;
		if(a[i+w-1] != b[w-1]) continue;

		bool good = true;
		//*
		for (int k=0; k<10; k++) {
			int test = rand()%w;
			if (b[test] != a[i+test]) good = false;
		}//*/
		if (good) cnt++;
		continue;

		for (int j=0; j<w; j++) {
			if (a[i+j] != b[j]) {
				good = false;
				break;
			}
		}
		if (good) cnt++;
	}

	cout << cnt << endl;

	return 0;
}
/*
13 5
2 4 5 5 4 3 2 2 2 3 3 2 1
3 4 4 3 2

5 1
1 2 1 3 2
1

5 2
1 2 1 3 2
2 3

2
5
1
*/


// In the Name of Allah
// AD13
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef unsigned long long  ull;
typedef pair <int, int> pii;
const double eps = 1e-14; // 15 is also used!
const int INF = 2147483647;
//#define For(i, a, b) for (int i = (a); i < (b); i++)
#define debug(x) { cerr << #x << " = _" << (x) << "_" << endl; }
void Error(string err) { cout << err; cerr << err; while(1); }
/*-------------------------------------------------------------------------------------*/

void f () {

}

const int SZ = 212345;
ll n, w, cnt = 0;
ll nn[SZ], ww[SZ];
ll a[SZ], b[SZ], bhsh[SZ];

/*_____________________________________________________________________________________*/

int main () {
	//freopen("a.in", "r", stdin); 	freopen("a.out", "w", stdout);

	cin >> n >> w;
	for (int i=0; i<n; i++) cin >> nn[i];
	for (int i=0; i<w; i++) cin >> ww[i];
	if (n < w) {
		cout << cnt << endl;
		return 0;
	}
	if (w == 1) {
		cout << n << endl;
		return 0;
	}

	for (int i=1; i<n; i++)
		a[i-1] = nn[i]-nn[i-1];
	n--;
	for (int i=1; i<w; i++)
		b[i-1] = ww[i]-ww[i-1];
	w--;

	const ll hval = 10000007;
	bhsh[0] = a[0]*hval;
	for (int i=1; i<n; i++) {
		bhsh[i] = a[i]*hval + bhsh[i-1];
	}
	ll hsh = 0;
	for (int i=0; i<w; i++) hsh += b[i]*hval;

	for (int i=0; i+w <= n; i++) {
		ll x = 0;
		if (i > 0) x = bhsh[i-1];
		if (hsh != bhsh[i+w-1] - x) continue;
		if (a[i] != b[0]) continue;
		if(a[i+w-1] != b[w-1]) continue;

		bool good = true;
		//*
		for (int k=0; k<100; k++) {
			int test = rand()%w;
			if (b[test] != a[i+test]) good = false;
		}//*/
		if (good) cnt++;
		continue;

		for (int j=0; j<w; j++) {
			if (a[i+j] != b[j]) {
				good = false;
				break;
			}
		}
		if (good) cnt++;
	}

	cout << cnt << endl;

	return 0;
}
/*
13 5
2 4 5 5 4 3 2 2 2 3 3 2 1
3 4 4 3 2

5 1
1 2 1 3 2
1

5 2
1 2 1 3 2
2 3

2
5
1
*/


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;cin>>t;
    while(t--)
    {
        vector<int>v1;
        long long int i,j,n,p,k;cin>>n>>p>>k;
        for(i=0;i<n;i++)
        {
            long long int temp;cin>>temp;
            v1.push_back(temp);
        }
        long long int price = 0;
        long long int ans = 0;
        sort(v1.begin(),v1.end());
        for(i=0;i<k;i++)
        {
            long long int count = 0 , price = 0;
            if(v1[i]>p) break;
            for(j=i;j<n;j+=2)
            {
                if(price + v1[j]<=p)
                {
                    count = j+1;
                    price += v1[j];
                }
                else
                {
                    break;
                }
            }
            ans = max(ans,count);
        }
        cout<<ans<<endl;
    }
}