import sys

import numpy as np

from collections import defaultdict



sr = lambda: sys.stdin.readline().rstrip()

ir = lambda: int(sr())

lr = lambda: list(map(int, sr().split()))



N, K = lr()

A = np.array([0] + lr())

A = (A-1) % K

Acum = A.cumsum() % K

counter = defaultdict(int)

answer = 0

for i, x in enumerate(Acum):

    answer += counter[x]

    counter[x] += 1

    if i >= K-1:

        counter[Acum[i-(K-1)]] -= 1



print(answer)

import sys

import numpy as np

from collections import defaultdict



sr = lambda: sys.stdin.readline().rstrip()

ir = lambda: int(sr())

lr = lambda: list(map(int, sr().split()))



N, K = lr()

A = np.array([1] + lr())

A = (A-1) % K

N += 1

# 累積和が同じになっている箇所に注目、要素がK-1離れている組み合わせは無理

Acum = (A.cumsum() % K).tolist()

answer = 0

dic = defaultdict(int)

for i, cur in enumerate(Acum): 

    answer += dic[cur]

    dic[cur] += 1

    if i >= K-1:

        vanish = Acum[i-(K-1)]

        dic[vanish] -= 1



print(answer)

# 10
import sys
import numpy as np
from collections import defaultdict

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, K = lr()
A = np.array([0] + lr())
A = (A - 1) % K
Acum = A.cumsum() % K
counter = defaultdict(int)
answer = 0
for i, x in enumerate(Acum):
    answer += counter[x]
    counter[x] += 1
    if i >= K - 1:
        counter[Acum[i - (K - 1)]] -= 1
print(answer)

import sys
import numpy as np
from collections import defaultdict

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, K = lr()
A = np.array([1] + lr())
A = (A - 1) % K
N += 1
# 累積和が同じになっている箇所に注目、要素がK-1離れている組み合わせは無理
Acum = (A.cumsum() % K).tolist()
answer = 0
dic = defaultdict(int)
for i, cur in enumerate(Acum):
    answer += dic[cur]
    dic[cur] += 1
    if i >= K - 1:
        vanish = Acum[i - (K - 1)]
        dic[vanish] -= 1
print(answer)
# 10

-A = np.array([0] + lr()) +A = np.array([1] + lr()) -Acum = A.cumsum() % K -counter = defaultdict(int) +N += 1 +# 累積和が同じになっている箇所に注目、要素がK-1離れている組み合わせは無理 +Acum = (A.cumsum() % K).tolist() -for i, x in enumerate(Acum): -    answer += counter[x] -    counter[x] += 1 +dic = defaultdict(int) +for i, cur in enumerate(Acum): +    answer += dic[cur] +    dic[cur] += 1 -        counter[Acum[i - (K - 1)]] -= 1 +        vanish = Acum[i - (K - 1)] +        dic[vanish] -= 1 +# 10