Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

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

l = [list(np.repeat(0, K)), list(np.repeat(0, K))]
ans = []
k = [int(s) for s in S]
v0 = 1 if k[0] == 0 else 0
v1 = 1 if k[0] == 1 else 0
for i in range(1, N):
    if (k[i]==0) & (k[i-1]==0):
        v0 += 1
    elif (k[i]==1) & (k[i-1]==0):
        l[0].append(v0)
        v0 = 0
        v1 += 1
    elif (k[i]==0) & (k[i-1]==1):
        l[1].append(v1)
        v1 = 0
        v0 += 1
        
        a = sum(l[0][-K:]+l[1][-K-1:])
        ans.append(a)    
    else:
        v1 += 1
        
for i, v in enumerate([v0, v1]):
    if v > 0:
        l[i].append(v)

if len(l[0])-K <= K:
    print(N)

else:
    a = sum(l[0][-K:]+l[1][-K-1:])
    ans.append(a)
    print(max(ans))

Fixed submission:
import numpy as np

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

l = [[], []]
ans = []
k = [int(s) for s in S]
if k[0] == 0:
    l[1].append(0)
v0 = 1 if k[0] == 0 else 0
v1 = 1 if k[0] == 1 else 0
for i in range(1, N):
    if (k[i]==0) & (k[i-1]==0):
        v0 += 1
    elif (k[i]==1) & (k[i-1]==0):
        l[0].append(v0)
        v0 = 0
        v1 += 1
    elif (k[i]==0) & (k[i-1]==1):
        l[1].append(v1)
        v0 += 1
        v1 = 0 
    else:
        v1 += 1
        
for i, v in enumerate([v0, v1]):
    if v > 0:
        l[i].append(v)
        
if k[0] == 0:
    l[1].append(0)

if len(l[0]) <= K:
    print(N)

else:
    l[0].extend(np.repeat(0,K+1))
    l[1].extend(np.repeat(0,K+1))
    a = sum(l[0][:K]) + sum(l[1][:K+1])
    ans.append(a)
    for i in range(1, len(l[0])-K-1):
        a -= l[0][i-1] + l[1][i-1]
        a += l[0][i+K-1] + l[1][i+K]
        ans.append(a)
    print(max(ans))

Buggy python submission (verdict: Runtime Error):
import numpy as np

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

l = [list(np.repeat(0, K)), list(np.repeat(0, K))]
ans = []
k = [int(s) for s in S]
v0 = 1 if k[0] == 0 else 0
v1 = 1 if k[0] == 1 else 0
for i in range(1, N):
    if (k[i]==0) & (k[i-1]==0):
        v0 += 1
    elif (k[i]==1) & (k[i-1]==0):
        l[0].append(v0)
        v0 = 0
        v1 += 1
    elif (k[i]==0) & (k[i-1]==1):
        l[1].append(v1)
        v1 = 0
        v0 += 1
        
        
        a = sum(l[0][-K:]+l[1][-K-1:])
        ans.append(a)
        
    elif (k[i]==1) & (k[i-1]==1):
        v1 += 1
        
for i, v in enumerate([v0, v1]):
    if v > 0:
        l[i].append(v)

if (v0==0) & (v1>0):
    a = sum(l[0][-K:]+l[1][-K-1:])
    ans.append(a)
    
print(max(ans))

Fixed submission:
import numpy as np

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

l = [[], []]
ans = []
k = [int(s) for s in S]
if k[0] == 0:
    l[1].append(0)
v0 = 1 if k[0] == 0 else 0
v1 = 1 if k[0] == 1 else 0
for i in range(1, N):
    if (k[i]==0) & (k[i-1]==0):
        v0 += 1
    elif (k[i]==1) & (k[i-1]==0):
        l[0].append(v0)
        v0 = 0
        v1 += 1
    elif (k[i]==0) & (k[i-1]==1):
        l[1].append(v1)
        v0 += 1
        v1 = 0 
    else:
        v1 += 1
        
for i, v in enumerate([v0, v1]):
    if v > 0:
        l[i].append(v)
        
if k[0] == 0:
    l[1].append(0)

if len(l[0]) <= K:
    print(N)

else:
    l[0].extend(np.repeat(0,K+1))
    l[1].extend(np.repeat(0,K+1))
    a = sum(l[0][:K]) + sum(l[1][:K+1])
    ans.append(a)
    for i in range(1, len(l[0])-K-1):
        a -= l[0][i-1] + l[1][i-1]
        a += l[0][i+K-1] + l[1][i+K]
        ans.append(a)
    print(max(ans))