#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) begin(x), end(x)
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
  #define debug(x) cout << #x " => " << (x) << endl
#else
  #define debug(x) 0
#endif
using lint = long long;
constexpr int MOD = (int)1e9 + 7;
constexpr double EPS = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

class VariableModInt {
  long long x;
  static long long &mod() {
    static long long mod_num = 1;
    return mod_num;
  }

  public:
  VariableModInt(const long long num = 0) : x(num % get_mod()) { if (x < 0) x += get_mod(); }
  bool operator==(const VariableModInt &r) const { return this->x == r.x; }
  bool operator!=(const VariableModInt &r) const { return this->x != r.x; }
  bool operator<(const VariableModInt &r) const { return this->x < r.x; }
  bool operator>(const VariableModInt &r) const { return this->x > r.x; }
  bool operator<=(const VariableModInt &r) const { return this->x <= r.x; }
  bool operator>=(const VariableModInt &r) const { return this->x >= r.x; }
  VariableModInt operator+(const VariableModInt &r) const { return VariableModInt(*this) += r; }
  VariableModInt operator-(const VariableModInt &r) const { return VariableModInt(*this) -= r; }
  VariableModInt operator*(const VariableModInt &r) const { return VariableModInt(*this) *= r; }
  VariableModInt operator/(const VariableModInt &r) const { return VariableModInt(*this) /= r; }
  friend VariableModInt operator+(const long long &l, const VariableModInt &r) { return VariableModInt(l) += r; }
  friend VariableModInt operator-(const long long &l, const VariableModInt &r) { return VariableModInt(l) -= r; }
  friend VariableModInt operator*(const long long &l, const VariableModInt &r) { return VariableModInt(l) *= r; }
  friend VariableModInt operator/(const long long &l, const VariableModInt &r) { return VariableModInt(l) /= r; }
  VariableModInt &operator++() { return *this += 1; }
  VariableModInt &operator--() { return *this -= 1; }
  VariableModInt &operator+=(const VariableModInt &r) {
    x += r.x;
    if (x >= get_mod()) x -= get_mod();
    return *this;
  }
  VariableModInt &operator-=(const VariableModInt &r) {
    if (x < r.x) x += get_mod();
    x -= r.x;
    return *this;
  }
  VariableModInt &operator*=(const VariableModInt &r) {
    x = x * r.x % get_mod();
    return *this;
  }
  VariableModInt &operator/=(VariableModInt r) {
    *this *= r.inverse();
    return *this;
  }
  VariableModInt inverse(void) const {
    long long a = x, b = get_mod(), u = 1, v = 0;
    while (b) {
      long long t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return VariableModInt(u);
  }
  VariableModInt pow(long long n) const {
    VariableModInt ret(1), mul(x);
    while (n) {
      if (n & 1) ret *= mul;
      mul *= mul;
      n  >>= 1;
    }
    return ret;
  }
  friend istream &operator>>(istream &is, VariableModInt &r) {
    long long n;
    is >> n;
    r = VariableModInt(n);
    return is;
  }
  friend ostream &operator<<(ostream &os, const VariableModInt &r) { return os << r.x; }
  static void set_mod(const long long mod_num) { mod() = mod_num; }
  static long long get_mod() { return mod(); }
  explicit operator int() const { return x; }
  explicit operator long long() const { return x; }
  explicit operator double() const { return x; }
};

using mint = VariableModInt;
int main(void) {
  int n, k;
  cin >> n >> k;
  mint::set_mod(k);
  vector<mint> a(n);
  rep (i, n) cin >> a[i];
  vector<mint> b = a;
  rep (i, n) (--b[i]);
  vector<mint> bsum(n + 1);
  rep (i, n) bsum[i + 1] = bsum[i] + b[i];
  unordered_map<int, int> um;
  lint ans = 0;
  rep (i, n) {
    ++um[(int)bsum[i]];
    if (i >= k - 1) --um[(int)bsum[i - k + 1]];
    ans += um[(int)bsum[i + 1]];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 13256