Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
s = list(input())

seq = []

if s[0] == '1':
    seq.append(0)

prev = s[0]
seq_val = 1
last_seq_length = n
for i in range(1, n):
    if s[i] == prev:
        seq_val += 1
    else:
        last_seq_length -= seq_val
        seq.append(seq_val)
        seq_val = 1
        prev = s[i]

seq += [last_seq_length]

ans = 0
for i in range(len(seq)):
    if i % 2 == 0:
        ans = max(ans, sum(seq[i:i+2*k]))
    else:
        ans = max(ans, sum(seq[i:i+2*k+1]))

print(ans)

Fixed submission:
import itertools

n, k = map(int,input().split())
s = input()
seq = []

if s[0] == '0':
    seq.append(0)

i = 1
seq_cnt = 1
while i != n:
    if s[i] != s[i-1]:
        seq.append(seq_cnt)
        seq_cnt = 1
    else:
        seq_cnt += 1
    i += 1

seq.append(seq_cnt)
if s[-1] == '0':
    seq.append(0)

b = [0] + list(itertools.accumulate(seq))

ans = 0
for left in range(0, len(b), 2):
    right = left + 2*k + 1
    if right >= len(b):
        right = len(b)-1

    ans = max(ans, b[right] - b[left])

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
s = list(input())

seq = []

if s[0] == '1':
    seq.append(0)

prev = s[0]
seq_val = 1
last_seq_length = n
for i in range(1, n):
    if s[i] == prev:
        seq_val += 1
    else:
        last_seq_length -= seq_val
        seq.append(seq_val)
        seq_val = 1
        prev = s[i]

seq += [last_seq_length]

ans = 0
for i in range(n):
    if i % 2 == 0:
        ans = max(ans, sum(seq[i:i+2*k]))
    else:
        ans = max(ans, sum(seq[i:i+2*k+1]))

print(ans)

Fixed submission:
import itertools

n, k = map(int,input().split())
s = input()
seq = []

if s[0] == '0':
    seq.append(0)

i = 1
seq_cnt = 1
while i != n:
    if s[i] != s[i-1]:
        seq.append(seq_cnt)
        seq_cnt = 1
    else:
        seq_cnt += 1
    i += 1

seq.append(seq_cnt)
if s[-1] == '0':
    seq.append(0)

b = [0] + list(itertools.accumulate(seq))

ans = 0
for left in range(0, len(b), 2):
    right = left + 2*k + 1
    if right >= len(b):
        right = len(b)-1

    ans = max(ans, b[right] - b[left])

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
s = list(input())

seq = []

if s[0] == '1':
    seq.append(0)

prev = s[0]
seq_val = 1
for i in range(1, n):
    if s[i] == prev:
        seq_val += 1
    else:
        seq.append(seq_val)
        seq_val = 1
        prev = s[i]

seq += [n-sum(seq)]

ans = 0
for i in range(n):
    if i % 2 == 0:
        # print(seq[i:i+2*k])
        ans = max(ans, sum(seq[i:i+2*k]))
    else:
        # print(seq[i:i+2*k])
        ans = max(ans, sum(seq[i:i+2*k+1]))

print(ans)

Fixed submission:
import itertools

n, k = map(int,input().split())
s = input()
seq = []

if s[0] == '0':
    seq.append(0)

i = 1
seq_cnt = 1
while i != n:
    if s[i] != s[i-1]:
        seq.append(seq_cnt)
        seq_cnt = 1
    else:
        seq_cnt += 1
    i += 1

seq.append(seq_cnt)
if s[-1] == '0':
    seq.append(0)

b = [0] + list(itertools.accumulate(seq))

ans = 0
for left in range(0, len(b), 2):
    right = left + 2*k + 1
    if right >= len(b):
        right = len(b)-1

    ans = max(ans, b[right] - b[left])

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
s = list(input())

seq = []

if s[0] == '1':
    seq.append(0)

prev = s[0]
i = 0
while i < n:
    f = True
    for j in range(i+1, n):
        if s[j] != prev:
            seq.append(j-i)
            f = False
            prev = s[j]
            break
    if f:
        i += 1
    else:
        i = j

last_length = 1
prev = s[-1]
for i, c in enumerate(s[::-1][1:]):
    if c != prev:
        last_length += i
        break
seq += [last_length]

ans = 0
for i in range(n):
    if i % 2 == 0:
        # print(seq[i:i+2*k])
        ans = max(ans, sum(seq[i:i+2*k]))
    else:
        # print(seq[i:i+2*k])
        ans = max(ans, sum(seq[i:i+2*k+1]))

print(ans)

Fixed submission:
import itertools

n, k = map(int,input().split())
s = input()
seq = []

if s[0] == '0':
    seq.append(0)

i = 1
seq_cnt = 1
while i != n:
    if s[i] != s[i-1]:
        seq.append(seq_cnt)
        seq_cnt = 1
    else:
        seq_cnt += 1
    i += 1

seq.append(seq_cnt)
if s[-1] == '0':
    seq.append(0)

b = [0] + list(itertools.accumulate(seq))

ans = 0
for left in range(0, len(b), 2):
    right = left + 2*k + 1
    if right >= len(b):
        right = len(b)-1

    ans = max(ans, b[right] - b[left])

print(ans)