Buggy python submission (verdict: Runtime Error):
def solve():
  n,k = (int(i) for i in input().split())
  s = input()
  one = []
  zero = []  
  for i in range(n):
    if i == 0:
      if s[i] == "0":
        one.append(0)
        zero.append(1)
      else:
        one.append(1)
    
    else:     
     if s[i] == s[i-1]:
      if s[i] == "0":
        zero[-1]+= 1
      else:
        one[-1] += 1
     else:
      if s[i] == "0":
        zero.append(1)
      else:
        one.append(1)
  ans = 0 
  if len(zero) <= k:
    ans = n
  one = one + [0]*5
  zero = zero + [0]*5
  
  tmp = 0
  for i in range(k+1):
   tmp += one[i]
  for i in range(k):
   tmp += zero[i]
  ans = max(tmp,ans)
  for i in range(len(zero)-k-1):
       
       tmp -=  one[i]
       tmp +=  one[i+k+1]
       tmp -=  zero[i]
       tmp +=  zero[i+k]
       ans = max(ans,tmp)

  #print (one) 
 # print(zero)
  print(ans)
    
solve()

Fixed submission:
def solve():
  n,k = (int(i) for i in input().split())
  s = input()
  one = []
  zero = []  
  for i in range(n):
    if i == 0:
      if s[i] == "0":
        one.append(0)
        zero.append(1)
      else:
        one.append(1)
    
    else:     
     if s[i] == s[i-1]:
      if s[i] == "0":
        zero[-1]+= 1
      else:
        one[-1] += 1
     else:
      if s[i] == "0":
        zero.append(1)
      else:
        one.append(1)
  ans = 0 
  if len(zero) <= k:
    ans = n

  else:
   one = one + [0]*5
   zero = zero + [0]*5
   tmp = 0
   for i in range(k+1):
    tmp += one[i]
   for i in range(k):
    tmp += zero[i]
   ans = max(tmp,ans)
   for i in range(len(zero)-k-1):
        
       tmp -=  one[i]
       tmp +=  one[i+k+1]
       tmp -=  zero[i]
       tmp +=  zero[i+k]
       ans = max(ans,tmp)

  #print (one) 
 # print(zero)
  print(ans)
    
solve()

Buggy python submission (verdict: Runtime Error):
def solve():
  n,k = (int(i) for i in input().split())
  s = input()
  one = []
  zero = []  
  for i in range(n):
    if i == 0:
      if s[i] == "0":
        zero.append(1)
      else:
        one.append(1)
    
    else:     
     if s[i] == s[i-1]:
      if s[i] == "0":
        zero[-1]+= 1
      else:
        one[-1] += 1
     else:
      if s[i] == "0":
        #zero.append(0)
        zero.append(1)
      else:
        #one.append(0)
        one.append(1)
  ans = 0 
  if len(zero) <= k:
    ans = n
  elif len(one) > len(zero):
    tmp = 0
    for i in range(k+1):
     tmp += one[i]
    for i in range(k):
     tmp += zero[i]
    for i in range(len(zero)-k):
       
       tmp -=  one[i]
       tmp +=  one[i+k+1]
       tmp -=  zero[i]
       tmp +=  zero[i+k]
       ans = max(ans,tmp)
  else:
    tmp = 0
    for i in range(k):
      tmp += one[i]
    for i in range(k):
      tmp += zero[i]
    ans = max(ans,tmp)
    tmp -= zero[i]
    tmp += zero[i+1]
    ans = max(ans,tmp)
    for i in range(len(zero)-k-1):
       
       tmp -=  one[i]
       tmp +=  one[i+k+1]
       tmp -=  zero[i+1]
       tmp +=  zero[i+2]
       ans = max(ans,tmp)
  print(ans)
    
solve()

Fixed submission:
def solve():
  n,k = (int(i) for i in input().split())
  s = input()
  one = []
  zero = []  
  for i in range(n):
    if i == 0:
      if s[i] == "0":
        one.append(0)
        zero.append(1)
      else:
        one.append(1)
    
    else:     
     if s[i] == s[i-1]:
      if s[i] == "0":
        zero[-1]+= 1
      else:
        one[-1] += 1
     else:
      if s[i] == "0":
        zero.append(1)
      else:
        one.append(1)
  ans = 0 
  if len(zero) <= k:
    ans = n

  else:
   one = one + [0]*5
   zero = zero + [0]*5
   tmp = 0
   for i in range(k+1):
    tmp += one[i]
   for i in range(k):
    tmp += zero[i]
   ans = max(tmp,ans)
   for i in range(len(zero)-k-1):
        
       tmp -=  one[i]
       tmp +=  one[i+k+1]
       tmp -=  zero[i]
       tmp +=  zero[i+k]
       ans = max(ans,tmp)

  #print (one) 
 # print(zero)
  print(ans)
    
solve()