Buggy python submission (verdict: Runtime Error):
def main():
    N, K = map(int, input().split())
    A = tuple(map(int, input().split()))
    d = {}
    d2 = {}
    d[0] = [0]
    s = 0
    for i in range(1, N+1):
        s = (s + A[i-1]) % K
        t = (s-i) % K
        if t in d:
            d[t].append(i)
        else:
            d[t] = [i]
        d2[i] = t
    a = 0
    x = [0] * K
    for i in range(1, N+1):
        for j, v in enumerate(d[d2[i]][x[d2[i]]:]):
            if i - K < v and v < i:
                a += 1
            elif v >= i:
                break
            else:
                x[d2[i]] = j
    return a

print(main())


Fixed submission:
def main():
    N, K = map(int,input().split())
    A = list(map(int, input().split()))
    s = 0
    d = {}
    d[0] = {0}
    r = 0
    l = [0] * (N + 1)
    for i, v in enumerate(A, start=1):
        if i - K >= 0:
           x = l[i - K]
           d[x].remove(i-K)
        s += v % K
        s %= K
        t = (s - i) % K
        l[i] = t
        if t in d:
            r += len(d[t])
            d[t].add(i)
        else:
            d[t] = {i}
    return r
print(main())

Buggy python submission (verdict: Runtime Error):
def main():
    N, K = map(int, input().split())
    A = tuple(map(int, input().split()))
    d = {}
    d2 = {}
    d[0] = [0]
    s = 0
    for i in range(1, N+1):
        s = (s + A[i-1]) % K
        t = (s-i) % K
        if t in d:
            d[t].append(i)
        else:
            d[t] = [i]
        d2[i] = t
    a = 0
    x = [0] * K
    for i in range(1, N+1):
        t = d[d2[i]]
        for j in t[x[d2[i]]:]:
            if i - K < j and j < i:
                a += 1
            elif j >= i:
                break
            else:
                x[d2[i]] = j

    return a

print(main())


Fixed submission:
def main():
    N, K = map(int,input().split())
    A = list(map(int, input().split()))
    s = 0
    d = {}
    d[0] = {0}
    r = 0
    l = [0] * (N + 1)
    for i, v in enumerate(A, start=1):
        if i - K >= 0:
           x = l[i - K]
           d[x].remove(i-K)
        s += v % K
        s %= K
        t = (s - i) % K
        l[i] = t
        if t in d:
            r += len(d[t])
            d[t].add(i)
        else:
            d[t] = {i}
    return r
print(main())

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, K = map(int, input().split())
    A = tuple(map(int, input().split()))
    d = {}
    d2 = {}
    d[0] = [0]
    s = 0
    for i in range(1, N+1):
        s = (s + A[i-1]) % K
        t = (s-i) % K
        if t in d:
            d[t].append(i)
        else:
            d[t] = [i]
        d2[i] = t
    a = 0
    for i in range(1, N+1):
        for j in d[d2[i]]:
            if i - K < j and j < i:
                a += 1
            if j >= i:
                break
    return a

print(main())


Fixed submission:
def main():
    N, K = map(int,input().split())
    A = list(map(int, input().split()))
    s = 0
    d = {}
    d[0] = {0}
    r = 0
    l = [0] * (N + 1)
    for i, v in enumerate(A, start=1):
        if i - K >= 0:
           x = l[i - K]
           d[x].remove(i-K)
        s += v % K
        s %= K
        t = (s - i) % K
        l[i] = t
        if t in d:
            r += len(d[t])
            d[t].add(i)
        else:
            d[t] = {i}
    return r
print(main())

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, K = map(int, input().split())
    A = tuple(map(int, input().split()))
    d = {}
    d2 = {}
    d[0] = [0]
    s = 0
    for i in range(1, N+1):
        s = s + A[i-1]
        t = (s-i) % K
        if t in d:
            d[t].append(i)
        else:
            d[t] = [i]
        d2[i] = t
    a = 0
    for i in range(1, N+1):
        for j in d[d2[i]]:
            if i - K < j and j < i:
                a += 1
    return a

print(main())


Fixed submission:
def main():
    N, K = map(int,input().split())
    A = list(map(int, input().split()))
    s = 0
    d = {}
    d[0] = {0}
    r = 0
    l = [0] * (N + 1)
    for i, v in enumerate(A, start=1):
        if i - K >= 0:
           x = l[i - K]
           d[x].remove(i-K)
        s += v % K
        s %= K
        t = (s - i) % K
        l[i] = t
        if t in d:
            r += len(d[t])
            d[t].add(i)
        else:
            d[t] = {i}
    return r
print(main())

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, K = map(int, input().split())
    A = tuple(map(int, input().split()))
    a = 0
    for j in range(N):
        x = A[j] % K
        if x == 1:
            a += 1
    s = A[0] % K
    for i in range(1, N):
        t = i + 1
        y = (s + A[i]) % K
        if y == t:
            a += 1
        s = y
        s2 = y
        for j in range(1, N-i):
            y = (s2 + A[i+j] - A[j-1]) % K
            if y == t:
                a +=1
            s2 = y
    return a
print(main())


Fixed submission:
def main():
    N, K = map(int,input().split())
    A = list(map(int, input().split()))
    s = 0
    d = {}
    d[0] = {0}
    r = 0
    l = [0] * (N + 1)
    for i, v in enumerate(A, start=1):
        if i - K >= 0:
           x = l[i - K]
           d[x].remove(i-K)
        s += v % K
        s %= K
        t = (s - i) % K
        l[i] = t
        if t in d:
            r += len(d[t])
            d[t].add(i)
        else:
            d[t] = {i}
    return r
print(main())

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, K = map(int, input().split())
    A = tuple(map(int, input().split()))
    a = 0
    for j in range(N):
        x = A[j] % K
        if x == 1:
            a += 1
    s = A[0] % K
    for i in range(1, N):
        t = i + 1
        y = (s + A[i]) % K
        if y == t:
            a += 1
        s = y
        s2 = y
        for j in range(1, N-i):
            y = (s2 + A[i+j] - A[j-1]) % K
            if y == t:
                a +=1
            s2 = y
    return a
print(main())


Fixed submission:
def main():
    N, K = map(int,input().split())
    A = list(map(int, input().split()))
    s = 0
    d = {}
    d[0] = {0}
    r = 0
    l = [0] * (N + 1)
    for i, v in enumerate(A, start=1):
        if i - K >= 0:
           x = l[i - K]
           d[x].remove(i-K)
        s += v % K
        s %= K
        t = (s - i) % K
        l[i] = t
        if t in d:
            r += len(d[t])
            d[t].add(i)
        else:
            d[t] = {i}
    return r
print(main())

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, K = 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())


Fixed submission:
def main():
    N, K = map(int,input().split())
    A = list(map(int, input().split()))
    s = 0
    d = {}
    d[0] = {0}
    r = 0
    l = [0] * (N + 1)
    for i, v in enumerate(A, start=1):
        if i - K >= 0:
           x = l[i - K]
           d[x].remove(i-K)
        s += v % K
        s %= K
        t = (s - i) % K
        l[i] = t
        if t in d:
            r += len(d[t])
            d[t].add(i)
        else:
            d[t] = {i}
    return r
print(main())

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, K = 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())


Fixed submission:
def main():
    N, K = map(int,input().split())
    A = list(map(int, input().split()))
    s = 0
    d = {}
    d[0] = {0}
    r = 0
    l = [0] * (N + 1)
    for i, v in enumerate(A, start=1):
        if i - K >= 0:
           x = l[i - K]
           d[x].remove(i-K)
        s += v % K
        s %= K
        t = (s - i) % K
        l[i] = t
        if t in d:
            r += len(d[t])
            d[t].add(i)
        else:
            d[t] = {i}
    return r
print(main())