from collections import defaultdict

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

A = [(int(c)%K)-1 for c in input().split()]

B = [0]

for c in A:

  B += [B[-1]+c]

dic = defaultdict(int)

ldic = defaultdict(int)

for i in range(min(K,N+1)):

  c = B[i]

  dic[c%K] += 1

ans = 0

#print(dic)

for i in range(1,N+1):

  x = B[i-1]

  ldic[x%K] += 1

  ans += dic[x%K]-ldic[x%K]

  if K+i-1<=N:

    dic[B[K+i-1]%K] += 1

  """

  print('###############')

  print(i,x, ans)

  print(dic)

  print(ldic)

  """

print(ans)

from itertools import accumulate

from collections import Counter

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

A = [a-1 for a in A]

B = [b%K for b in accumulate(A)]

if K>N:

  Cnt = Counter(B)

  ans = Cnt[0]+sum(v*(v-1)//2 for v in list(Cnt.values()))

else:

  Cnt = Counter(B[:K])

  ans = Cnt[0]+sum(v*(v-1)//2 for v in list(Cnt.values()))

  if B[K-1]==0:

    ans -= 1

  for i in range(N-K):

    Cnt[B[i]] -= 1

    ans += Cnt[B[i+K]]

    Cnt[B[i+K]] += 1

print(ans)
from collections import defaultdict

N, K = list(map(int, input().split()))
A = [(int(c) % K) - 1 for c in input().split()]
B = [0]
for c in A:
    B += [B[-1] + c]
dic = defaultdict(int)
ldic = defaultdict(int)
for i in range(min(K, N + 1)):
    c = B[i]
    dic[c % K] += 1
ans = 0
# print(dic)
for i in range(1, N + 1):
    x = B[i - 1]
    ldic[x % K] += 1
    ans += dic[x % K] - ldic[x % K]
    if K + i - 1 <= N:
        dic[B[K + i - 1] % K] += 1
    """
  print('###############')
  print(i,x, ans)
  print(dic)
  print(ldic)
  """
print(ans)

from itertools import accumulate
from collections import Counter

N, K, *A = list(map(int, open(0).read().split()))
A = [a - 1 for a in A]
B = [b % K for b in accumulate(A)]
if K > N:
    Cnt = Counter(B)
    ans = Cnt[0] + sum(v * (v - 1) // 2 for v in list(Cnt.values()))
else:
    Cnt = Counter(B[:K])
    ans = Cnt[0] + sum(v * (v - 1) // 2 for v in list(Cnt.values()))
    if B[K - 1] == 0:
        ans -= 1
    for i in range(N - K):
        Cnt[B[i]] -= 1
        ans += Cnt[B[i + K]]
        Cnt[B[i + K]] += 1
print(ans)

-from collections import defaultdict +from itertools import accumulate +from collections import Counter -N, K = list(map(int, input().split())) -A = [(int(c) % K) - 1 for c in input().split()] -B = [0] -for c in A: -    B += [B[-1] + c] -dic = defaultdict(int) -ldic = defaultdict(int) -for i in range(min(K, N + 1)): -    c = B[i] -    dic[c % K] += 1 -ans = 0 -# print(dic) -for i in range(1, N + 1): -    x = B[i - 1] -    ldic[x % K] += 1 -    ans += dic[x % K] - ldic[x % K] -    if K + i - 1 <= N: -        dic[B[K + i - 1] % K] += 1 -    """ -  print('###############') -  print(i,x, ans) -  print(dic) -  print(ldic) -  """ +N, K, *A = list(map(int, open(0).read().split())) +A = [a - 1 for a in A] +B = [b % K for b in accumulate(A)] +if K > N: +    Cnt = Counter(B) +    ans = Cnt[0] + sum(v * (v - 1) // 2 for v in list(Cnt.values())) +else: +    Cnt = Counter(B[:K]) +    ans = Cnt[0] + sum(v * (v - 1) // 2 for v in list(Cnt.values())) +    if B[K - 1] == 0: +        ans -= 1 +    for i in range(N - K): +        Cnt[B[i]] -= 1 +        ans += Cnt[B[i + K]] +        Cnt[B[i + K]] += 1