Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
w=input()
l=[]
c=0
w="1"+w
for i in range(1,1+n):
  if w[i]!=w[i-1]:
    l.append(c)
    c=1
  else:
    c+=1
l.append(c)
if w[-1]=="0":
  l.append(0)
s=l[0]
for i in range(1,1+k):
  s+=l[2*i]+l[2*i-1]
s1=s
c1=l[0]+l[1]
for i in range(1,(len(l)+1)//2-k):
  s1=s1-l[2*i-2]-l[2*i-1]+l[2*i-1+2*k]+l[2*i+2*k]
  if s1>s:
    s=s1
print(s)

Fixed submission:
n,k=map(int,input().split())
l=input()
b=True
if l[0]=="1":
  b=True
else:
  b=False
l1=[]
c=1
l11=l[0]
for i in range(1,len(l)):
  if l[i]!=l[i-1]:
    l1.append(c)
    c=1
  else:
    c+=1
l1.append(c)
if b:
  if k>=len(l1)//2:
    print(n)
  else:
    l2=[]
    c1=0
    for i in range(0,(len(l1)//2)):
      c1+=l1[i*2+1]+l1[i*2]
      l2.append(c1)
    if len(l1)%2==1:
      c2=l2[k-1]+l1[2*k]
      for j in range(k,len(l2)):
        c3=l2[j]-l2[j-k]+l1[2*(j+1)]
        if c3>c2:
          c2=c3
      print(c2)
    else:
      c2=l2[k-1]+l1[2*k]
      for j in range(k,len(l2)-1):
        c3=l2[j]-l2[j-k]+l1[2*(j+1)]
        if c3>c2:
          c2=c3
      c3=l2[-1]-l2[-1-k]
      if c3>c2:
        c2=c3
      print(c2)
else:
  if k>=(len(l1)//2)+1:
    print(n)
  else:
    l2=[l1[0]]
    c1=l1[0]
    if len(l1)%2==1:
      for i in range(1,(len(l1)//2)+1):
        c1+=l1[2*i]+l1[2*i-1]
        l2.append(c1)
      c2=l2[k-1]+l1[2*k-1]
      for i in range(k,len(l2)-1):
        c3=l2[i]-l2[i-k]+l1[i*2+1]
        if c3>c2:
          c2=c3
      c3=l2[len(l2)-1]-l2[len(l2)-1-k]
      if c3>c2:
        c2=c3
      print(c2)
    else:
      for i in range(1,(len(l1)//2)):
        c1+=l1[2*i]+l1[2*i-1]
        l2.append(c1)
      c2=l2[k-1]+l1[2*k-1]
      for i in range(k,len(l2)):
        c3=l2[i]-l2[i-k]+l1[i*2+1]
        if c3>c2:
          c2=c3
      print(c2)

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
w=input()
l=[]
c=0
w="1"+w
for i in range(1,1+n):
  if w[i]!=w[i-1]:
    l.append(c)
    c=1
  else:
    c+=1
l.append(c)
if w[-1]=="0":
  l.append(0)
s=l[0]
for i in range(1,1+k):
  s+=l[2*i]+l[2*i-1]
s1=s
c1=l[0]+l[1]
for i in range(1,(len(l)+1)/2):
  s1=s1-l[2*i-2]-l[2*i-1]+l[2*i-2+2*k+1]+l[2*i+2*k]
  if s1>s:
    s=s1
print(s)
  



Fixed submission:
n,k=map(int,input().split())
l=input()
b=True
if l[0]=="1":
  b=True
else:
  b=False
l1=[]
c=1
l11=l[0]
for i in range(1,len(l)):
  if l[i]!=l[i-1]:
    l1.append(c)
    c=1
  else:
    c+=1
l1.append(c)
if b:
  if k>=len(l1)//2:
    print(n)
  else:
    l2=[]
    c1=0
    for i in range(0,(len(l1)//2)):
      c1+=l1[i*2+1]+l1[i*2]
      l2.append(c1)
    if len(l1)%2==1:
      c2=l2[k-1]+l1[2*k]
      for j in range(k,len(l2)):
        c3=l2[j]-l2[j-k]+l1[2*(j+1)]
        if c3>c2:
          c2=c3
      print(c2)
    else:
      c2=l2[k-1]+l1[2*k]
      for j in range(k,len(l2)-1):
        c3=l2[j]-l2[j-k]+l1[2*(j+1)]
        if c3>c2:
          c2=c3
      c3=l2[-1]-l2[-1-k]
      if c3>c2:
        c2=c3
      print(c2)
else:
  if k>=(len(l1)//2)+1:
    print(n)
  else:
    l2=[l1[0]]
    c1=l1[0]
    if len(l1)%2==1:
      for i in range(1,(len(l1)//2)+1):
        c1+=l1[2*i]+l1[2*i-1]
        l2.append(c1)
      c2=l2[k-1]+l1[2*k-1]
      for i in range(k,len(l2)-1):
        c3=l2[i]-l2[i-k]+l1[i*2+1]
        if c3>c2:
          c2=c3
      c3=l2[len(l2)-1]-l2[len(l2)-1-k]
      if c3>c2:
        c2=c3
      print(c2)
    else:
      for i in range(1,(len(l1)//2)):
        c1+=l1[2*i]+l1[2*i-1]
        l2.append(c1)
      c2=l2[k-1]+l1[2*k-1]
      for i in range(k,len(l2)):
        c3=l2[i]-l2[i-k]+l1[i*2+1]
        if c3>c2:
          c2=c3
      print(c2)

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
l1=list(input())
l=[]
lm=[]
c=0
d=l1[0]
for i in l1:
  if i==d:
    c+=1
  else:
    d=i
    l.append(c)
    c=1
l.append(c)
if l1[0]=="1":
  if len(l)//2<=m:
    print(n)
  else:
    j=0
    for i in range((len(l)-2*m-1)//2+1):
      lm.append(sum(l[j:j+2*m])+l[j+2*m])
      j+=2
      if j+2*m+1>len(l):
        break
    print(max(lm))
else:
  if (len(l)+1)//2<=m:
    print(n)
  else:
    j=1
    for i in range((len(l)-2*m-2)//2+1):
      lm.append(sum(l[j:j+2*m])+l[j+2*m])
      j+=2
      if j+2*m+1>len(l):
        break
    print(max(lm))

Fixed submission:
n,k=map(int,input().split())
l=input()
b=True
if l[0]=="1":
  b=True
else:
  b=False
l1=[]
c=1
l11=l[0]
for i in range(1,len(l)):
  if l[i]!=l[i-1]:
    l1.append(c)
    c=1
  else:
    c+=1
l1.append(c)
if b:
  if k>=len(l1)//2:
    print(n)
  else:
    l2=[]
    c1=0
    for i in range(0,(len(l1)//2)):
      c1+=l1[i*2+1]+l1[i*2]
      l2.append(c1)
    if len(l1)%2==1:
      c2=l2[k-1]+l1[2*k]
      for j in range(k,len(l2)):
        c3=l2[j]-l2[j-k]+l1[2*(j+1)]
        if c3>c2:
          c2=c3
      print(c2)
    else:
      c2=l2[k-1]+l1[2*k]
      for j in range(k,len(l2)-1):
        c3=l2[j]-l2[j-k]+l1[2*(j+1)]
        if c3>c2:
          c2=c3
      c3=l2[-1]-l2[-1-k]
      if c3>c2:
        c2=c3
      print(c2)
else:
  if k>=(len(l1)//2)+1:
    print(n)
  else:
    l2=[l1[0]]
    c1=l1[0]
    if len(l1)%2==1:
      for i in range(1,(len(l1)//2)+1):
        c1+=l1[2*i]+l1[2*i-1]
        l2.append(c1)
      c2=l2[k-1]+l1[2*k-1]
      for i in range(k,len(l2)-1):
        c3=l2[i]-l2[i-k]+l1[i*2+1]
        if c3>c2:
          c2=c3
      c3=l2[len(l2)-1]-l2[len(l2)-1-k]
      if c3>c2:
        c2=c3
      print(c2)
    else:
      for i in range(1,(len(l1)//2)):
        c1+=l1[2*i]+l1[2*i-1]
        l2.append(c1)
      c2=l2[k-1]+l1[2*k-1]
      for i in range(k,len(l2)):
        c3=l2[i]-l2[i-k]+l1[i*2+1]
        if c3>c2:
          c2=c3
      print(c2)