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

# 奇数番目は1のカタマリの人数　偶数番目は0のカタマリの人数 両端は必ず1のカタマリの人数
now_state, now_count = '1', 0
L = []
Ladd = L.append
for i in range(len(S)):
  if S[i] == now_state:
    now_count += 1
  else:
    Ladd(now_count)
    # reset
    now_count = 1
    now_state = '1' if now_state == '0' else '0'
Ladd(now_count)
if now_state == '0':
  Ladd(0)

j = min(int((len(L)-1)/2), K) # 0のカタマリをひっくり返せるだけひっくり返す
print(max([sum(L[i:i+j*2+1]) for i in range(len(L)-j*2) if i%2==0]))

Fixed submission:
N,K = map(int, input().strip().split(' '))
S = input().strip()
l,r,now_max,now_zeros = 0,0,1,0
for r in range(1,N):
  if S[r-1] == '0':
    if S[r] == '0':
      continue
    else:
      now_zeros += 1
  else:
    if S[r] == '0':
      if now_zeros < K:
        continue
      else:
        now_max = max(r-l, now_max)
        now_zeros -= 1
        for _ in range(l,r):
          l += 1
          if S[l-1:l+1] == '01':
            break
    else:
      continue
now_max = max(r-l+1, now_max)
print(now_max)

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

# 奇数番目は1のカタマリの人数　偶数番目は0のカタマリの人数 両端は必ず1のカタマリの人数
now_state, now_count = '1', 0
L = []
Ladd = L.append
for i in range(len(S)):
  if S[i] == now_state:
    now_count += 1
  else:
    Ladd(now_count)
    # reset
    now_count = 1
    now_state = '1' if now_state == '0' else '0'
Ladd(now_count)
if now_state == '0':
  Ladd(0)

#print(L)
# 0の塊をj個ひっくり返す
# j==1のとき101の3個の和の最大
# j==2のとき10101の5個の和の最大
# j==jのとき101...1のj*2+1個の和の最大

def evenngram(n, _list):
  return [_list[i:i+n] for i in range(len(_list)-n+1) if i%2==0]

j = min(int((len(L)-1)/2), K) # 0のカタマリをひっくり返せるだけひっくり返す
tmp = evenngram(j*2+1, L)
tmp = max([sum(t) for t in tmp])
print(tmp)



Fixed submission:
N,K = map(int, input().strip().split(' '))
S = input().strip()
l,r,now_max,now_zeros = 0,0,1,0
for r in range(1,N):
  if S[r-1] == '0':
    if S[r] == '0':
      continue
    else:
      now_zeros += 1
  else:
    if S[r] == '0':
      if now_zeros < K:
        continue
      else:
        now_max = max(r-l, now_max)
        now_zeros -= 1
        for _ in range(l,r):
          l += 1
          if S[l-1:l+1] == '01':
            break
    else:
      continue
now_max = max(r-l+1, now_max)
print(now_max)

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

# 奇数番目は1のカタマリの人数　偶数番目は0のカタマリの人数 両端は必ず1のカタマリの人数
now_state, now_count = '1', 0
L = []
Ladd = L.append
for i in range(len(S)):
  if S[i] == now_state:
    now_count += 1
  else:
    Ladd(now_count)
    # reset
    now_count = 1
    now_state = '1' if now_state == '0' else '0'
Ladd(now_count)
if now_state == '0':
  Ladd(0)

#print(L)
# 0の塊をj個ひっくり返す
# j==1のとき101の3個の和の最大
# j==2のとき10101の5個の和の最大
# j==jのとき101...1のj*2+1個の和の最大

def evenngram(n, _list):
  return [_list[i:i+n] for i in range(len(_list)-n+1) if i%2==0]

now_max = 0
j = min(int((len(L)-1)/2), K) # 0のカタマリをひっくり返せるだけひっくり返す
tmp = evenngram(j*2+1, L)
tmp = [sum(t) for t in tmp]
tmp = max(tmp) if len(tmp) > 0 else 0
now_max = max(tmp, now_max)
print(now_max)


Fixed submission:
N,K = map(int, input().strip().split(' '))
S = input().strip()
l,r,now_max,now_zeros = 0,0,1,0
for r in range(1,N):
  if S[r-1] == '0':
    if S[r] == '0':
      continue
    else:
      now_zeros += 1
  else:
    if S[r] == '0':
      if now_zeros < K:
        continue
      else:
        now_max = max(r-l, now_max)
        now_zeros -= 1
        for _ in range(l,r):
          l += 1
          if S[l-1:l+1] == '01':
            break
    else:
      continue
now_max = max(r-l+1, now_max)
print(now_max)

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

# 奇数番目は1のカタマリの人数　偶数番目は0のカタマリの人数 両端は必ず1のカタマリの人数
now_state, now_count = '1', 0
L = []
for i in range(len(S)):
  if S[i] == now_state:
    now_count += 1
  else:
    L.append(now_count)
    # reset
    now_count = 1
    now_state = '1' if now_state == '0' else '0'
L.append(now_count)
if now_state == '0':
  L.append(0)

#print(L)
# 0の塊をj個ひっくり返す
# j==1のとき101の3個の和の最大
# j==2のとき10101の5個の和の最大
# j==jのとき101...1のj*2+1個の和の最大

def evenngram(n, _list):
  return [_list[i:i+n] for i in range(len(_list)-n+1) if i%2==0]

now_max = 0
j = min(int((len(L)-1)/2), K) # 0のカタマリをひっくり返せるだけひっくり返す
tmp = evenngram(j*2+1, L)
tmp = [sum(t) for t in tmp]
tmp = max(tmp) if len(tmp) > 0 else 0
now_max = max(tmp, now_max)
print(now_max)


Fixed submission:
N,K = map(int, input().strip().split(' '))
S = input().strip()
l,r,now_max,now_zeros = 0,0,1,0
for r in range(1,N):
  if S[r-1] == '0':
    if S[r] == '0':
      continue
    else:
      now_zeros += 1
  else:
    if S[r] == '0':
      if now_zeros < K:
        continue
      else:
        now_max = max(r-l, now_max)
        now_zeros -= 1
        for _ in range(l,r):
          l += 1
          if S[l-1:l+1] == '01':
            break
    else:
      continue
now_max = max(r-l+1, now_max)
print(now_max)

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

# 奇数番目は1のカタマリの人数　偶数番目は0のカタマリの人数 両端は必ず1のカタマリの人数
now_state, now_count = '1', 0
L = []
for i in range(len(S)):
  if S[i] == now_state:
    now_count += 1
  else:
    L.append(now_count)
    # reset
    now_count = 1
    now_state = '1' if now_state == '0' else '0'
L.append(now_count)
if now_state == '0':
  L.append(0)

#print(L)
# 0の塊をj個ひっくり返す
# j==1のとき101の3個の和の最大
# j==2のとき10101の5個の和の最大
# j==jのとき101...1のj*2+1個の和の最大

def ngram(n, _list):
  return [_list[i:i+n] for i in range(len(_list)-n+1)]

now_max = 0
j = min(int((len(L)-1)/2), K)
tmp = ngram(j*2+1, L)
# 偶数番目だけ
tmp = [sum(tmp[i]) for i in range(len(tmp)) if i%2 == 0]
tmp = max(tmp) if len(tmp) > 0 else 0
now_max = max(tmp, now_max)
print(now_max)

Fixed submission:
N,K = map(int, input().strip().split(' '))
S = input().strip()
l,r,now_max,now_zeros = 0,0,1,0
for r in range(1,N):
  if S[r-1] == '0':
    if S[r] == '0':
      continue
    else:
      now_zeros += 1
  else:
    if S[r] == '0':
      if now_zeros < K:
        continue
      else:
        now_max = max(r-l, now_max)
        now_zeros -= 1
        for _ in range(l,r):
          l += 1
          if S[l-1:l+1] == '01':
            break
    else:
      continue
now_max = max(r-l+1, now_max)
print(now_max)

Buggy python submission (verdict: Runtime Error):
N,K = map(int, input().strip().split(' '))
S = input().strip()

# 奇数番目は1のカタマリの人数　偶数番目は0のカタマリの人数 両端は必ず1のカタマリの人数
now_state, now_count = '1', 0
L = []
for i in range(len(S)):
  if S[i] == now_state:
    now_count += 1
  else:
    L.append(now_count)
    # reset
    now_count = 1
    now_state = '1' if now_state == '0' else '0'
L.append(now_count)
if now_state == '0':
  L.append(0)

#print(L)
# 0の塊をj個ひっくり返す
# j==1のとき101の3個の和の最大
# j==2のとき10101の5個の和の最大
# j==jのとき101...1のj*2+1個の和の最大

def ngram(n, _list):
  return [_list[i:i+n] for i in range(len(_list)-n+1)]

now_max = 0
j = min((len(L)-1)/2, K)
tmp = ngram(j*2+1, L)
# 偶数番目だけ
tmp = [sum(tmp[i]) for i in range(len(tmp)) if i%2 == 0]
tmp = max(tmp) if len(tmp) > 0 else 0
now_max = max(tmp, now_max)
print(now_max)



Fixed submission:
N,K = map(int, input().strip().split(' '))
S = input().strip()
l,r,now_max,now_zeros = 0,0,1,0
for r in range(1,N):
  if S[r-1] == '0':
    if S[r] == '0':
      continue
    else:
      now_zeros += 1
  else:
    if S[r] == '0':
      if now_zeros < K:
        continue
      else:
        now_max = max(r-l, now_max)
        now_zeros -= 1
        for _ in range(l,r):
          l += 1
          if S[l-1:l+1] == '01':
            break
    else:
      continue
now_max = max(r-l+1, now_max)
print(now_max)

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

# 奇数番目は1のカタマリの人数　偶数番目は0のカタマリの人数 両端は必ず1のカタマリの人数
now_state, now_count = '1', 0
L = []
for i in range(len(S)):
  if S[i] == now_state:
    now_count += 1
  else:
    L.append(now_count)
    # reset
    now_count = 1
    now_state = '1' if now_state == '0' else '0'
L.append(now_count)
if now_state == '0':
  L.append(0)

#print(L)
# 0の塊をj個ひっくり返す
# j==1のとき101の3個の和の最大
# j==2のとき10101の5個の和の最大
# j==jのとき101...1のj*2+1個の和の最大

def ngram(n, _list):
  return [_list[i:i+n] for i in range(len(_list)-n+1)]

now_max = 0
for j in range(0,K+1):
  tmp = ngram(j*2+1, L)
  # 偶数番目だけ
  tmp = [sum(tmp[i]) for i in range(len(tmp)) if i%2 == 0]
  tmp = max(tmp) if len(tmp) > 0 else 0
  #print(tmp)
  #tmp = [sum(t) for t in tmp]
  #print(tmp)
  #tmp = max(tmp)
  #print(j,tmp)
  now_max = max(tmp, now_max)
print(now_max)





Fixed submission:
N,K = map(int, input().strip().split(' '))
S = input().strip()
l,r,now_max,now_zeros = 0,0,1,0
for r in range(1,N):
  if S[r-1] == '0':
    if S[r] == '0':
      continue
    else:
      now_zeros += 1
  else:
    if S[r] == '0':
      if now_zeros < K:
        continue
      else:
        now_max = max(r-l, now_max)
        now_zeros -= 1
        for _ in range(l,r):
          l += 1
          if S[l-1:l+1] == '01':
            break
    else:
      continue
now_max = max(r-l+1, now_max)
print(now_max)