Buggy python submission (verdict: Time Limit Exceeded):
def cul(lst, m):
    r = 0
    for i in lst:
        r  += i if i < m else m
    return r

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

a = 1
for i in range(1, len(s)):
    if s[i-1] == s[i]:
        a += 1
    else:
        val.append(a)
        a = 1
val.append(a)
ans = []
now = int(s[0])
for i in range(len(s)-k):
    ins = 0
    lst = val[i:i+k*2] if now == 0 else val[i:i+k*2+1]
    if len(lst) == 0: break
    ans.append(cul(lst, n))
    now = 1 if now == 0 else 0

print(max(ans) if not len(ans) == 0 else len(s))

Fixed submission:
n, k = map(int,input().split())
s = input()
nums = []

now = 1
cnt = 0
for i in range(len(s)):
    if s[i] == str(now): cnt += 1
    else:
        nums.append(cnt)
        now = 1 - now
        cnt = 1
if not cnt == 0: nums.append(cnt)
if len(nums) % 2 == 0: nums.append(0)

summ = [0]
for i in range(len(nums)):
    summ.append(summ[i]+nums[i])

ans = 0
for i in range(len(nums))[::2]:
    left = i
    right = min(i+k*2+1, len(nums))
    tmp = summ[right] - summ[left]

    ans = max(tmp, ans)


print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def cul(lst, m):
    r = 0
    for i in lst:
        r  += i if i < m else m
    return r

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

a = 1
for i in range(1, len(s)):
    if s[i-1] == s[i]:
        a += 1
    else:
        val.append(a)
        a = 1
val.append(a)
ans = []
now = int(s[0])
for i in range(len(s)-k):
    ins = 0
    lst = val[i:i+k*2] if now == 0 else val[i:i+k*2+1]
    ans.append(cul(lst, n))
    now = 1 if now == 0 else 0

print(max(ans) if not len(ans) == 0 else len(s))

Fixed submission:
n, k = map(int,input().split())
s = input()
nums = []

now = 1
cnt = 0
for i in range(len(s)):
    if s[i] == str(now): cnt += 1
    else:
        nums.append(cnt)
        now = 1 - now
        cnt = 1
if not cnt == 0: nums.append(cnt)
if len(nums) % 2 == 0: nums.append(0)

summ = [0]
for i in range(len(nums)):
    summ.append(summ[i]+nums[i])

ans = 0
for i in range(len(nums))[::2]:
    left = i
    right = min(i+k*2+1, len(nums))
    tmp = summ[right] - summ[left]

    ans = max(tmp, ans)


print(ans)

Buggy python submission (verdict: Runtime Error):
def cul(lst, m):
    r = 0
    for i in lst:
        r  += i if i < m else m
    return r

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

if len(s) == 1:
    print(1)

a = 1
for i in range(1, len(s)):
    if s[i-1] == s[i]:
        a += 1
    else:
        val.append(a)
        a = 1
val.append(a)
ans = []
now = int(s[0])
for i in range(len(s)-k):
    lst = val[i:i+k*2+1]
    if now == 1:
        ans.append(cul(lst, n))
    now = 1 if now == 0 else 0
print(max(ans))

Fixed submission:
n, k = map(int,input().split())
s = input()
nums = []

now = 1
cnt = 0
for i in range(len(s)):
    if s[i] == str(now): cnt += 1
    else:
        nums.append(cnt)
        now = 1 - now
        cnt = 1
if not cnt == 0: nums.append(cnt)
if len(nums) % 2 == 0: nums.append(0)

summ = [0]
for i in range(len(nums)):
    summ.append(summ[i]+nums[i])

ans = 0
for i in range(len(nums))[::2]:
    left = i
    right = min(i+k*2+1, len(nums))
    tmp = summ[right] - summ[left]

    ans = max(tmp, ans)


print(ans)