import sys

from collections import Counter

from itertools import accumulate

read = sys.stdin.read



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

a = list(accumulate([0] + A))

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





def cmb(x):

    return x * (x - 1) // 2





answer = 0

if N < K:

    for i in list(Counter(a).values()):

        answer += cmb(i)

else:

    dic = Counter(a[:K])

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

        answer += cmb(i)

    here = K

    for i, x in enumerate(a[K:]):

        dic[a[i]] -= 1

        answer += dic[x]

        dic[x] += 1



print(answer)
import sys

from collections import defaultdict

from itertools import accumulate

read = sys.stdin.read



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

a = list(accumulate([0] + A))

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



answer = 0

dic = defaultdict(int)



for i, x in enumerate(a):

    answer += dic[x]

    dic[x] += 1

    if i >= K - 1:

        dic[a[i - K + 1]] -= 1



print(answer)
import sys
from collections import Counter
from itertools import accumulate

read = sys.stdin.read
N, K, *A = list(map(int, read().split()))
a = list(accumulate([0] + A))
a = [(a[i] - i) % K for i in range(N + 1)]


def cmb(x):
    return x * (x - 1) // 2


answer = 0
if N < K:
    for i in list(Counter(a).values()):
        answer += cmb(i)
else:
    dic = Counter(a[:K])
    for i in list(dic.values()):
        answer += cmb(i)
    here = K
    for i, x in enumerate(a[K:]):
        dic[a[i]] -= 1
        answer += dic[x]
        dic[x] += 1
print(answer)

import sys
from collections import defaultdict
from itertools import accumulate

read = sys.stdin.read
N, K, *A = list(map(int, read().split()))
a = list(accumulate([0] + A))
a = [(a[i] - i) % K for i in range(N + 1)]
answer = 0
dic = defaultdict(int)
for i, x in enumerate(a):
    answer += dic[x]
    dic[x] += 1
    if i >= K - 1:
        dic[a[i - K + 1]] -= 1
print(answer)

-from collections import Counter +from collections import defaultdict - - -def cmb(x): -    return x * (x - 1) // 2 - - -if N < K: -    for i in list(Counter(a).values()): -        answer += cmb(i) -else: -    dic = Counter(a[:K]) -    for i in list(dic.values()): -        answer += cmb(i) -    here = K -    for i, x in enumerate(a[K:]): -        dic[a[i]] -= 1 -        answer += dic[x] -        dic[x] += 1 +dic = defaultdict(int) +for i, x in enumerate(a): +    answer += dic[x] +    dic[x] += 1 +    if i >= K - 1: +        dic[a[i - K + 1]] -= 1