from bisect import bisect_right



N, K = list(map(int, input().split()))

A = list(map(int, input().split()))



for i in range(N):

    A[i] = (A[i]-1)%K



B = [0]

for a in A:

    B.append((B[-1]+a)%K)



dic = {}

for i, b in enumerate(B):

    if not b in list(dic.keys()):

        dic[b] = [i]

    else:

        dic[b].append(i)



ans = 0

for L in list(dic.values()):

    for i in range(len(L)):

        #print(L, i)

        j = bisect_right(L, L[i]+K-1)

        #print(j)

        ans += j-i-1

print(ans)
import sys

input = sys.stdin.readline

from collections import deque



N, K = list(map(int, input().split()))

A = list(map(int, input().split()))



B = [0]

for a in A:

    b = (B[-1] + (a-1)) % K

    B.append(b)



ans = 0

dic = {}

for i, b in enumerate(B):

    if b in dic:

        dic[b].append(i)

    else:

        dic[b] = deque()

        dic[b].append(i)

    

    while len(dic[b]) > 0 and dic[b][0] <= i - K:

        dic[b].popleft()

    ans += len(dic[b])-1

    



print(ans)
from bisect import bisect_right

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
for i in range(N):
    A[i] = (A[i] - 1) % K
B = [0]
for a in A:
    B.append((B[-1] + a) % K)
dic = {}
for i, b in enumerate(B):
    if not b in list(dic.keys()):
        dic[b] = [i]
    else:
        dic[b].append(i)
ans = 0
for L in list(dic.values()):
    for i in range(len(L)):
        # print(L, i)
        j = bisect_right(L, L[i] + K - 1)
        # print(j)
        ans += j - i - 1
print(ans)

import sys

input = sys.stdin.readline
from collections import deque

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = [0]
for a in A:
    b = (B[-1] + (a - 1)) % K
    B.append(b)
ans = 0
dic = {}
for i, b in enumerate(B):
    if b in dic:
        dic[b].append(i)
    else:
        dic[b] = deque()
        dic[b].append(i)
    while len(dic[b]) > 0 and dic[b][0] <= i - K:
        dic[b].popleft()
    ans += len(dic[b]) - 1
print(ans)

-from bisect import bisect_right +import sys + +input = sys.stdin.readline +from collections import deque -for i in range(N): -    A[i] = (A[i] - 1) % K -    B.append((B[-1] + a) % K) +    b = (B[-1] + (a - 1)) % K +    B.append(b) +ans = 0 -    if not b in list(dic.keys()): -        dic[b] = [i] +    if b in dic: +        dic[b].append(i) +        dic[b] = deque() -ans = 0 -for L in list(dic.values()): -    for i in range(len(L)): -        # print(L, i) -        j = bisect_right(L, L[i] + K - 1) -        # print(j) -        ans += j - i - 1 +    while len(dic[b]) > 0 and dic[b][0] <= i - K: +        dic[b].popleft() +    ans += len(dic[b]) - 1