from collections import defaultdict

import bisect

n,k=list(map(int,input().split()))

a=[1]+list(map(int,input().split()))

d = defaultdict(list)

for i in range(n+1):

  a[i]-=1

d[a[0]%k].append(0)

for i in range(n):

  a[i + 1] += a[i]

  d[a[i+1]%k].append(i+1)

ans=0

for l in list(d.values()):

  for i, idx in enumerate(l):

    ans += bisect.bisect_left(l,idx+k)-i-1

print(ans)

from collections import defaultdict

from bisect import bisect_left

n, k = list(map(int, input().split()))

a = [0] + list(map(int, input().split()))

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

    a[i] -= 1

for i in range(n):

    a[i + 1] += a[i]

    a[i] %= k

a[i + 1] %= k

c = defaultdict(list)

for i in range(n + 1):

    c[a[i]].append(i)

ans = 0

for v in list(c.values()):

    for i in range(len(v)):

        ans += bisect_left(v, v[i] + k) - i - 1

print(ans)

from collections import defaultdict
import bisect

n, k = list(map(int, input().split()))
a = [1] + list(map(int, input().split()))
d = defaultdict(list)
for i in range(n + 1):
    a[i] -= 1
d[a[0] % k].append(0)
for i in range(n):
    a[i + 1] += a[i]
    d[a[i + 1] % k].append(i + 1)
ans = 0
for l in list(d.values()):
    for i, idx in enumerate(l):
        ans += bisect.bisect_left(l, idx + k) - i - 1
print(ans)

from collections import defaultdict
from bisect import bisect_left

n, k = list(map(int, input().split()))
a = [0] + list(map(int, input().split()))
for i in range(1, n + 1):
    a[i] -= 1
for i in range(n):
    a[i + 1] += a[i]
    a[i] %= k
a[i + 1] %= k
c = defaultdict(list)
for i in range(n + 1):
    c[a[i]].append(i)
ans = 0
for v in list(c.values()):
    for i in range(len(v)):
        ans += bisect_left(v, v[i] + k) - i - 1
print(ans)

-import bisect +from bisect import bisect_left -a = [1] + list(map(int, input().split())) -d = defaultdict(list) -for i in range(n + 1): +a = [0] + list(map(int, input().split())) +for i in range(1, n + 1): -d[a[0] % k].append(0) -    d[a[i + 1] % k].append(i + 1) +    a[i] %= k +a[i + 1] %= k +c = defaultdict(list) +for i in range(n + 1): +    c[a[i]].append(i) -for l in list(d.values()): -    for i, idx in enumerate(l): -        ans += bisect.bisect_left(l, idx + k) - i - 1 +for v in list(c.values()): +    for i in range(len(v)): +        ans += bisect_left(v, v[i] + k) - i - 1