#include "bits/stdc++.h"

using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  REP(i, n) cin >> v[i];
  vector<ll> a(n + 1);
  REP(i, n) a[i + 1] = a[i] + v[i];
  REP(i, n + 1) a[i] = (a[i] - i + k) % k;
  map<int, int> mp;
  mp[0]++;
  ll ans = 0;
  REP(i, n) {
    if (i >= k - 1) mp[a[i - k + 1]]--;
    ans += mp[a[i + 1]];
    mp[a[i + 1]]++;
  }
  cout << ans << endl;
}
