#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main(){

int n, k;

cin>> n >> k;


vector <long long> a(n), sa(n+1);

sa[0] = 0;

map<long long, int> amap;
amap[0] = 1;
long long ans = 0;

for(int i=0; i<n; i++){
int tmp;
cin >> tmp;
a[i] = tmp - 1;
sa[i+1] = (sa[i] + a[i]) % k;
ans += amap[sa[i+1]];
amap[sa[i+1]] += 1;
if(i-k+2>=0) amap[sa[i-k+2]]--;
}
  
  
if(k==1) ans = 0;

cout << ans << endl;
}
