import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto K = s[1].to!long;
    auto A = readln.split.map!(to!long).array;

    auto B = new long[](N+1);
    foreach (i; 0..N) B[i+1] = (B[i] + A[i]) % K;

    long ans = 0;
    long[long] cnt;
    auto C = new long[](N+1);

    foreach (i; 0..N+1) {
        long z = ((B[i] - i) % K + K) % K;
        if (i >= K) {
            cnt[C[i - K.to!int]] -= 1;
        }
        if (z in cnt) ans += cnt[z];
        cnt[z] += 1;
        C[i] = z;
    }

    ans.writeln;
}