Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())

S = input()
n = list(map(int, str(S)))
count = 1
mas = []
for i in range(N-1):
    if n[i] == n[i + 1]:
        count += 1
        if i == N-2:
            mas.append(count)
    else:
        mas.append(count)
        count = 1
        if i == N-2:
            mas.append(1)
        

mas2 = []
if n[0] == 0:
    mas.insert(0, 0)
    
if n[N-1] == 0:
    mas.append(0)
    
l=len(mas)
mas2=[0]
for i in range(1, 1+len(mas)):
    mas2.append(sum(mas[:i]))
    
if K >= (l-1)/2:
    print(N)
else:
    mas3 = []
    k = int(((l-1)/2)-K+1)
    for i in range(k):
        mas3.append(mas2[K*2 + 2*i+1]-mas2[0 + 2*i])
    print(max(mas3))
        

Fixed submission:
from itertools import accumulate

N, K = map(int, input().split())

S = input()
n = list(map(int, str(S)))
count = 1
mas = []
for i in range(N-1):
    if n[i] == n[i + 1]:
        count += 1
        if i == N-2:
            mas.append(count)
    else:
        mas.append(count)
        count = 1
        if i == N-2:
            mas.append(1)
        

mas2 = []
if n[0] == 0:
    mas.insert(0, 0)
    
if n[N-1] == 0:
    mas.append(0)
    
l=len(mas)
mas2=[0] + list(accumulate(mas))
#for i in range(1, 1+len(mas)):
#    mas2.append(sum(mas[:i]))
    
if K >= (l-1)/2:
    print(N)
else:
    mas3 = []
    k = int(((l-1)/2)-K+1)
    for i in range(k):
        mas3.append(mas2[K*2 + 2*i+1]-mas2[0 + 2*i])
    print(max(mas3))

Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()
n = list(map(int, str(S)))
count = 1
mas = []
for i in range(N-1):
    if n[i] == n[i + 1]:
        count += 1
    else:
        mas.append(count)
        count = 1
        if i == N-2:
            mas.append(1)
        
l = len(mas)
mas2 = []
for m in K:
    

    if l%2==0:
            for k in range(l//2):
                mas2.append(mas[2*k+1] + mas[2*k] + mas[2*k+2])
        else:
            for k in range(l/2-1):
                mas2.append(mas[2*k+1] + mas[2*k] + mas[2*k+2])
            mas.append(mas[l-2] + mas[l-1])
    
    else:
        else:
            mas2.append(mas[0] + mas[1])
            for k in range(1, l//2):
                mas2.append(mas[2*k-1] + mas[2*k] + mas[2*k+1])
        else:
            mas2.append(mas[0] + mas[1])
            for k in range(1, l//2-1):
                mas2.append(mas[2*k+1] + mas[2*k] + mas[2*k-1])
            mas.append(mas[l-2] + mas[l-1])

            
            
print(max(mas2))

Fixed submission:
from itertools import accumulate

N, K = map(int, input().split())

S = input()
n = list(map(int, str(S)))
count = 1
mas = []
for i in range(N-1):
    if n[i] == n[i + 1]:
        count += 1
        if i == N-2:
            mas.append(count)
    else:
        mas.append(count)
        count = 1
        if i == N-2:
            mas.append(1)
        

mas2 = []
if n[0] == 0:
    mas.insert(0, 0)
    
if n[N-1] == 0:
    mas.append(0)
    
l=len(mas)
mas2=[0] + list(accumulate(mas))
#for i in range(1, 1+len(mas)):
#    mas2.append(sum(mas[:i]))
    
if K >= (l-1)/2:
    print(N)
else:
    mas3 = []
    k = int(((l-1)/2)-K+1)
    for i in range(k):
        mas3.append(mas2[K*2 + 2*i+1]-mas2[0 + 2*i])
    print(max(mas3))