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

typedef long long ll;

ll ans;
ll sum[200005];
map<ll,int> num;

int main() {
  ll n,k;
  cin >> n >> k;
  for(int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    a--;
    sum[i+1] = (sum[i] + a) % k;
  }

  num[0]++;
  
  for(int i = 1; i <= n; i++) {
    if(i - k >= 0) num[sum[i-k]]--;
    ans += num[sum[i]]++;
   
  }

  cout << ans << endl;
}
  
    
  
