#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a[1000000];
map<ll,ll> num;
ll add[1000000];
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n,k;
    cin>>n>>k;
    num[0]=1;
    ll ret=0;
    for (int i=1;i<=n;i++) {
        if (i>=k)num[add[i-k]]--;
        cin>>a[i];
        a[i]+=a[i-1];
        ll have = ((a[i]-i)%k+k)%k;
        add[i] = have;
        ret+=num[have];
        num[((a[i]-i)%k+k)%k]++;
    }
    cout<<ret<<endl;
}
