#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;
const ll LINF=1e18;

int main(){
    ll n,k;
    cin>>n>>k;
    ll a[n+1];
    a[0]=0;
    for(int i=0;i<n;i++){
        cin>>a[i+1];
        a[i+1]-=1;
        a[i+1]+=a[i];
        a[i+1]%=k;
    }
    ll ans=0;
    map<ll,int> mp;
    for(int i=0;i<=n;i++){
        if(i>=k)mp[a[i-k]]--;
        ans+=mp[a[i]];
        mp[a[i]]++;
    }
    cout<<ans<<endl;
}