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

key=S[0]
cnt=1
count=[]
for i in range(1,N):
  if S[i]==key:
    cnt+=1
  else:
    count.append([key,cnt])
    key=S[i]
    cnt=1
count.append([key,cnt])

if len(count)==1:
  print(N)
  exit()

ans=0
for i in range(len(count)-1):
  if count[i][0]=="0":
    cnt=1
  else:
    cnt=0
  val=count[i][1]
  for j in range(i+1,len(count)):
    if count[j][0]=="0":
      val+=count[j][1]
      cnt+=1
      if cnt==K+1:
        val-=count[j][1]
        break
    else:
      val+=count[j][1]
  ans=max(ans,val)
print(ans)

Fixed submission:
from itertools import accumulate

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

count=[0]
if S[0]=="0":
    count.append(0)

s=S[0]
cnt=0
for i in range(N):
    if s==S[i]:
        cnt+=1
    else:
        count.append(cnt)
        cnt=1
        s=S[i]
count.append(cnt)
if S[N-1]=="0":
    count.append(0)

l=len(count)
count=list(accumulate(count))
ans=0
for i in range(0,l,2):
    ans=max(ans,count[min(l-1,i+2*K+1)]-count[i])
print(ans)

Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
S=input()
A=[]
a=S[0]
count=1
for i in range(1,N):
  if S[i]==a:
    count+=1
  else:
    A.append([a,count])
    count=1
    a=S[i]
A.append([a,count])
B=[]
C=[]
for i in range(len(A)):
  if A[i][0]=='0':
    B.append(A[i][1])
  else:
    C.append(A[i][1])
if K>=len(B):
  print(sum(B)+sum(C))
else:
  D=[]
  if S[0]=='0':
    D.append(sum(B[:K])+sum(C[:K]))
    if len(B)==len(C):
      for i in range(1,len(B)-K+1):
        D.append(sum(B[i:K+i])+sum(C[i-1:K+i]))
        prin(max(D))
    else:
      for i in range(1,len(B)-K):
        D.append(sum(B[i:K+i])+sum(C[i-1:K+i]))
      D.append(sum(B[len(B)-K:len(B)+1])+sum(C[len(B)-K-1:len(B)]))
      print(max(D))
  else:
    if len(C)>len(B):
      for i in range(len(B)-K+1):
        D.append(sum(B[i:K+i])+sum(C[i:K+i+1]))
      print(max(D))
    else:
      for i in range(len(B)-K):
        D.append(sum(B[i:K+i])+sum(C[i:K+i+1]))
      D.append(sum(B[len(B)-K:len(B)+1])+sum(C[len(B)-K:len(B)+1]))
      print(max(D))

Fixed submission:
from itertools import accumulate

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

count=[0]
if S[0]=="0":
    count.append(0)

s=S[0]
cnt=0
for i in range(N):
    if s==S[i]:
        cnt+=1
    else:
        count.append(cnt)
        cnt=1
        s=S[i]
count.append(cnt)
if S[N-1]=="0":
    count.append(0)

l=len(count)
count=list(accumulate(count))
ans=0
for i in range(0,l,2):
    ans=max(ans,count[min(l-1,i+2*K+1)]-count[i])
print(ans)

Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
S=input()
A=[]
a=S[0]
count=1
for i in range(1,N):
  if S[i]==a:
    count+=1
  else:
    A.append([a,count])
    count=1
    a=S[i]
A.append([a,count])
B=[]
C=[]
for i in range(len(A)):
  if A[i][0]=='0':
    B.append(A[i][1])
  else:
    C.append(A[i][1])
if K>=len(B):
  print(sum(B)+sum(C))
else:
  D=[]
  if S[0]=='0':
    D.append(sum(B[:K])+sum(C[:K]))
    if len(B)<=len(C):
      for i in range(1,len(B)-K+1):
        D.append(sum(B[i:K+i])+sum(C[i-1:K+i]))
        prin(max(D))
    else:
      for i in range(len(B)-K):
        D.append(sum(B[i:K+i])+sum(C[i-1:K+i]))
      D.append(sum(B[len(B)-K+1:len(B)-K+1])+sum(C[len(B)-K:len(B)-K]))
      print(max(D))
  else:
    D.append(sum(B[:K])+sum(C[:K+1]))
    if len(C)>len(B):
      for i in range(1,len(B)-K+1):
        D.append(sum(B[i:K+i])+sum(C[i:K+i+1]))
      print(max(D))
    else:
      for i in range(1,len(B)-K):
        D.append(sum(B[i:K+i])+sum(C[i:K+i+1]))
      D.append(sum(B[len(B)-K+1:len(B)+1])+sum(C[len(B)-K+1:len(B)+1]))
      print(max(D))
print(D)

Fixed submission:
from itertools import accumulate

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

count=[0]
if S[0]=="0":
    count.append(0)

s=S[0]
cnt=0
for i in range(N):
    if s==S[i]:
        cnt+=1
    else:
        count.append(cnt)
        cnt=1
        s=S[i]
count.append(cnt)
if S[N-1]=="0":
    count.append(0)

l=len(count)
count=list(accumulate(count))
ans=0
for i in range(0,l,2):
    ans=max(ans,count[min(l-1,i+2*K+1)]-count[i])
print(ans)