#include <bits/stdc++.h>
using namespace std;
void RI() {}
template <typename... T>
void RI(int& head, T&... tail) {
  scanf("%d", &head);
  RI(tail...);
}
template <typename T>
void _dump(const char* s, T&& head) {
  cerr << s << "=" << head << endl;
}
template <typename T, typename... Args>
void _dump(const char* s, T&& head, Args&&... tail) {
  int c = 0;
  while (*s != ',' || c != 0) {
    if (*s == '(' || *s == '[' || *s == '{') c++;
    if (*s == ')' || *s == ']' || *s == '}') c--;
    cerr << *s++;
  }
  cerr << "=" << head << ", ";
  _dump(s + 1, tail...);
}
template <typename A, typename B>
ostream& operator<<(ostream& s, const pair<A, B>& p) {
  return s << "(" << p.first << "," << p.second << ")";
}
template <typename Iter>
ostream& _out(ostream& s, Iter b, Iter e) {
  s << "[";
  for (auto it = b; it != e; it++) s << (it == b ? "" : " ") << *it;
  s << "]";
  return s;
}
template <typename T>
ostream& operator<<(ostream& s, const vector<T>& c) {
  return _out(s, begin(c), end(c));
}
template <typename T>
ostream& operator<<(ostream& s, const set<T>& c) {
  return _out(s, begin(c), end(c));
}
template <typename A, typename B>
ostream& operator<<(ostream& s, const map<A, B>& c) {
  return _out(s, begin(c), end(c));
}
const int MAX_N = 200010;
int n, k, a[MAX_N], s[MAX_N];
map<int, long long> me;
void input() {
  RI(n, k);
  for (int i = 0; i < (int)(n); i++) RI(a[i]);
}
void solve() {
  int ans = 0;
  s[0] = 0;
  for (int i = 0; i < (int)(n); i++) s[i + 1] = (s[i] + a[i] - 1) % k;
  for (int i = 0; i < (int)(n + 1); i++) {
    if (i >= k) me[s[i - k]]--;
    ans += me[s[i]];
    me[s[i]]++;
  }
  printf("%d\n", ans);
}
int main(int argc, char* argv[]) {
  input();
  solve();
  return 0;
}
