Buggy python submission (verdict: Runtime Error):
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 submission:
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 python submission (verdict: Time Limit Exceeded):
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)

Fixed submission:
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 python submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = [0] + list(map(int, input().split()))

ans = 0
#s = []
b = []
temp = 0
for i, x in enumerate(a):
    temp = (temp + x) % k
    c = (temp - (i % k) + k) % k
    b.append(c)
    #if x % k == 1:
    #    ans += 1

#print(s)
#print(b)

m = [0] * k

for i in range(min(k, n+1)):
    ans += m[b[i]]
    m[b[i]] += 1

#print(m)

for i in range(k, n+1):
    m[b[i-k]] -= 1
    ans += m[b[i]]
    m[b[i]] += 1
    #print(m)

print(ans)

Fixed submission:
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 python submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = [0] + list(map(int, input().split()))

ans = 0
#s = []
b = []
temp = 0
for i, x in enumerate(a):
    temp = (temp + x) % k
    c = (temp - (i % k) + k) % k
    b.append(c)
    #if x % k == 1:
    #    ans += 1

#print(s)
#print(b)

m = [0] * k

for i in range(k):
    ans += m[b[i]]
    m[b[i]] += 1

#print(m)

for i in range(k, n+1):
    m[b[i-k]] -= 1
    ans += m[b[i]]
    m[b[i]] += 1
    #print(m)

print(ans)

Fixed submission:
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 python submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = [0] + list(map(int, input().split()))

ans = 0
#s = []
b = []
temp = 0
for i, x in enumerate(a):
    temp = (temp + x) % k
    c = (temp - (i % k) + k) % k
    b.append(c)
    #if x % k == 1:
    #    ans += 1

#print(s)
#print(b)

m = [0] * k

for i in range(k):
    ans += m[b[i]]
    m[b[i]] += 1

#print(m)

for i in range(k, n+1):
    m[b[i-k]] -= 1
    ans += m[b[i]]
    m[b[i]] += 1
    #print(m)

print(ans)

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