Buggy python submission (verdict: Time Limit Exceeded):
N, K = list(map(int, input().split()))
S = input()
 
S += "X"
j = 0
count = 1
change = [] if S[0] != "0" else [0]
for j in range(len(S)-1):
  if S[j:j+2] == "10":
    change.append(count)
    count = 0
  elif S[j:j+2] == "01":
    change.append(count)
    count = 0
  count += 1

change.append(count-1)
#print(change)
max_len = max([sum(change[i:i+2*K+1]) for i in range(0, len(change), 2)])
  
print(max_len)

Fixed submission:
N, K = list(map(int, input().split()))
S = input()
 
S += "X"
i = 0
j = 0
max_len = 0
change = 0 if S[0] != "0" else 1
while j < len(S)-1:
  if change <= K:
    #print(i, j)
    max_len = max([j-i+1, max_len])
    if S[j:j+2] == "10":
      change += 1
    j += 1
  else:
    if S[i:i+2] == "01":
      change -= 1
    i += 1

print(max_len)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = list(map(int, input().split()))
S = input()
 
S += "X"
j = 0
count = 1
change = [] if S[0] != "0" else [0]
for j in range(len(S)-1):
  if S[j:j+2] == "10":
    change.append(count)
    count = 0
  elif S[j:j+2] == "01":
    change.append(count)
    count = 0
  count += 1

change.append(count-1)
#print(change)
max_len = 0
for i in range(0, len(change), 2):
  #print(i, sum(change[i:i+2*K+1]))
  max_len = max([sum(change[i:i+2*K+1]), max_len])
  
print(max_len)

Fixed submission:
N, K = list(map(int, input().split()))
S = input()
 
S += "X"
i = 0
j = 0
max_len = 0
change = 0 if S[0] != "0" else 1
while j < len(S)-1:
  if change <= K:
    #print(i, j)
    max_len = max([j-i+1, max_len])
    if S[j:j+2] == "10":
      change += 1
    j += 1
  else:
    if S[i:i+2] == "01":
      change -= 1
    i += 1

print(max_len)

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

S += "X"
j = 0
count = 1
change = [] if S[0] != "0" else [0]
while j < len(S)-1:
  if S[j:j+2] == "10":
    change.append(count)
    count = 0
  elif S[j:j+2] == "01":
    change.append(count)
    count = 0
    
  j += 1
  count += 1

change.append(count-1)
i = 0
max_len = 0
while i < len(change):
  max_len = max([sum(change[i:i+2*K+1]), max_len])
  i += 2
  
print(max_len)

Fixed submission:
N, K = list(map(int, input().split()))
S = input()
 
S += "X"
i = 0
j = 0
max_len = 0
change = 0 if S[0] != "0" else 1
while j < len(S)-1:
  if change <= K:
    #print(i, j)
    max_len = max([j-i+1, max_len])
    if S[j:j+2] == "10":
      change += 1
    j += 1
  else:
    if S[i:i+2] == "01":
      change -= 1
    i += 1

print(max_len)

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

S += "X"
j = 0
count = 1
change = [] if S[0] != "0" else [0]
while True:
  if S[j:j+2] == "10":
    change.append(count)
    count = 0
  elif S[j:j+2] == "01":
    change.append(count)
    count = 0
    
  j += 1
  if j == len(S)-1:
    change.append(count)
    break
  count += 1

i = 0
max_len = 0
while i < len(change):
  max_len = max([sum(change[i:i+2*K+1]), max_len])
  i += 2
  
print(max_len)

Fixed submission:
N, K = list(map(int, input().split()))
S = input()
 
S += "X"
i = 0
j = 0
max_len = 0
change = 0 if S[0] != "0" else 1
while j < len(S)-1:
  if change <= K:
    #print(i, j)
    max_len = max([j-i+1, max_len])
    if S[j:j+2] == "10":
      change += 1
    j += 1
  else:
    if S[i:i+2] == "01":
      change -= 1
    i += 1

print(max_len)

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

def search(first, count):
  change = 0
  past = "1"
  for i in range(first, len(S)):
    now = S[i]
    if past != now:
      change += 1
      if change == count*2:
        #print(S[first], S[i])
        for j in range(i, len(S)):
          if "1" != S[j]:
            #print(j, first)
            return j-first
    past = S[i]
  #print(len(S), first)
  return len(S)-first

max_len = 0
past = ""
for i in range(len(S)):
  now = S[i]
  if past != now:
    #print(i, S[i], search(i, K))
    max_len = max([search(i, K), max_len])
  past = S[i] 
  

#print(N, K, S)
print(max_len)

Fixed submission:
N, K = list(map(int, input().split()))
S = input()
 
S += "X"
i = 0
j = 0
max_len = 0
change = 0 if S[0] != "0" else 1
while j < len(S)-1:
  if change <= K:
    #print(i, j)
    max_len = max([j-i+1, max_len])
    if S[j:j+2] == "10":
      change += 1
    j += 1
  else:
    if S[i:i+2] == "01":
      change -= 1
    i += 1

print(max_len)