CodeEff/ECCO huggingface dataset:
# Original solution
import math
import itertools

def read():
    N, K = list(map(int, input().strip().split()))
    A = list(map(int, input().strip().split()))
    return N, K, A


def solve(N, K, A):
    S = [0 for _ in range(N+1)]
    for i in range(N):
        S[i+1] = (S[i] + A[i]) % K
    count = 0
    for j in range(N+1):
        for i in range(j):
            if (S[j] - S[i]) % K == (j - i):
                count += 1
    return count
    
if __name__ == '__main__':
    inputs = read()
    output = solve(*inputs)
    print(("%d" % output))


# Optimized solution
def read():
    N, K = list(map(int, input().strip().split()))
    A = list(map(int, input().strip().split()))
    return N, K, A

def solve(N, K, A):
    if K == 1:
        return 0
    
    S = [0 for _ in range(N+1)]
    for i in range(N):
        S[i+1] = S[i] + A[i]
    
    count_sum = 0
    count = dict()
    for j in range(1, N+1):
        j_mod_k = (S[j] - j) % K  # 0 <= jmodk < K
        if j == 1:
            for i in range(max(0, j-K+1), j):
                # (S[i] - i) % K の値 i_mod_k は、次のループでもほぼ重複する
                # i = max(0, j-K+1) の時の i_mod_k は、i+1で破棄する
                # i = j の時の i_mod_k は、i+1で生成する
                i_mod_k = (S[i] - i) % K
                if i_mod_k in count:
                    count[i_mod_k] += 1
                else:
                    count[i_mod_k] = 1
        else:
            if max(0, j-K+1) != max(0, (j-1)-K+1):
                i = max(0, (j-1)-K+1)
                i_mod_k = (S[i] - i) % K
                if i_mod_k in count:
                    if count[i_mod_k] == 1:
                        count.pop(i_mod_k)
                    else:
                        count[i_mod_k] -= 1
            i = j-1
            i_mod_k = (S[i] - i) % K
            if i_mod_k in count:
                count[i_mod_k] += 1
            else:
                count[i_mod_k] = 1
        if j_mod_k in count:
            count_sum += count[j_mod_k]
    return count_sum

if __name__ == '__main__':
    inputs = read()
    print(('%d' % solve(*inputs)))
# Original solution
def main():
    N, K = list(map(int, input().split()))
    A = tuple(map(int, input().split()))
    l = [[0] * N for _ in range(N)]
    a = 0
    for j in range(N):
        x = A[j] % K
        if x == 1:
            a += 1
        l[j][0] = x
    for i in range(1, N):
        t = i + 1
        y = (l[0][i - 1] + A[i]) % K
        if y == t:
            a += 1
        l[0][i] = y
        for j in range(1, N-i):
            y = (l[j-1][i] + A[i+j] - A[j-1]) % K
            if y == t:
                a +=1
            l[j][i] = y
    return a
print((main()))


# Optimized solution
def main():
    N, K = list(map(int, input().split()))
    A = tuple(map(int, input().split()))
    l = [0] * N
    a = 0
    for j in range(N):
        x = A[j] % K
        if x == 1:
            a += 1
        l[j] = x
    for i in range(1, N):
        t = i + 1
        y = (l[0] + A[i]) % K
        if y == t:
            a += 1
        l[0] = y
        for j in range(1, N-i):
            y = (l[j-1] + A[i+j] - A[j-1]) % K
            if y == t:
                a +=1
            l[j] = y
    return a
print((main()))
# Original solution
from itertools import accumulate
from collections import defaultdict
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = accumulate([0]+ A)
C = [(b-i)%K for i, b in enumerate(B)]
cnt = defaultdict(int)
cnt[C[0]] = 1
res = 0
for i in range(1, N+1):
    if i >= K:
        cnt[C[i-K]] -= 1
    res += cnt[C[i]]
    cnt[C[i]] += 1
print(res)


# Optimized solution
from itertools import accumulate
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = accumulate([0]+ A)
C = [(b-i)%K for i, b in enumerate(B)]
cnt = dict()
cnt[C[0]] = 1
res = 0
for i in range(1, N+1):
    if i >= K:
        cnt[C[i-K]] = cnt.get(C[i-K],0) - 1
    res += cnt.get(C[i], 0)
    cnt[C[i]] = cnt.get(C[i],0) + 1
print(res)
# Original solution
n,k=list(map(int,input().split()))
a=list([(int(x)-1)%k for x in input().split()])
s=[0]
#print(a)
for i in a:
    s.append((s[-1]+i)%k)
#print(s)
mp={}
ans=0
for i in range(len(s)):
    if i-k>=0:
        mp[s[i-k]]-=1
    if s[i] in mp:
        ans+=mp[s[i]]
    if s[i] in mp:
        mp[s[i]]+=1
    else:
        mp[s[i]]=1
    #print(i,ans)
print(ans)
#ans+=sum(list(map(lambda x: x==0,s)))
#print(ans)


# Optimized solution
n,k=list(map(int,input().split()))
a=list([(int(x)-1)%k for x in input().split()])
s=[0]
for i in a:
    s.append((s[-1]+i)%k)
mp={}
ans=0
for i in range(len(s)):
    if i-k>=0:
        mp[s[i-k]]-=1
    if s[i] in mp:
        ans+=mp[s[i]]
        mp[s[i]]+=1
    else:
        mp[s[i]]=1
print(ans)
# Original solution
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
from collections import defaultdict
def resolve():
    n,k=list(map(int,input().split()))
    A=list(map(int,input().split()))
    S=[0]*(n+1)
    for i in range(n):
        S[i+1]=S[i]+A[i]

    for i in range(n+1):
        S[i]-=i
        S[i]%=k

    C=defaultdict(list)
    for i in range(n+1):
        C[S[i]].append(i)

    ans=0
    C=list(C.values())
    for d in range(len(C)):
        n=len(C[d])
        if(n<=1): continue
        r=0
        for l in range(n):
            while(r+1<n and C[d][r+1]-C[d][l]<k):
                r+=1
            ans+=r-l
            if(r==l): r+=1
    print(ans)
resolve()

# Optimized solution
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
from collections import defaultdict
def resolve():
    n,k=list(map(int,input().split()))
    A=list([int(x)-1 for x in input().split()])
    S=[0]*(n+1)
    for i in range(n):
        S[i+1]=S[i]+A[i]
        S[i+1]%=k

    C=defaultdict(int)
    ans=0
    for i in range(n+1):
        if(i-k>=0):
            C[S[i-k]]-=1
        ans+=C[S[i]]
        C[S[i]]+=1
    print(ans)
resolve()
# Original solution
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
from collections import defaultdict,deque
def resolve():
    n,k=list(map(int,input().split()))
    A=list([int(x)-1 for x in input().split()])
    S=[0]*(n+1)
    for i in range(n):
        S[i+1]=S[i]+A[i]
        S[i+1]%=k

    C=defaultdict(int)
    Q=deque()
    ans=0
    for s in S:
        ans+=C[s]
        C[s]+=1
        Q.append(s)
        if(len(Q)==k):
            C[Q.popleft()]-=1
    print(ans)
resolve()

# Optimized solution
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
from collections import defaultdict
def resolve():
    n,k=list(map(int,input().split()))
    A=list(map(int,input().split()))
    S=[0]*(n+1)
    for i in range(n):
        S[i+1]=S[i]+A[i]
    for i in range(n+1):
        S[i]-=i
        S[i]%=k

    ans=0
    D=defaultdict(int)
    for i in range(n+1):
        s=S[i]
        ans+=D[s]
        D[s]+=1
        if(i>=k-1):
            D[S[i-k+1]]-=1
    print(ans)
resolve()
# Original solution
def main():
    from itertools import accumulate
    N,K=list(map(int,input().split()))
    A=list(map(int,input().split()))
    A=list(accumulate(A))
    A=[[(A[i]-i-1)%K,i+1] for i in range(0,N)]
    A.append([0,0])
    A.sort()
    s=1
    start=0
    count=0
    for i in range(0,N):
        if A[i][0]==A[i+1][0]:
            s+=1
        else:
            X=[A[i][1] for i in range(start,start+s)]
            a=0
            b=0
            subcount=0
            while len(X)-1>=a and len(X)-1>=b:
                if K-1>=X[b]-X[a]:
                    b+=1
                else:
                    subcount+=len(X)-b
                    a+=1
            count+=len(X)*(len(X)-1)//2-subcount
            start+=s
            s=1
    X=[A[i][1] for i in range(start,start+s)]
    a=0
    b=0
    subcount=0
    while len(X)-1>=a and len(X)-1>=b:
        if K-1>=X[b]-X[a]:
            b+=1
        else:
            subcount+=len(X)-b
            a+=1
    count+=len(X)*(len(X)-1)//2-subcount
    print(count)

if __name__ == '__main__':
    main()


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

for i in range(1,N):
    A[i]+=A[i-1]

A.append(0)
A.sort()

A=[((A[i]-i)%K,i) for i in range(0,N+1)]
A.sort()
count=0
s=0
t=1
while N>=t and N>=s:
    if A[t][0]==A[s][0] and K>A[t][1]-A[s][1]:
        t+=1
        if t==N+1:
            count+=((t-s)*(t-s-1))//2
    else:
        count+=t-s-1
        s+=1
        if s==t:
            t+=1

print(count)
# Original solution
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, k = LI()
A = [0] + LI()

for i in range(1, n + 1):
    A[i] = (A[i] + A[i - 1] - 1) % k


ans = 0
D = defaultdict(int)
for j in range(n + 1):
    if j >= k:
        D[A[j - k]] -= 1
    ans += D[A[j]]
    D[A[j]] += 1





print(ans)


# Optimized solution
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, cos, radians, pi, sin
from operator import mul
from functools import reduce
from operator import mul


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


n, k = LI()
A = [0] + LI()
for i in range(1, n + 1):
    A[i] = (A[i] + A[i - 1] - 1) % k

D = defaultdict(int)
ans = 0
for i in range(n + 1):
    if i >= k:
        D[A[i - k]] -= 1
    ans += D[A[i]]
    D[A[i]] += 1

print(ans)
# Original solution
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, cos, radians, pi, sin
from operator import mul
from functools import reduce
from operator import mul


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


n, k = LI()
A = [0] + LI()
for i in range(1, n + 1):
    A[i] = (A[i] + A[i - 1] - 1) % k

D = defaultdict(int)
ans = 0
for i in range(n + 1):
    if i >= k:
        D[A[i - k]] -= 1
    ans += D[A[i]]
    D[A[i]] += 1

print(ans)

# Optimized solution
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, cos, radians, pi, sin
from operator import mul
from functools import reduce
from operator import mul


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


n, k = LI()
A = LI()
L = [0]
for i in range(n):
    L += [(L[-1] + A[i] - 1) % k]

D = defaultdict(int)
ans = 0
for i in range(n + 1):
    if i >= k:
        D[L[i - k]] -= 1
    ans += D[L[i]]
    D[L[i]] += 1

print(ans)
# Original solution
from collections import defaultdict, deque

n, k = list(map(int, input().split()))
a = tuple(map(int, input().split()))
acc = [0]
t = 0
for a_ in a:
    t = (t + a_ - 1) % k
    acc.append(t)

d = defaultdict(int)

ret = 0
count = 0
dq = deque()

for acc_ in acc:
    ret += d[acc_]
    d[acc_] += 1
    dq.append(acc_)
    if len(dq) >= k:
        v = dq.popleft()
        d[v] -= 1
print(ret)


# Optimized solution
def main():
    from collections import defaultdict, deque

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

    def accumulate(a, mod):
        s = 0
        yield s
        for x in a:
            s = (s + x - 1) % mod
            yield s

    *acc, = accumulate(a, mod=K)

    d = defaultdict(int)
    dq = deque()
    ans = 0
    for x in acc:
        ans += d[x]
        d[x] += 1
        dq.append(x)
        if len(dq) >= K:
            r = dq.popleft()
            d[r] -= 1
    print(ans)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())
# Original solution
def main():
    from collections import defaultdict, deque

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

    def accumulate(a, mod):
        s = 0
        yield s
        for x in a:
            s = (s + x - 1) % mod
            yield s

    *acc, = accumulate(a, mod=K)

    d = defaultdict(int)
    dq = deque()
    ans = 0
    for x in acc:
        ans += d[x]
        d[x] += 1
        dq.append(x)
        if len(dq) >= K:
            r = dq.popleft()
            d[r] -= 1
    print(ans)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


# Optimized solution
def main():
    from collections import defaultdict, deque

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

    def accumulate(a, mod):
        s = 0
        yield s
        for x in a:
            s = (s + x - 1) % mod
            yield s

    acc = accumulate(a, mod=K)

    d = defaultdict(int)
    dq = deque()
    ans = 0
    for x in acc:
        ans += d[x]
        d[x] += 1
        dq.append(x)
        if len(dq) >= K:
            r = dq.popleft()
            d[r] -= 1
    print(ans)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())
# Original solution
N,K=list(map(int,input().split()))
A=list(map(int,input().split()))
A=[0]+A
R=[0]
for i in range(1,N+1):
    R.append(R[-1]+A[i])
I=[i for i in range(N+1)]

ans=0
for i in range(N):
    for j in range(i+1,N+1):
        if (R[j]-R[i])%K==(j-i):
            ans+=1
print(ans)

# Optimized solution
N,K=list(map(int,input().split()))
a=list(map(int,input().split()))
A=[0]
for i in range(N):
    A.append((A[-1]+a[i]-1))
for i in range(len(A)):
    A[i]%=K
#print(A)

D={}
D[0]=1
ans=0

for i in range(1,N+1):
    if A[i] in D:
        ans+=D[A[i]]
        D[A[i]]+=1
    else:
        D[A[i]]=1
    if i-K+1>=0:
        D[A[i-K+1]]-=1
#print(D)
if K==1:
    print((0))
else:
    print(ans)
# Original solution
from itertools import accumulate
from collections import Counter
n, k, *a = list(map(int, open(0).read().split()))
a = [x % k - 1 for x in a]
a = [0] + [x % k for x in accumulate(a)]
d = Counter()
ans = 0
for l, r in zip([k] * min(k, n + 1) + a, a):
	d[l] -= 1
	ans += d[r]
	d[r] += 1
print(ans)


# Optimized solution
n,k,*a=list(map(int, open(0).read().split()))
b=[0]*-~n
for i in range(n):b[i+1]=(a[i]+b[i]-1)%k
d={k:0}
a=0
for l,r in zip([k]*min(k,n+1)+b,b):d[l]-=1;t=d.get(r,0);a+=t;d[r]=t+1
print(a)
# Original solution
#尺取り法と累積和
from collections import deque
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
#kを法とする配列を作る
a = [(i - 1) for i in a]
acc_a = [0 for i in range(n+1)]
acc_a[0] = 0
acc_a[1] = a[0] % k
#kを法とする累積和
for i in range(2,len(a) + 1):
    acc_a[i] = (a[i - 1] + acc_a[i-1]) % k
ans = 0
count = {}
for i in range(k):
    count[i] = 0
q = deque()
for i in acc_a:
    ans += count[i]
    count[i] += 1
    q.append(i)
    if len(q) == k:
        count[q.popleft()] -= 1
print(ans)

# Optimized solution
from collections import deque
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
#kを法とする配列を作る
a = [(i - 1) for i in a]
acc_a = [0 for i in range(n+1)]
acc_a[0] = 0
acc_a[1] = a[0] % k
#kを法とする累積和
for i in range(2,len(a) + 1):
    acc_a[i] = (a[i - 1] + acc_a[i-1]) % k
ans = 0
count = {}
q = deque()
for i in acc_a:
    if i not in count:
        count[i] = 0
    ans += count[i]
    count[i] += 1
    q.append(i)
    if len(q) == k:
        count[q.popleft()] -= 1
print(ans)
# Original solution
import sys
import itertools
import collections


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, input().rstrip('\n').split()))
    ls = [0] + list([int(x) - 1 for x in input().rstrip('\n').split()])
    ls = [i % k for i in list(itertools.accumulate(ls))]
    
    d = collections.defaultdict(int)
    t = 0
    for i, x in enumerate(ls):
        t += d[x]
        d[x] += 1
        if i >= k - 1:
            d[ls[i - k + 1]] -= 1
    print(t)


if __name__ == '__main__':
    solve()


# Optimized solution
import sys
import itertools
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, readline().split()))
    a = list([int(x) - 1 for x in readline().split()])
    a = [0] + [i % k for i in list(itertools.accumulate(a))]
    d = collections.defaultdict(int)
    cnt = 0
    for i in range(n + 1):
        cnt += d[a[i]]
        d[a[i]] += 1
        if i >= k - 1:
            d[a[i-k+1]] -= 1
    print(cnt)


if __name__ == '__main__':
    solve()
# Original solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
r = 0
s = {0: [0]}
for i in range(n):
    r = (r + a[i] - 1) % k
    s[r] = s.get(r, []) + [i + 1]
ret = 0
for key in s:
    a = s[key]
    en = 0
    for st in range(len(a)):
        while en < len(a) and a[en] - a[st] < k:
            en += 1
        ret += en - st - 1
print(ret)


# Optimized solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
r = 0
s = {0: [0]}
for i in range(n):
    r = (r + a[i] - 1) % k
    if r in s:
        s[r].append(i + 1)
    else:
        s[r] = [i + 1]
ret = 0
for key in s:
    a = s[key]
    en = 0
    for st in range(len(a)):
        while en < len(a) and a[en] - a[st] < k:
            en += 1
        ret += en - st - 1
print(ret)
# Original solution
def main():
    N, K  = [int(i) for i in input().split()]
    A  = [int(i) for i in input().split()]
    v = [0] * N
    r = 0
    for i, a in enumerate(A, 1):
        for j in range(i):
            v[j] = t = (v[j] + a) % K
            if t == i - j:
                r += 1
    return(r)


print((main()))


# Optimized solution
def main():
    N, K  = [int(i) for i in input().split()]
    A  = [int(i) for i in input().split()]
    v = {0: 1}
    n = [0]
    r = 0
    t = 0
    for i, a in enumerate(A, 1):
        if i >= K:
            v[n[i - K]] -= 1
        t += a
        j = (t - i) % K
        r += v.get(j, 0)
        v[j] = v.get(j, 0) + 1
        n.append(j)

    return r


print((main()))
# Original solution
M, K = list(map(int, input().split()))
A = list(map(int, input().split()))

ans = 0
accum = []
ids = []
for i, a in enumerate(A):
  ids.append(i+1)
  accum = list([x+a for x in accum])
  accum.append(a)
  ans += sum([1 if s%K == idx else 0 for s, idx in zip(accum, ids[::-1])])

print(ans)  

# Optimized solution
M, K = list(map(int, input().split()))
A = list(map(int, input().split()))

ans = 0
accum = [0]
d = {0 : 1}

for i, a in enumerate(A):
  accum.append((accum[-1] + a - 1)%K)
  if i >= K - 1:
    d[accum[i-K+1]] -= 1
  
  if accum[-1] in d:
    ans += d[accum[-1]]
    d[accum[-1]] += 1
  
  else:
    d[accum[-1]] = 1

print(ans)
# Original solution
import sys
from collections import Counter
from itertools import accumulate
read = sys.stdin.read

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

# Optimized solution
import sys
from collections import defaultdict
from itertools import accumulate
read = sys.stdin.read

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

answer = 0
dic = defaultdict(int)

for i, x in enumerate(a):
    answer += dic[x]
    dic[x] += 1
    if i >= K - 1:
        dic[a[i - K + 1]] -= 1

print(answer)
# Original solution
from itertools import *
from collections import defaultdict
def ints():
  return [int(x) for x in input().split()]
def readi():
  return int(eval(input()))

N, K = ints()
A = ints()
S = [0] + list(accumulate(A))

def f(i):
  return (S[i]-i)%K

s = 0
for j in range(1, N+1):
  fj = f(j)
  for i in range(max(0, j-K+1), j):
    if f(i)==fj:
      s += 1
print(s)


# Optimized solution
from itertools import *
from collections import defaultdict
def ints():
  return [int(x) for x in input().split()]
def readi():
  return int(eval(input()))

N, K = ints()
A = ints()
S = [0] + list(accumulate(A))

def f(i):
  return (S[i]-i)%K

s = 0
memo = defaultdict(int)
for j in range(1, N+1):
  fj = f(j)

  if j-K>=0:
    memo[f(j-K)] -= 1
  memo[f(j-1)] += 1

  s += memo[fj]
print(s)
# Original solution
[ a, b, c ] = list(map ( int, input ( ).split ( ) ));

if a < b < c:
  print ( "Yes" )
else:
  print ( "No" )

# Optimized solution
x = input().split()
a, b, c = int(x[0]), int(x[1]), int(x[2])

if a < b < c:
    print("Yes")
else:
    print("No")
# Original solution
(a, b, c) = input().rstrip().split(' ')
a = int(a)
b = int(b)
c = int(c)
 
if a < b < c:
    print('Yes')
else:
    print('No')

# Optimized solution
a, b, c = list(map(int, input().split()))
if a<b<c:
	print("Yes")
else:
	print("No")