from collections import defaultdict



N, K, *A = list(map(int, open(0).read().split()))



S = [0] * (N + 1)

for i in range(N):

    S[i + 1] = S[i] + A[i]



d = defaultdict(int)

ans = 0

for j in range(N + 1):

    v = (S[j] - j) % K

    ans += d[v]

    d[v] += 1

    if j >= K - 1:

        d[(S[j - K + 1] - (j - K + 1)) % K] -= 1

        

print(ans)

from collections import defaultdict



N, K, *A = list(map(int, open(0).read().split()))



x = [0] * (N + 1)

for i in range(N):

    x[i + 1] = x[i] + A[i]

    

y = [(x[i] - i) % K for i in range(N + 1)]



ctr = defaultdict(int)

ans = 0

for j in range(N + 1):

    ans += ctr[y[j]]

    ctr[y[j]] += 1

    if j - K + 1 >= 0:

        ctr[y[j - K + 1]] -= 1

print(ans)

from collections import defaultdict

N, K, *A = list(map(int, open(0).read().split()))
S = [0] * (N + 1)
for i in range(N):
    S[i + 1] = S[i] + A[i]
d = defaultdict(int)
ans = 0
for j in range(N + 1):
    v = (S[j] - j) % K
    ans += d[v]
    d[v] += 1
    if j >= K - 1:
        d[(S[j - K + 1] - (j - K + 1)) % K] -= 1
print(ans)

from collections import defaultdict

N, K, *A = list(map(int, open(0).read().split()))
x = [0] * (N + 1)
for i in range(N):
    x[i + 1] = x[i] + A[i]
y = [(x[i] - i) % K for i in range(N + 1)]
ctr = defaultdict(int)
ans = 0
for j in range(N + 1):
    ans += ctr[y[j]]
    ctr[y[j]] += 1
    if j - K + 1 >= 0:
        ctr[y[j - K + 1]] -= 1
print(ans)

-S = [0] * (N + 1) +x = [0] * (N + 1) -    S[i + 1] = S[i] + A[i] -d = defaultdict(int) +    x[i + 1] = x[i] + A[i] +y = [(x[i] - i) % K for i in range(N + 1)] +ctr = defaultdict(int) -    v = (S[j] - j) % K -    ans += d[v] -    d[v] += 1 -    if j >= K - 1: -        d[(S[j - K + 1] - (j - K + 1)) % K] -= 1 +    ans += ctr[y[j]] +    ctr[y[j]] += 1 +    if j - K + 1 >= 0: +        ctr[y[j - K + 1]] -= 1