Buggy python submission (verdict: Time Limit Exceeded):
import numpy
N,K=map(int,input().split())
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 and str(S2[j-K]) in d:
        d[str(S2[j-K])] -= 1
        
    if str(S2[j-1]) in d:
        d[str(S2[j-1])] += 1
    else:
        d[str(S2[j-1])] = 1
        
    if str(S2[j]) in d:
        ans += d[str(S2[j])]
print(ans)

Fixed submission:
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 python submission (verdict: Time Limit Exceeded):
import numpy
N,K=map(int,input().split())
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:
        d[str(S2[j-K])] = d.get(str(S2[j-K]), 0) - 1
    d[str(S2[j-1])] = d.get(str(S2[j-1]), 0) + 1
    ans += d.get(str(S2[j]), 0)
print(ans)

Fixed submission:
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 python submission (verdict: Runtime Error):
import numpy
N,K=map(int,input().split())
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:
        d[str(S2[j-K])] = d.get(str(S2[j-K]), 0) - 1
    d[str(S2[j-1])] = d.get(str(S2[j-1]), 0) + 1
    ans += d.get(str(S2[j]), 0)
print(ans)

Fixed submission:
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 python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
    N,K=map(int,input().split())
    ans=0
    
    A=list(map(int,input().split()))
    A=[A[j]%K for j in range(N)]
    ans += A.count(1)
    
    B=[(A[j]+A[j+1])%K for j in range(N-1)]
    ans += B.count(2)
    
    for i in range(2,min(K+1,N)):
        C = [(B[j]+B[j+1]-A[j+1])%K for j in range(N-i)]
        ans += C.count(i+1)
        A = B
        B = C
        
    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
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 python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
    N,K=map(int,input().split())
    ans=0
    
    A=list(map(int,input().split()))
    A=[A[j]%K for j in range(N)]
    ans += A.count(1)
    
    B=[(A[j]+A[j+1])%K for j in range(N-1)]
    ans += B.count(2)
    
    for i in range(2,min(K+1,N)):
        C = [(B[j]+B[j+1]-A[j+1])%K for j in range(N-i)]
        ans += C.count(i+1)
        A = B
        B = C
        
    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
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 python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
ans=0

A=list(map(int,input().split()))
A=[A[j]%K for j in range(N)]
ans += A.count(1)

B=[(A[j]+A[j+1])%K for j in range(N-1)]
ans += B.count(2)

for i in range(2,min(K+1,N)):
    C = [(B[j]+B[j+1]-A[j+1])%K for j in range(N-i)]
    ans += C.count(i+1)
    A = B
    B = C
    
print(ans)
    


Fixed submission:
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 python submission (verdict: Runtime Error):
N,K=map(int,input().split())
ans=[0]*(10**9+1)

A=list(map(int,input().split()))
A=[A[j]%K for j in range(N)]
ans[1] = A.count(1)

B=[(A[j]+A[j+1])%K for j in range(N-1)]
ans[2] = B.count(2)

for i in range(2,min(K+1,N)):
    C = [(B[j]+B[j+1]-A[j+1])%K for j in range(N-i)]
    ans[i+1] = C.count(i+1)
    A = B
    B = C
    
print(sum(ans))


Fixed submission:
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 python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
ans=0

A=list(map(int,input().split()))
A=[A[j]%K for j in range(N)]
ans += A.count(1)

B=[(A[j]+A[j+1])%K for j in range(N-1)]
ans += B.count(2)

for i in range(2,min(K+1,N)):
    C = [(B[j]+B[j+1]-A[j+1])%K for j in range(N-i)]
    ans += C.count(i+1)
    A = B
    B = C
    
print(ans)
    


Fixed submission:
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 python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
ans=0

A=list(map(int,input().split()))
for j in range(N):
    A[j] %= K
ans += A.count(1)

B=[]
for j in range(N-1):
    B.append((A[j]+A[j+1])%K)
ans += B.count(2)

for i in range(2,min(K+1,N)):
    C=[]
    for j in range(N-i):
        C.append((B[j]+B[j+1]-A[j+1])%K)
    ans += C.count(i+1)
    A = B
    B = C
    
print(ans)
    


Fixed submission:
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 python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
ans=0

A=list(map(int,input().split()))
for j in range(N):
    A[j] %= K
ans += A.count(1)

B=[]
for j in range(N-1):
    B.append((A[j]+A[j+1])%K)
ans += B.count(2)

for i in range(2,N):
    C=[]
    for j in range(N-i):
        C.append((B[j]+B[j+1]-A[j+1])%K)
    ans += C.count(i+1)
    A = B
    B = C
    
print(ans)

Fixed submission:
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)