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)

56ad3ef5a1e191d5fe3bb051b31a69cb9044d632
<mask token>

<mask token>
for i, x in enumerate(Acum):
    answer += counter[x]
    counter[x] += 1
    if i >= K - 1:
        counter[Acum[i - (K - 1)]] -= 1
print(answer)

<mask token>
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([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)
