Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N, K = mi()
S = input()

len_list = [0]*(10**5+100)
ind = 0
if S[0] == '0':
    len_list[0] = 0
    ind += 1

cnt = 1
for i in range(1, N):
    if S[i] != S[i-1]:
        len_list[ind] = cnt
        ind += 1
        cnt = 1
    else:
        cnt += 1
len_list[ind] = cnt

#print(len_list[:30])
i = 0
wa = 0
sum_l = sum(len_list[:2*K+1])
while True:
    if len_list[i+2*K+1] != 0:
        wa = max(wa, sum_l)
    else:
        wa = max(wa, sum_l)
        break
    sum_l -= (len_list[i] + len_list[i+1])
    sum_l += (len_list[i+2*K+1] + len_list[i+2*K+2])
    i += 2
print(wa)


        



Fixed submission:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N, K = mi()
S = input()
inds = [[0, 0]]

flag = 0
s = 0
for i in range(N):
    if S[i] == '0':
        if not flag:
            flag = 1
            inds.append([s, i-1])
    else:
        if flag:
            s = i
        flag = 0
if flag:
    inds.append([N-1, N-1])
if not flag:
    inds.append([s, N-1])
#print(inds)
l_inds = len(inds)
wa = 0
if K >= l_inds-1:
    print(N)
    exit()
for i in range(l_inds-K):
    wa = max(inds[i+K][1] - inds[i][0] + 1, wa)

print(wa)

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N, K = mi()
S = input()

len_list = [0]*(10**5+10)
ind = 0
if S[0] == '0':
    len_list[0] = 0
    ind += 1

cnt = 1
for i in range(1, N):
    if S[i] != S[i-1]:
        len_list[ind] = cnt
        ind += 1
        cnt = 1
    else:
        cnt += 1
len_list[ind] = cnt

#print(len_list[:30])
i = 0
wa = 0
sum_l = sum(len_list[:2*K+1])
while True:
    if len_list[i+2*K+1] != 0:
        wa = max(wa, sum_l)
    else:
        wa = max(wa, sum_l)
        break
    sum_l -= (len_list[i] + len_list[i+1])
    sum_l += (len_list[i+2*K+1] + len_list[i+2*K+2])
    i += 2
print(wa)


        



Fixed submission:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N, K = mi()
S = input()
inds = [[0, 0]]

flag = 0
s = 0
for i in range(N):
    if S[i] == '0':
        if not flag:
            flag = 1
            inds.append([s, i-1])
    else:
        if flag:
            s = i
        flag = 0
if flag:
    inds.append([N-1, N-1])
if not flag:
    inds.append([s, N-1])
#print(inds)
l_inds = len(inds)
wa = 0
if K >= l_inds-1:
    print(N)
    exit()
for i in range(l_inds-K):
    wa = max(inds[i+K][1] - inds[i][0] + 1, wa)

print(wa)

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N, K = mi()
S = input()

len_list = [0]*(10**5)
ind = 0
if S[0] == '0':
    len_list[0] = 0
    ind += 1

cnt = 1
for i in range(1, N):
    if S[i] != S[i-1]:
        len_list[ind] = cnt
        ind += 1
        cnt = 1
    else:
        cnt += 1
len_list[ind] = cnt

#print(len_list[:30])
i = 0
wa = 0
while True:
    if len_list[i+2*K+1] != 0:
        wa = max(wa, sum(len_list[i:i+2*K+1]))
    else:
        wa = max(wa, sum(len_list[i:]))
        break
    i += 2
print(wa)

Fixed submission:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N, K = mi()
S = input()
inds = [[0, 0]]

flag = 0
s = 0
for i in range(N):
    if S[i] == '0':
        if not flag:
            flag = 1
            inds.append([s, i-1])
    else:
        if flag:
            s = i
        flag = 0
if flag:
    inds.append([N-1, N-1])
if not flag:
    inds.append([s, N-1])
#print(inds)
l_inds = len(inds)
wa = 0
if K >= l_inds-1:
    print(N)
    exit()
for i in range(l_inds-K):
    wa = max(inds[i+K][1] - inds[i][0] + 1, wa)

print(wa)

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N, K = mi()
S = input()

len_list = [0]*(10**5)
ind = 0
if S[0] == '0':
    len_list[0] = 0
    ind += 1

cnt = 1
for i in range(1, N):
    if S[i] != S[i-1]:
        len_list[ind] = cnt
        ind += 1
        cnt = 1
    else:
        cnt += 1
len_list[ind] = cnt

#print(len_list[:30])
i = 0
wa = 0
while True:
    if len_list[i+2*K+1] != 0:
        wa = max(wa, sum(len_list[i:i+2*K+1]))
    else:
        wa = max(wa, sum(len_list[i:]))
        break
    i += 2
print(wa)

Fixed submission:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N, K = mi()
S = input()
inds = [[0, 0]]

flag = 0
s = 0
for i in range(N):
    if S[i] == '0':
        if not flag:
            flag = 1
            inds.append([s, i-1])
    else:
        if flag:
            s = i
        flag = 0
if flag:
    inds.append([N-1, N-1])
if not flag:
    inds.append([s, N-1])
#print(inds)
l_inds = len(inds)
wa = 0
if K >= l_inds-1:
    print(N)
    exit()
for i in range(l_inds-K):
    wa = max(inds[i+K][1] - inds[i][0] + 1, wa)

print(wa)

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N, K = mi()
S = input()

len_list = []
if S[0] == '1' and S[1] != '1':
    len_list.append(0)

cnt = 1
for i in range(1, N):
    if S[i] != S[i-1]:
        len_list.append(cnt)
        cnt = 1
    else:
        cnt += 1
len_list.append(cnt)

#print(len_list)
i = 0
wa = 0
while True:
    if i+2*K+1 < N:
        wa = max(wa, sum(len_list[i:i+2*K+1]))
    else:
        wa = max(wa, sum(len_list[i:]))
        break
    i += 2
print(wa)

Fixed submission:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N, K = mi()
S = input()
inds = [[0, 0]]

flag = 0
s = 0
for i in range(N):
    if S[i] == '0':
        if not flag:
            flag = 1
            inds.append([s, i-1])
    else:
        if flag:
            s = i
        flag = 0
if flag:
    inds.append([N-1, N-1])
if not flag:
    inds.append([s, N-1])
#print(inds)
l_inds = len(inds)
wa = 0
if K >= l_inds-1:
    print(N)
    exit()
for i in range(l_inds-K):
    wa = max(inds[i+K][1] - inds[i][0] + 1, wa)

print(wa)