Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
a = list(map(lambda x:int(x)%k, input().split()))
for i in range(1,n):
  a[i] += a[i-1]
b = 0
for j in range(n):
  if a[j]%k == j+1:
    b += 1
  for i in range(max(0,j-k+1),j):
    if (a[j]-a[i])%k == j-i:
      b += 1
print(b)

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
a[0] = (a[0]-1)%k
for i in range(1,n):
  a[i] = (a[i]+a[i-1]-1)%k
ans = 0
b = {0:1}
for i in range(n):
  if i>0:
    b[a[i-1]] = b.get(a[i-1],0) + 1
  if i>=k:
    b[a[i-k]] -= 1
  if i==k-1:
    b[0] -= 1
  ans += b.get(a[i],0)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import copy
n, k = map(int, input().split())
a = list(map(lambda x:int(x)%k, input().split()))
a2 = copy.deepcopy(a)
b = 0
c = 0
for i in range(1,min(n,k-1)+1):
  b += sum([1 for j in a2[:(n-i+1)] if j==i])
  if i < min(n,k-1):
    a2 = [(a[i+j]+a2[j])%k for j in range(n-i)]
print(b)

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
a[0] = (a[0]-1)%k
for i in range(1,n):
  a[i] = (a[i]+a[i-1]-1)%k
ans = 0
b = {0:1}
for i in range(n):
  if i>0:
    b[a[i-1]] = b.get(a[i-1],0) + 1
  if i>=k:
    b[a[i-k]] -= 1
  if i==k-1:
    b[0] -= 1
  ans += b.get(a[i],0)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
a = list(map(lambda x:int(x)%k, input().split()))

b = 0
c = 0
for i in range(1,min(n,k-1)+1):
  c = (c + a[i-1])%k
  c2 = c
  for j in range(n-i+1):
    c2 = c2%k
    if c2 == i:
      b += 1
    if i+j < n:
      c2 += a[i+j] - a[j]
print(b)

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
a[0] = (a[0]-1)%k
for i in range(1,n):
  a[i] = (a[i]+a[i-1]-1)%k
ans = 0
b = {0:1}
for i in range(n):
  if i>0:
    b[a[i-1]] = b.get(a[i-1],0) + 1
  if i>=k:
    b[a[i-k]] -= 1
  if i==k-1:
    b[0] -= 1
  ans += b.get(a[i],0)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
a = list(map(lambda x:int(x)%k, input().split()))

b = 0
c = 0
for i in range(1,min(n,k-1)+1):
  c += a[i-1]
  c2 = c
  for j in range(n-i+1):
    if c2%k == i:
      b += 1
    if i+j < n:
      c2 += a[i+j] - a[j]
print(b)

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
a[0] = (a[0]-1)%k
for i in range(1,n):
  a[i] = (a[i]+a[i-1]-1)%k
ans = 0
b = {0:1}
for i in range(n):
  if i>0:
    b[a[i-1]] = b.get(a[i-1],0) + 1
  if i>=k:
    b[a[i-k]] -= 1
  if i==k-1:
    b[0] -= 1
  ans += b.get(a[i],0)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
a = list(map(int, input().split()))

b = 0
c = 0
for i in range(1,min(n,k-1)+1):
  c += a[i-1]
  c2 = c
  for j in range(n-i+1):
    if c2%k == i:
      b += 1
    if i+j < n:
      c2 += a[i+j] - a[j]
print(b)

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
a[0] = (a[0]-1)%k
for i in range(1,n):
  a[i] = (a[i]+a[i-1]-1)%k
ans = 0
b = {0:1}
for i in range(n):
  if i>0:
    b[a[i-1]] = b.get(a[i-1],0) + 1
  if i>=k:
    b[a[i-k]] -= 1
  if i==k-1:
    b[0] -= 1
  ans += b.get(a[i],0)
print(ans)