#include<bits/stdc++.h>
#define int long long 
using namespace std;
const int maxn=200000;
map<int,int> buc;
int n,k;
int a[maxn+5];
int Sub(int x,int y)
{
	x-=y;
	if(x<0) x+=k;
	return x;
}
signed main()
{
	scanf("%lld%lld",&n,&k);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	for(int i=1;i<=n;i++) a[i]=(a[i-1]+a[i])%k;
	buc[Sub(a[0],0)]++;
	int now=0,ans=0;
	for(int i=1;i<=n;i++)
	{
		while(now<i-k+1) buc[Sub(a[now],now%k)]--,now++;
		ans+=buc[Sub(a[i],i%k)];
		buc[Sub(a[i],i%k)]++;
	}
	printf("%lld\n",ans);
	return 0;
}