Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
S = input()
c0, c1 = [], []
if S[0] == '1':
    c0.append(0)
i = 0
while i < N:
    p = S[i]
    c = 1
    i += 1
    while i < N and S[i] == p:
        i += 1
        c += 1
    if p == '0':
        c0.append(c)
    else:
        c1.append(c)
if S[N-1] == '0':
    c1.append(0)
l0 = len(c0)
for i in range(1, l0):
    c0[i] += c0[i-1]
    c1[i] += c1[i-1]
l = l0 - K + 1
ans = c0[K-1] + c1[K-1]
for i in range(1, l):
    tmp = c0[i+K-1] - c0[i-1] + c1[i+K-1] - c1[i-2]
    if ans < tmp:
        ans = tmp
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
S = input()
c0, c1 = [], []
if S[0] == '1':
    c0.append(0)
i = 0
while i < N:
    p = S[i]
    c = 1
    i += 1
    while i < N and S[i] == p:
        i += 1
        c += 1
    if p == '0':
        c0.append(c)
    else:
        c1.append(c)
if S[N-1] == '0':
    c1.append(0)
l0 = len(c0)
if l0 < K:
    K = l0
ans = sum(c0[0:K]) + sum(c1[0:K])
for i in range(1, l0):
    c0[i] += c0[i-1]
    c1[i] += c1[i-1]
l = l0 - K + 1
if l0 == 2 and S[0] == '1':
    ans = N
else:
    for i in range(1, l):
        tmp = c0[i+K-1] - c0[i-1] + c1[i+K-1]
        if i - 2 >= 0:
            tmp -= c1[i-2]
        if ans < tmp:
            ans = tmp
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
S = input()
c0, c1 = [], []
if S[0] == '1':
    c0.append(0)
i = 0
while i < N:
    p = S[i]
    c = 1
    i += 1
    while i < N and S[i] == p:
        i += 1
        c += 1
    if p == '0':
        c0.append(c)
    else:
        c1.append(c)
if S[N-1] == '0':
    c1.append(0)
l0 = len(c0)
for i in range(1, l0):
    c0[i] += c0[i-1]
    c1[i] += c1[i-1]
l = l0 - K + 1
ans = c0[K] + c1[K]
for i in range(1, l):
    tmp = c0[i+K-1] - c0[i-1] + c1[i+K-1] - c1[i-2]
    if ans < tmp:
        ans = tmp
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
S = input()
c0, c1 = [], []
if S[0] == '1':
    c0.append(0)
i = 0
while i < N:
    p = S[i]
    c = 1
    i += 1
    while i < N and S[i] == p:
        i += 1
        c += 1
    if p == '0':
        c0.append(c)
    else:
        c1.append(c)
if S[N-1] == '0':
    c1.append(0)
l0 = len(c0)
if l0 < K:
    K = l0
ans = sum(c0[0:K]) + sum(c1[0:K])
for i in range(1, l0):
    c0[i] += c0[i-1]
    c1[i] += c1[i-1]
l = l0 - K + 1
if l0 == 2 and S[0] == '1':
    ans = N
else:
    for i in range(1, l):
        tmp = c0[i+K-1] - c0[i-1] + c1[i+K-1]
        if i - 2 >= 0:
            tmp -= c1[i-2]
        if ans < tmp:
            ans = tmp
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
S = input()
c0, c1 = [], []
if S[0] == '1':
    c0.append(0)
i = 0
while i < N:
    p = S[i]
    c = 1
    i += 1
    while i < N and S[i] == p:
        i += 1
        c += 1
    if p == '0':
        c0.append(c)
    else:
        c1.append(c)
if S[N-1] == '0':
    c1.append(0)
ans = sum(c0[0:K]) + sum(c1[0:K])
for i in range(1, len(c1) - K + 1):
    tmp = sum(c0[i:i + K]) + sum(c1[i-1:i + K])
    if ans < tmp:
        ans = tmp
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
S = input()
c0, c1 = [], []
if S[0] == '1':
    c0.append(0)
i = 0
while i < N:
    p = S[i]
    c = 1
    i += 1
    while i < N and S[i] == p:
        i += 1
        c += 1
    if p == '0':
        c0.append(c)
    else:
        c1.append(c)
if S[N-1] == '0':
    c1.append(0)
l0 = len(c0)
if l0 < K:
    K = l0
ans = sum(c0[0:K]) + sum(c1[0:K])
for i in range(1, l0):
    c0[i] += c0[i-1]
    c1[i] += c1[i-1]
l = l0 - K + 1
if l0 == 2 and S[0] == '1':
    ans = N
else:
    for i in range(1, l):
        tmp = c0[i+K-1] - c0[i-1] + c1[i+K-1]
        if i - 2 >= 0:
            tmp -= c1[i-2]
        if ans < tmp:
            ans = tmp
print(ans)