Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
S_list = ['0'] + list(input()) + ['-1']

s_count_list =[]

cnt = 1
for i in range(1,N+2) :
    if S_list[i] == S_list[i-1] :
        cnt +=1
    else:
        s_count_list.append(cnt)
        cnt = 1
if S_list[1] == '0':
    s_count_list[0] = s_count_list[0] -1
else:
    s_count_list.pop(0)

ruisekiwa = [0]
for i,s in enumerate(s_count_list):
    ruisekiwa.append(s_count_list[i] + s)

for i in range(0,len(ruisekiwa),2):
    left = i
    right = min((i + (2 * K) + 1),len(ruisekiwa))
    tmp = ruisekiwa[right] - ruisekiwa[left]
    answer = max(tmp,answer)

print(answer)

Fixed submission:
q, k = list(map(int, input().split()))
list = [int(i) for i in input()]

# 0 ,1 のまとまりを作る
sum01 = []
pre = 1
cnt = 0
# 111010
# 001010
for i, e in enumerate(list):
    if e != pre:
        sum01.append(cnt)
        cnt = 1
        pre = e
    else:
        cnt += 1
if cnt != 0:
    sum01.append(cnt)

if len(sum01) % 2 == 1:
    sum01.append(0)

# print(sum01)
Add = 2 * k + 1
ruiseki = [0]
for i, e in enumerate(sum01):
    ruiseki.append(ruiseki[i] + sum01[i])

# print(ruiseki)
answer = 0
for i in range(0, len(sum01), 2):
    left = i
    right = min(i + Add, len(sum01))
    temp = ruiseki[right] - ruiseki[left]
    answer = max(temp, answer)

print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
q, k = list(map(int, input().split()))
list = [int(i) for i in input()]

# 0 ,1 のまとまりを作る
sum01 = []
pre = 1
cnt = 0
# 111010
# 001010
for i, e in enumerate(list):
    if e != pre:
        sum01.append(cnt)
        cnt = 1
        pre = e
    else:
        cnt += 1
if cnt != 0:
    sum01.append(cnt)

if len(sum01) % 2 == 1:
    sum01.append(0)

#print(sum01)
Add = 2 * k + 1
answer = 0
for i in range(0, len(sum01), 2):
    temp = 0
    left = i
    right = min(i + Add, len(sum01))
    for j in range(left, right, 1):
        temp += sum01[j]
    answer = max(temp, answer)

print(answer)

Fixed submission:
q, k = list(map(int, input().split()))
list = [int(i) for i in input()]

# 0 ,1 のまとまりを作る
sum01 = []
pre = 1
cnt = 0
# 111010
# 001010
for i, e in enumerate(list):
    if e != pre:
        sum01.append(cnt)
        cnt = 1
        pre = e
    else:
        cnt += 1
if cnt != 0:
    sum01.append(cnt)

if len(sum01) % 2 == 1:
    sum01.append(0)

# print(sum01)
Add = 2 * k + 1
ruiseki = [0]
for i, e in enumerate(sum01):
    ruiseki.append(ruiseki[i] + sum01[i])

# print(ruiseki)
answer = 0
for i in range(0, len(sum01), 2):
    left = i
    right = min(i + Add, len(sum01))
    temp = ruiseki[right] - ruiseki[left]
    answer = max(temp, answer)

print(answer)

Buggy python submission (verdict: Runtime Error):
q, k = list(map(int, input().split()))
list = [int(i) for i in input()]

# 0 ,1 のまとまりを作る
sum01 = []
pre = 1
cnt = 0
# 111010
# 001010
for i, e in enumerate(list):
    if e != pre:
        sum01.append(cnt)
        cnt = 1
        pre = e
    else:
        cnt += 1
if cnt != 0:
    sum01.append(cnt)

if len(sum01) % 2 == 1:
    sum01.append(0)

print(sum01)
Add = 2 * k + 1
answer = 0
for i in range(0, len(sum01), 2):
    temp = 0
    left = i
    right = min(i + Add, len(sum01))
    for j in range(left, right, 1):
        temp += sum01[j]
    answer = max(temp, answer)

print(answer)

'''

Fixed submission:
q, k = list(map(int, input().split()))
list = [int(i) for i in input()]

# 0 ,1 のまとまりを作る
sum01 = []
pre = 1
cnt = 0
# 111010
# 001010
for i, e in enumerate(list):
    if e != pre:
        sum01.append(cnt)
        cnt = 1
        pre = e
    else:
        cnt += 1
if cnt != 0:
    sum01.append(cnt)

if len(sum01) % 2 == 1:
    sum01.append(0)

# print(sum01)
Add = 2 * k + 1
ruiseki = [0]
for i, e in enumerate(sum01):
    ruiseki.append(ruiseki[i] + sum01[i])

# print(ruiseki)
answer = 0
for i in range(0, len(sum01), 2):
    left = i
    right = min(i + Add, len(sum01))
    temp = ruiseki[right] - ruiseki[left]
    answer = max(temp, answer)

print(answer)