#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

struct BitVector {
    static constexpr int wordsize = 64;
    static int popcount(uint64_t x) {
#ifdef __GNUC__
        return __builtin_popcountll(x);
#elif defined USE_SIMD
        return _mm_popcnt_u64(x);
#else
        x -= (x >> 1) & 0x5555555555555555ull; x = (x & 0x3333333333333333ull) + ((x >> 2) & 0x3333333333333333ull);
        return x = (x + (x >> 4)) & 0x0F0F0F0F0F0F0F0Full, (x * 0x0101010101010101ull) >> 56;
#endif
    }
    vector<uint64_t> dat; vector<int> rnk;
    /*constexpr */BitVector() : dat(), rnk() {}
    BitVector(int n_) : dat(n_ / wordsize + 1), rnk(n_ / wordsize + 1, 0) {}
    void set(int k) { dat[k / wordsize] |= 1ULL << k % wordsize; }
    void build() { for (int i = 1; i < rnk.size(); ++i) rnk[i] = rnk[i - 1] + popcount(dat[i - 1]); }
    int rank1(int k) const { return rnk[k / wordsize] + popcount(dat[k / wordsize] & ((1ULL << k % wordsize) - 1)); }
    int rank(bool v, int k) const { return v ? rank1(k) : k - rank1(k); }
    int select1(int a, int b, int k) const {
        int l = a / wordsize, r = (b + wordsize - 1) / wordsize, n = k + rnk[l]; for (; r - l > 1; ) { int m = (l + r) / 2; if (rnk[m] < n) l = m; else r = m; }
        int i = 0; k += rank(1, a); for (int c = rnk[l]; i < wordsize && c < k; ++i) c += dat[l] >> i & 1; return l * wordsize + i;
    }
    int select0(int a, int b, int k) const {
        int l = a / wordsize, r = (b + wordsize - 1) / wordsize, n = k + l * wordsize - rnk[l];
        for (; r - l > 1; ) { int m = (l + r) / 2; if (m * wordsize - rnk[m] < n) l = m; else r = m; }
        int i = 0; k += rank(0, a); for (int c = l * wordsize - rnk[l]; i < wordsize && c < k; ++i) c += !(dat[l] >> i & 1); return l * wordsize + i;
    }
    int select(int a, int b, bool v, int k) const { return v ? select1(a, b, k) : select0(a, b, k); }
};

template<typename T, int L>
struct WaveletMatrix {
    int n; array<BitVector, L> bv; array<int, L> zero; array<int, L + 1> buff_a, buff_b;
    void build(vector<T> v) {
        n = v.size(); vector<T> v0(n), v1(n);
        for (int i = 0; i < L; ++i) {
            bv[i] = BitVector(n); T bit = (T)1 << L - i - 1; int j0 = 0, j1 = 0;
            for (int j = 0; j < n; ++j) { if (v[j] & bit) v1[j1++] = v[j], bv[i].set(j); else v0[j0++] = v[j]; }
            bv[i].build(); swap(v, v0); copy(v1.begin(), v1.begin() + j1, v.begin() + j0); zero[i] = bv[i].rank(0, n);
        }
    }
    void search(int a, int b, T x) {
        buff_a[0] = a; buff_b[0] = b;
        for (int i = 0; i < L; ++i) {
            bool bit = x >> L - i - 1 & 1;
            buff_a[i + 1] = zero[i] * bit + bv[i].rank(bit, buff_a[i]);
            buff_b[i + 1] = zero[i] * bit + bv[i].rank(bit, buff_b[i]);
        }
    }
    int rank(int a, int b, T x) { search(a, b, x); return buff_b[L] - buff_a[L]; }
    int rankLessThan(int a, int b, T x) {
        search(a, b, x); int ret = 0;
        for (int i = 0; i < L; ++i) ret += x >> L - i - 1 & 1 ? (buff_b[i] - buff_a[i]) - (buff_b[i + 1] - buff_a[i + 1]) : 0;
        return ret;
    }
    int select(int k, T x) {
        search(0, n, x);
        for (int i = L - 1; i >= 0; --i) k = bv[i].select(buff_a[i], buff_b[i], x >> L - i - 1 & 1, k) - buff_a[i];
        return k;
    }
    int rangefreq(int a, int b, T lower, T upper) { return rankLessThan(a, b, upper) - rankLessThan(a, b, lower); }
    T quantile(int a, int b, int k) {
        T ret = 0;
        for (int i = 0; i < L; ++i) {
            int l = bv[i].rank(0, a), r = bv[i].rank(0, b);
            if (r - l > k) a = l, b = r; else a = zero[i] + a - l, b = zero[i] + b - r, k -= r - l, ret |= (T)1 << L - i - 1;
        }
        return ret;
    }
};

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    vector<int> sum(N + 1);
    rep(i, N) sum[i + 1] = (sum[i] + A[i] - 1) % K;
    WaveletMatrix<int, 31> wm;
    wm.build(sum);

    ll ans = 0;
    rep(i, N) {
        int target = (sum[i]) % K;
        int a = wm.rank(i + 1, min(N + 1, i + K), target);
        ans += a;
    }
    write(ans);
}

Measured memory_bytes: 5376