#include <vector>
#include <iostream>
#include <map>
using namespace std;

int main(){
  int N, K;
  cin >> N >> K;
  vector<long long> A(N+1);
  for(int i = 1; i <= N; ++i)
    cin >> A[i], A[i] +=  K-1+A[i-1], A[i] %= K;
  
  map<int,int> C;
  long long ans = 0;
  ++C[0];
  for(int i = 1; i <= N; ++i){
    A[i] %= K;
    if(i >= K) --C[A[i-K]];
    // cerr << i << " " << C[A[i]] << endl;
    ans += C[A[i]];
    ++C[A[i]];
  }
  cout << ans << endl;
}
