You are given a sequence of N positive integers A_1, A_2, ..., A_N, and a positive integer K. Find the number of non-empty contiguous subsequences in A such that the remainder when dividing the sum of its elements by K is equal to the number of its elements. Two subsequences are considered different if they are taken from different positions, even if they are equal sequences.

Constraints:
- All values in input are integers.
- 1 <= N <= 2*10^5
- 1 <= K <= 10^9
- 1 <= A_i <= 10^9

Input:
The input is given in the format: N K
Followed by the sequence A_1, A_2, ..., A_N

Output:
Print the number of subsequences that satisfy the condition.

Sample Input 1:
5 4
1 4 2 3 5

Sample Output 1:
4
Four sequences satisfy the condition: (1), (4,2), (1,4,2), and (5).

Sample Input 2:
8 4
4 2 4 2 4 2 4 2

Sample Output 2:
7
(4,2) is counted four times, and (2,4) is counted three times.

Sample Input 3:
10 7
14 15 92 65 35 89 79 32 38 46

Sample Output 3:
8

# Buggy version:
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

acc = [0] * (N + 1)
for i in range(1, N + 1):
    acc[i] = acc[i - 1] + A[i - 1] - 1
    acc[i] %= K

mp = defaultdict(int)
ans = 0
for j in range(N + 1):
    ans += mp[acc[j]]
    mp[acc[j]] += 1
    if j >= K:
        mp[acc[j - K]] -= 1
print(ans)

# Fixed version:
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

acc = [0] * (N + 1)
for i in range(1, N + 1):
    acc[i] = acc[i - 1] + A[i - 1] - 1
    acc[i] %= K

mp = defaultdict(int)
ans = 0
q = deque([])
for j in range(N + 1):
    ans += mp[acc[j]]
    mp[acc[j]] += 1
    q.append(acc[j])
    if len(q) == K:
        mp[q[0]] -= 1
        q.popleft()
print(ans)

# Buggy version:
N,K=map(int,input().split())
A=list(map(int,input().split()))
DP=dict()
if K==1:
  print(0)
  exit()
DP[0]=1
P=0
Y=[0]*(N+1)
for i in range(N):
  Y[i+1]=(Y[i]+A[i]-1)%K
  P+=DP.get(Y[i+1],0)
  DP[Y[i+1]]=DP.get(Y[i+1],0)+1
  if i>=K-2:
    DP[Y[i-K+2]]-=1

# Fixed version:
N,K=map(int,input().split())
A=list(map(int,input().split()))
DP=dict()
if K==1:
  print(0)
  exit()
DP[0]=1
P=0
Y=[0]*(N+1)
for i in range(N):
  Y[i+1]=(Y[i]+A[i]-1)%K
  P+=DP.get(Y[i+1],0)
  DP[Y[i+1]]=DP.get(Y[i+1],0)+1
  if i>=K-2:
    DP[Y[i-K+2]]-=1
print(P)

# Buggy version:
n,k = map(int,input().split())
l = list(map(int,input().split()))
mo = [0]
mod = [0]
for i in range(n):
    a = l[i]%k
    mo.append((a+mo[-1])%k)
    mod.append((mo[-1]-(i+1))%k)
dic = {0:1}
le = 1
ans = 0
for i in range(1,n+1):
    if le < k:
        if mod[i] in dic:
            ans += dic[mod[i]]
            dic[mod[i]] += 1
        else:
            dic[mod[i]] = 1
        le += 1
    else:
        dic[mod[i-k]] -= 1
        if mod[i] in dic:
            ans += dic[mod[i]]
            dic[mod[i]] += 1
        else:
            dic[mod[i]] = 1
    print(dic)
print(ans)


# Fixed version:
n,k = map(int,input().split())
l = list(map(int,input().split()))
mo = [0]
mod = [0]
for i in range(n):
    a = l[i]%k
    mo.append((a+mo[-1])%k)
    mod.append((mo[-1]-(i+1))%k)
dic = {0:1}
le = 1
ans = 0
for i in range(1,n+1):
    if le < k:
        if mod[i] in dic:
            ans += dic[mod[i]]
            dic[mod[i]] += 1
        else:
            dic[mod[i]] = 1
        le += 1
    else:
        dic[mod[i-k]] -= 1
        if mod[i] in dic:
            ans += dic[mod[i]]
            dic[mod[i]] += 1
        else:
            dic[mod[i]] = 1
    
print(ans)

# Buggy version:
N, K = map(int,input().split())
A = list(map(int, input().split()))
S = [0]*(N+1)
dict = {}#最新K件の度数分布の管理

for i in range(N):
    S[i+1]=S[i]+A[i]
    S[i+1]-=i+1
    S[i+1]%=K

ans =0
for i in range(N+1):
    if dict.get(S[i],0):
        ans += dict[S[i]]
        print(i,ans)
    dict[S[i]]=dict.get(S[i],0)+1
    if i >=K:
        dict[S[i-K]]-=1

print(ans)

# Fixed version:
N, K = map(int,input().split())
A = list(map(int, input().split()))
S = [0]*(N+1)
S2 = [0]*(N+1)
dict = {}#最新K件の度数分布の管理

for i in range(N):
    S[i+1]=S[i]+A[i]
    S2[i+1] =(S[i+1]-i-1)%K

ans =0
for i in range(N+1):
    if dict.get(S2[i],0):
        ans += dict[S2[i]]
    dict[S2[i]]=dict.get(S2[i],0)+1
    if i >=K-1:
        dict[S2[i-(K-1)]]-=1

print(ans)

# Buggy version:
from collections import defaultdict as d
from itertools import accumulate as ac
n,k=map(int,input().split())
a=[0]+list(ac(list(map(int,input().split()))))
b=d(int)
c=0
for i in range(n+1):
    p=(a[i]-i)%k
    c+=b[p]
    b[p]+=1
    if i-k>=0:
        b[(a[i-k]-i+k)%k]-=1
print(c)

# Fixed version:
from collections import defaultdict as d
from itertools import accumulate as ac
n,k=map(int,input().split())
a=[0]+list(ac(list(map(int,input().split()))))
b=d(int)
c=0
for i in range(n+1):
    p=(a[i]-i)%k
    c+=b[p]
    b[p]+=1
    if i-k+1>=0:
        b[(a[i-k+1]-i+k-1)%k]-=1
print(c)

# Buggy version:
n, k = map(int, input().split())
a = [0] + list(map(int, input().split()))

n += 1
ans = 0
m = dict()
for x in a:
    m[x] = 0
temp = 0
b = []
for i in range(min(n, k)):
    temp = (temp + a[i]) % k
    c = (temp - (i % k) + k) % k
    b.append(c)
    m[c] += 1

for i in range(k, n):
    x = i % k
    m[b[x]] -= 1
    temp = (temp + a[i]) % k
    c = (temp - (i % k) + k) % k
    b[x] = c
    m[c] += 1

print(ans)

# Fixed version:
n, k = map(int, input().split())
a = [0] + list(map(int, input().split()))

n += 1
ans = 0
m = dict()
temp = 0
b = []
for i in range(min(n, k)):
    temp = (temp + a[i]) % k
    c = (temp - (i % k) + k) % k
    b.append(c)
    if c in m.keys():
        ans += m[c]
        m[c] += 1
    else:
        m[c] = 1

for i in range(k, n):
    x = i % k
    m[b[x]] -= 1
    temp = (temp + a[i]) % k
    c = (temp - (i % k) + k) % k
    b[x] = c
    if c in m.keys():
        ans += m[c]
        m[c] += 1
    else:
        m[c] = 1

print(ans)

# Buggy version:
from collections import defaultdict as dd
N, K = map(int, input().split())
A = list(map(int, input().split()))
S = [0]
# 累積和
for i in range(N):
    S.append(S[-1] + A[i] - (i+1))
    S[-1] %= K
    
B = dd(int)  # ここで範囲内のS[i]-iの個数を数えていく。
cnt = 0
for j in range(1,N):
    if j > K:
        B[S[j - 1 - K]] -= 1
    B[S[j]] += 1
    cnt += B[(-S[j]) % K]
print(cnt)

# Fixed version:
from collections import defaultdict as dd
N, K = map(int, input().split())
A = list(map(int, input().split()))
S = [0]*(N+1)
# 累積和
for i in range(1, N + 1):
    S[i] = S[i - 1] + A[i - 1] - 1
    S[i] %= K
        
B = dd(int)  # ここで範囲内のS[i]-iの個数を数えていく。
cnt = 0
for j in range(1, N + 1):
    B[S[j - 1]] += 1
    if j - K >= 0:
        B[S[j - K]] -= 1
    cnt += B[S[j]]

print(cnt)

# Buggy version:
def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    
    ans = 0
    ruiseki = [0]
    d = defaultdict(int)
    d[0]=1
    for i in range(n):
        if i - k + 1>= 0:
            d[ruiseki[i - k+1]]-=1
        ruiseki.append((ruiseki[i] + a[i] - 1)%k)
        ans += d[ruiseki[i+1]]
        d[ruiseki[i + 1]] += 1
    print(ans)
 
 
if __name__ == '__main__':
    main()

# Fixed version:
from collections import defaultdict 
def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    
    ans = 0
    ruiseki = [0]
    d = defaultdict(int)
    d[0]=1
    for i in range(n):
        if i - k + 1>= 0:
            d[ruiseki[i - k+1]]-=1
        ruiseki.append((ruiseki[i] + a[i] - 1)%k)
        ans += d[ruiseki[i+1]]
        d[ruiseki[i + 1]] += 1
    print(ans)
 
 
if __name__ == '__main__':
    main()

# Buggy version:
from collections import defaultdict
N,K=map(int, input().split())
A=list(map(int,input().split()))
"""count=0
for l in range(N):
    if A[l]%K==1:
        count+=1
for l in range(N-1):
    sum=A[l]
    for r in range(l+1,N):
        sum+=A[r]
        if sum%K==r-l+1:
            count+=1
print(count)"""
cum=[0]*(N+1)
for i in range(N):
    cum[i+1]=(cum[i]+A[i]-1)%K
dic=defaultdict(int)
ans=0
for i in range(N+1):
    print(dic)
    ans+=dic[cum[i]]
    dic[cum[i]]+=1
    if i>K:
        dic[cum[i-(K-1)]]-=1
print(ans)


# Fixed version:
from collections import defaultdict
N,K=map(int, input().split())
A=list(map(int,input().split()))
"""count=0
for l in range(N):
    if A[l]%K==1:
        count+=1
for l in range(N-1):
    sum=A[l]
    for r in range(l+1,N):
        sum+=A[r]
        if sum%K==r-l+1:
            count+=1
print(count)"""
cum=[0]*(N+1)
for i in range(N):
    cum[i+1]=(cum[i]+A[i]-1)%K
dic=defaultdict(int)
ans=0
for i in range(N+1):
    ans+=dic[cum[i]]
    dic[cum[i]]+=1
    if i-(K-1)>=0:
        dic[cum[i-(K-1)]]-=1
print(ans)

# Buggy version:

n,k = map(int, input().split())
a = [0] + list(map(int, input().split()))
for i in range(n):
    a[i+1] = (a[i] + a[i+1]-1)%k
from collections import defaultdict

d=defaultdict(int)
d[0]=1
ans=0
for i in range(1,n+1):
    ans+=d[a[i]]
    d[a[i]]+=1
    if i>=k:
        d[a[i-k]]-=1
print(ans)

# Fixed version:
n,k=map(int,input().split())
a=[0]+list(map(int,input().split()))
for i in range(n):a[i+1]=(a[i+1]+a[i]-1)%k
from collections import defaultdict
d=defaultdict(int)
x=0
d[0]=1
for i in range(1,n+1):
  if i-k>=0:d[a[i-k]]-=1
  x+=d[a[i]]
  d[a[i]]+=1
print(x)

# Buggy version:
from collections import defaultdict
n, k = map(int, input().split())


a = list(map(lambda x: int(x) - 1, input().split()))
s = [0] * (n + 1)
for i in range(n):
	s[i + 1] = (s[i] + a[i]) % k

mp = defaultdict(int)

print(s)
ans = 0
for i in range(n + 1):
	ans += mp[s[i]]
	mp[s[i]] += 1
	if i >= k - 1:
		mp[s[i - k + 1]] -= 1
print(ans)


# Fixed version:
from collections import defaultdict

n, k = map(int, input().split())
a = list(map(lambda x: int(x)-1, input().split()))
s = [0] * (n+1)
for i in range(n):
    s[i+1] = s[i] + a[i]
s = [x % k for x in s]
d = defaultdict(int)
ans = 0

for i in range(n+1):
    j = i - k
    if j >= 0: d[s[j]] -= 1
    ans += d[s[i]]
    d[s[i]] += 1

print(ans)

# Buggy version:
n,k=map(int,input().split())
l=list(map(int,input().split()))
if k==1:
    print(n)
    exit()
nl=[]
for i in range(n):
    nl.append((l[i]-1)%k)
r=[0]*(n+1)
for i in range(n):
    r[i+1]=(r[i]+nl[i])%k
p=[]
for i in range(n+1):
    p.append([r[i],i])
p.sort()
s=0
e=0
ans=0
f=0
while e<n+1:
    if p[s][0]!=p[e][0]:
        s=e
        f=0
    else:
        if p[s][1]+k-2>=p[e][1]:
            f+=1
            e+=1
        else:
            ans+=f
            f-=1
            s+=1
print(ans)


# Fixed version:
n,k=map(int,input().split())
l=list(map(int,input().split()))
if k==1:
    print(0)
    exit()
nl=[]
for i in range(n):
    nl.append((l[i]-1)%k)
r=[0]*(n+1)
for i in range(n):
    r[i+1]=(r[i]+nl[i])%k
p=[]
for i in range(n+1):
    p.append([r[i],i])
p.sort()
s=0
e=0
ans=0
f=0
while e<n+1:
    if p[s][0]!=p[e][0]:
        ans+=f*(f-1)//2
        s=e
        f=0
    else:
        if p[s][1]+k-1>=p[e][1]:
            f+=1
            e+=1
        else:
            ans+=f-1
            f-=1
            s+=1
print(ans+f*(f-1)//2)

# Buggy version:
def examE():
    N, K = LI()
    A = LI()
    sumA = [0]*(N+1)
    for i in range(1,N):
        sumA[i] = sumA[i-1]+A[i-1]
    d = defaultdict(int)
    ans = 0
    #連想配列 先頭からの番号　余分な量
    que = deque()
    for i,a in enumerate(sumA):
        #K番目以降は一番左のやつ消していく
        if que and que[0][0] <= (i-K):
            d[que.popleft()[1]] -= 1
        cur = (a-i)%K
        ans +=d[cur]
        d[cur] +=1
        que.append((i,cur))
        print(que,d)
    print(ans)
    return

def examF():
    return

import sys,copy,bisect,itertools,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examE()

# Fixed version:
def examE():
    N, K = LI()
    A = LI()
    sumA = [0]*(N+1)
    for i in range(1,N+1):
        sumA[i] = sumA[i-1]+A[i-1]
    d = defaultdict(int)
    ans = 0
    #連想配列 先頭からの番号　余分な量
    que = deque()
    for i,a in enumerate(sumA):
        #K番目以降は一番左のやつ消していく
        if que and que[0][0] <= (i-K):
            d[que.popleft()[1]] -= 1
        cur = (a-i)%K
        ans +=d[cur]
        d[cur] +=1
        que.append((i,cur))
#        print(ans,que,d,a-i)
    print(ans)
    return

def examF():
    return

import sys,copy,bisect,itertools,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examE()

# Buggy version:
from collections import defaultdict
from itertools import accumulate
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

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


ans = 0
D = defaultdict(int)
for l in range(N+1):
    t = (A_acc[l]-l) % K
    ans += D[t]
    D[t] += 1


print(ans)


# Fixed version:
from collections import defaultdict
from itertools import accumulate
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

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


ans = 0
D = defaultdict(int)
for l in range(N+1):
    t = (A_acc[l]-l) % K
    if l>=K:
      r = (A_acc[l-K]-(l-K))
      D[r%K]-=1
    ans += D[t]
    D[t] += 1


print(ans)

# Buggy version:
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
import math
import time
#import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
#sys.setrecursionlimit(10**6)
input=lambda: sys.stdin.readline().rstrip()

show_flg=False
show_flg=True

n,k=LI()
a=LI()
b=[k-1]
for i in range(n):
    b.append((b[-1]+a[i])%k)
b=[(b[i]-i)%k for i in range(n+1)]
ans=0
dc=defaultdict(int)
show(a)
show(b)
for i in range(n+1):
    if i>=k:
        dc[b[i-k]]-=1
    ans+=dc[b[i]]
    #if dc[b[i]]>0:show(i,a[i],dc[b[i]],ans)
    #show(i,b[i],dc)
    dc[b[i]]+=1

print(ans)


# Fixed version:
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
import math
import time
#import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
#sys.setrecursionlimit(10**6)
input=lambda: sys.stdin.readline().rstrip()

show_flg=False
#show_flg=True

n,k=LI()
a=LI()
b=[k-1]
for i in range(n):
    b.append((b[-1]+a[i])%k)
b=[(b[i]-i)%k for i in range(n+1)]
ans=0
dc=defaultdict(int)
show(a)
show(b)
for i in range(n+1):
    if i>=k:
        dc[b[i-k]]-=1
    ans+=dc[b[i]]
    #if dc[b[i]]>0:show(i,a[i],dc[b[i]],ans)
    #show(i,b[i],dc)
    dc[b[i]]+=1

print(ans)

# Buggy version:
n,k=map(int,input().split())
if k==1:
    print(0)
    exit()
a=list(map(int,input().split()))
from itertools import accumulate
a=list(accumulate(a))
from collections import defaultdict

a=list(map(lambda x:x%k,a))
a=list(map(lambda x:x-1,a))
a=[0]+a
d=defaultdict(int)
d[0]=1
ans=0
for i in range(1,n+1):
    ans+=d[a[i]]
    d[a[i]]+=1
    if i>=k:
        d[a[i-k]]-=1
print(ans)

# Fixed version:
n,k=map(int,input().split())
a=list(map(int,input().split()))
a=list(map(lambda x:x-1 ,a))

if k==1:
    print(0)
    exit()
s=[0]
for i in range(n):
    s.append(s[-1]+a[i])
s=list(map(lambda x:x%k,s))
from collections import defaultdict
d=defaultdict(int)
d[0]=1
ans=0

for i in range(1,n+1):
    ans+=d[s[i]]
    d[s[i]]+=1
    if i>=k-1:
        d[s[i-k+1]]-=1
print(ans)

# Buggy version:
import numpy
N,K=map(int,input().split())

if K==1:
    print(0)
    exit(0)

A=list(map(int,input().split()))
S=[0]+list(numpy.cumsum(A)) #累積和
S2=[(S[i]-i)%K for i in range(N+1)]
print(A,S,S2)

d = {}
ans = 0
for j in range(1,N+1):
    if j>K-1:
        if S2[j-K] in d:
            d[S2[j-K]] -= 1
        
    if S2[j-1] in d:
        d[S2[j-1]] += 1
    else:
        d[S2[j-1]] = 1
        
    if S2[j] in d:
        ans += d[S2[j]]
print(ans)

# Fixed version:
import numpy
N,K=map(int,input().split())

if K==1:
    print(0)
    exit(0)

A=list(map(int,input().split()))
S=[0]+list(numpy.cumsum(A)) #累積和
S2=[(S[i]-i)%K for i in range(N+1)]

d = {}
ans = 0
for j in range(1,N+1):
    if j>K-1:
        if S2[j-K] in d:
            d[S2[j-K]] -= 1
        
    if S2[j-1] in d:
        d[S2[j-1]] += 1
    else:
        d[S2[j-1]] = 1
        
    if S2[j] in d:
        ans += d[S2[j]]
print(ans)

# Buggy version:
import sys
from collections import Counter
from itertools import accumulate
read = sys.stdin.read

N, K, *A = 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 Counter(a).values():
        answer += cmb(i)
else:
    dic = Counter(a[:K])
    for i in dic.values():
        answer += cmb(i)
    print([0] + A)
    print(a)
    print(dic)
    here = K
    for i, x in enumerate(a[K:]):
        dic[a[i]] -= 1
        answer += dic[x]
        dic[x] += 1

print(answer)

# Fixed version:
import sys
from collections import Counter
from itertools import accumulate
read = sys.stdin.read

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

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

print(answer)

# Buggy version:
import sys
from collections import Counter
from itertools import accumulate
read = sys.stdin.read

N, K, *A = 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 Counter(a).values():
        answer += cmb(i)
else:
    dic = Counter(a[:K])
    for i in dic.values():
        answer += cmb(i)

    here = K
    while here <= N:
        if here >= K - 1:
            dic[a[here - K - 1]] -= 1
        if a[here] in dic:
            answer += dic[a[here]]
            dic[a[here]] += 1
        else:
            dic[a[here]] = 1
        here += 1
    print(answer)


# Fixed version:
import sys
from collections import Counter
from itertools import accumulate
read = sys.stdin.read

N, K, *A = 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 Counter(a).values():
        answer += cmb(i)
else:
    dic = Counter(a[:K])
    for i in 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)

# Buggy version:
n,k=map(int,input().split())
A=[int(i) for i in input().split()]
ans=0
AA=[A[0]-1]
for i in range(1,n):
  AA.append((AA[-1]+A[i]-1)%k)
import collections
d=collections.defaultdict(int)
d[0]+=1
for i in range(n):
  
  if i+1>=k:
    d[AA[i-k]]-=1
  ans+=d[AA[i]]
  d[AA[i]]+=1
print(ans)


# Fixed version:
n,k=map(int,input().split())
A=[int(i) for i in input().split()]
ans=0
AA=[(A[0]-1)%k]
for i in range(1,n):
  AA.append((AA[-1]+A[i]-1)%k)
import collections
d=collections.defaultdict(int)
d[0]+=1
for i in range(n):
  if i+1==k:
    d[0]-=1
  elif i+1>=k:
    d[AA[i-k]]=max(0,d[AA[i-k]]-1)
  ans+=d[AA[i]]
  d[AA[i]]+=1
print(ans)

# Buggy version:
import bisect

n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n - 1):
  a[i] -= 1
  a[i + 1] += a[i]
a[n - 1] -= 1

memo = {0 : []}
for i in range(n):
  if a[i] % k not in memo.keys():
    memo[a[i] % k] = [i]
  else:
    memo[a[i] % k].append(i)

ans = bisect.bisect_left(memo[0], k - 1)

for i in memo.keys():
  for j in range(len(memo[i]) - 1):
    ans += bisect.bisect_left(memo[i], memo[i][j] + k) - 1 - j

print(memo)
print(ans)

# Fixed version:
import bisect

n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n - 1):
  a[i] -= 1
  a[i + 1] += a[i]
a[n - 1] -= 1

memo = {0 : []}
for i in range(n):
  if a[i] % k not in memo.keys():
    memo[a[i] % k] = [i]
  else:
    memo[a[i] % k].append(i)

ans = bisect.bisect_left(memo[0], k - 1)

for i in memo.keys():
  for j in range(len(memo[i]) - 1):
    ans += bisect.bisect_left(memo[i], memo[i][j] + k) - 1 - j

print(ans)

# Buggy version:
n, k = map(int, input().split())
a = [0] + list(map(int, input().split()))

cnt = {0:1}

ans = 0

for i in range(1, n+1):
    left = i - k + 1
    if left >= 0:
        ldif = (a[left] - left) % k
        if ldif < 0: ldif += k
        cnt[ldif] -= 1
    
    a[i] += a[i-1]
    dif = (a[i] - i) % k
    if dif < 0: dif += k
    if dif not in cnt:
        cnt[dif] = 0
        
    ans += cnt[dif]
    cnt[dif] += 1

print(ans)

# Fixed version:
n, k = map(int, input().split())
a = [0] + list(map(int, input().split()))

cnt = {0:1}

ans = 0

for i in range(1, n+1):
    left = i - k
    if left >= 0:
        ldif = (a[left] - left) % k
        if ldif < 0: ldif += k
        cnt[ldif] -= 1
    
    a[i] += a[i-1]
    dif = (a[i] - i) % k
    if dif < 0: dif += k
    if dif not in cnt:
        cnt[dif] = 0
        
    ans += cnt[dif]
    cnt[dif] += 1

print(ans)