Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
S = input()
L = [0]
res = '1'
i = 0
for s in S:
    if s != res:
        L.append(i)
        i += 1
    else:
        i += 1
    res = s
L.append(i)
if len(L)<=2*k+1:
    ans = N
for i in range(0,len(L)-k*2-2,2):
    ans = L[i+K*2+1]-L[i]
print(ans)

Fixed submission:
N,K = map(int,input().split())
S = input()
L = [0]
ans = 0
res = '1'
i = 0
for s in S:
    if s != res:
        L.append(i)
        i += 1
    else:
        i += 1
    res = s
L.append(i)
L.append(i)
if len(L)<=2*K+1:
    ans = N
for i in range(0,len(L)-K*2-1,2):
    ans = max(ans,L[i+K*2+1]-L[i])
print(ans)

Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
S = input()+'2'
L = []
if S[0] == '0':
    L.append(1)
for i in range(1,N):
    if S[i] != S[i+1]:
        L.append(i+1)
for i in range(0,len(L)-K*2,2):
    ans = L[i+K*2]-(L[i]-1)#L[i-1]?
ans = 1 if N == 1 else ans
ans = 3 if N == 3 else ans
ans = 2 if N == 2 or S == '010' else ans
print(ans)

Fixed submission:
N,K = map(int,input().split())
S = input()
L = [0]
ans = 0
res = '1'
i = 0
for s in S:
    if s != res:
        L.append(i)
        i += 1
    else:
        i += 1
    res = s
L.append(i)
L.append(i)
if len(L)<=2*K+1:
    ans = N
for i in range(0,len(L)-K*2-1,2):
    ans = max(ans,L[i+K*2+1]-L[i])
print(ans)

Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
S = input()
L = [0]
for i in range(N):
    if S[i] == '0'and a != S[i]:
        L.append(i)
    a = S[i]
L.append(N)
for i in range(len(L)-(K+1)):
    ans = (L[i+(K+1)]-1)-(L[i])
if N == 1:
    ans = 1
elif N == 2 or S == '010':
    ans = 2
elif N == 3:
    ans = 3
    
print(ans)

Fixed submission:
N,K = map(int,input().split())
S = input()
L = [0]
ans = 0
res = '1'
i = 0
for s in S:
    if s != res:
        L.append(i)
        i += 1
    else:
        i += 1
    res = s
L.append(i)
L.append(i)
if len(L)<=2*K+1:
    ans = N
for i in range(0,len(L)-K*2-1,2):
    ans = max(ans,L[i+K*2+1]-L[i])
print(ans)

Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
S = input()
L = [0]
for i in range(N):
    if S[i] == '0'and a != S[i]:
        L.append(i)
    a = S[i]
L.append(N)
for i in range(len(L)-3):
    ans = (L[i+3]-1)-(L[i])
if N == 1:
    ans = 1
elif N == 2 or S == '010':
    ans = 2
elif N == 3:
    ans = 3
    
print(ans)

Fixed submission:
N,K = map(int,input().split())
S = input()
L = [0]
ans = 0
res = '1'
i = 0
for s in S:
    if s != res:
        L.append(i)
        i += 1
    else:
        i += 1
    res = s
L.append(i)
L.append(i)
if len(L)<=2*K+1:
    ans = N
for i in range(0,len(L)-K*2-1,2):
    ans = max(ans,L[i+K*2+1]-L[i])
print(ans)

Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
S = '9'+input()+'9'
S = [int(s) for s in S]
a = S[0]
L = []
for s  in S:
    if s != a:
        L.append(1)
        a = s
    else:
        L.append(0)
        a = S[0]
for i in range(N):
    if N == 1:
        ans = 1
        break
    elif N == 2:
        ans = 2
        break
    if a != S[i]:
        for j in range(i,N):
            if sum(S[i:j]) > K*2:
                ans = j-i
                break

print(ans)

Fixed submission:
N,K = map(int,input().split())
S = input()
L = [0]
ans = 0
res = '1'
i = 0
for s in S:
    if s != res:
        L.append(i)
        i += 1
    else:
        i += 1
    res = s
L.append(i)
L.append(i)
if len(L)<=2*K+1:
    ans = N
for i in range(0,len(L)-K*2-1,2):
    ans = max(ans,L[i+K*2+1]-L[i])
print(ans)