#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

  int n, k; cin >> n >> k;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];

  vector<int> imos(n+1, 0);
  for(int i = 0; i < n; i++){
    imos[i+1] = (imos[i] + a[i] - 1) % k;
  }

  int ans = 0;
  map<int, int> mp;
  for(int i = 0; i <= n; i++){
    if(i - k >= 0) mp[imos[i - k]]--;
    ans += mp[imos[i]];
    mp[imos[i]]++;
  }
  cout << ans << endl;

  return 0;
}
