#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main()
{
  cin.tie(0);
  cin.sync_with_stdio(0);

  int n, k;
  cin >> n >> k;

  vector < int >a(n);
  for (auto & x:a)
    cin >> x;
  a.insert(a.begin(), 0);

  ll ans = 0;
  map < int, int >cnt;
  for (int i = 1; i <= n; ++i)
    a[i] = (a[i] + a[i - 1] - 1) % k;

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

  cout << ans;
}
