Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
s = input()
s += '0'
s = '0' + s

t = []
accum_mode = False
l = r = 0

for i in range(1, n + 1):
    if s[i - 1] == '0' and s[i] == '1':
        l = i
    if s[i] == '1' and s[i + 1] == '0':
        r = i
        t.append((l, r))

res = 0

if k < len(t):
    for i in range(len(t) - k):
        tmp = t[i + k][1] - t[i][0]
        res = max(res, tmp)
    if t[0][0] != 1:
        tmp = t[k - 1][1] - 1
        res = max(res, tmp)
else:
    for i in range(len(t)):
        res = t[-1][1] - t[0][0]
    if t[0][0] != 1:
        tmp = t[min(k, len(t))-1][1] - 1
        res = max(res, tmp)

print(res + 1)

Fixed submission:
n, k = map(int, input().split())
s = input()
s += '0'
s = '0' + s

t = []
l = r = 0

for i in range(1, n + 1):
    if s[i - 1] == '0' and s[i] == '1':
        l = i
    if s[i] == '1' and s[i + 1] == '0':
        r = i
        t.append((l, r))

if len(t) > 0:
    res = 0

    if k < len(t):
        for i in range(len(t) - k):
            tmp = t[i + k][1] - t[i][0]
            res = max(res, tmp)
        if t[0][0] != 1:
            tmp = t[k - 1][1] - 1
            res = max(res, tmp)
        if t[-1][1] != n:
            tmp = n - t[-k][0]
            res = max(res, tmp)
    else:
        for i in range(len(t)):
            res = t[-1][1] - t[0][0]
        if t[0][0] != 1:
            tmp = t[min(k, len(t))-1][1] - 1
            res = max(res, tmp)
        if t[-1][1] != n:
            tmp = n - t[-min(k,len(t))][0]
            res = max(res, tmp)

    print(res + 1)
else:
    print(n)

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
s = input()
s += '0'
s = '0' + s

t = []
accum_mode = False
l = r = 0

for i in range(1, n + 1):
    if s[i - 1] == '0' and s[i] == '1':
        l = i
    if s[i] == '1' and s[i + 1] == '0':
        r = i
        t.append((l, r))

res = 0

if k < len(t):
    for i in range(len(t) - k):
        tmp = t[i + k][1] - t[i][0]
        res = max(res, tmp)
    if t[0][0] != 1:
        tmp = t[k - 1][1]
        res = max(res, tmp)
else:
    for i in range(len(t)):
        res = t[-1][1] - t[0][0]
    if t[0][0] != 1:
        tmp = t[min(k, len(t))-1][1]
        res = max(res, tmp)

print(res)

Fixed submission:
n, k = map(int, input().split())
s = input()
s += '0'
s = '0' + s

t = []
l = r = 0

for i in range(1, n + 1):
    if s[i - 1] == '0' and s[i] == '1':
        l = i
    if s[i] == '1' and s[i + 1] == '0':
        r = i
        t.append((l, r))

if len(t) > 0:
    res = 0

    if k < len(t):
        for i in range(len(t) - k):
            tmp = t[i + k][1] - t[i][0]
            res = max(res, tmp)
        if t[0][0] != 1:
            tmp = t[k - 1][1] - 1
            res = max(res, tmp)
        if t[-1][1] != n:
            tmp = n - t[-k][0]
            res = max(res, tmp)
    else:
        for i in range(len(t)):
            res = t[-1][1] - t[0][0]
        if t[0][0] != 1:
            tmp = t[min(k, len(t))-1][1] - 1
            res = max(res, tmp)
        if t[-1][1] != n:
            tmp = n - t[-min(k,len(t))][0]
            res = max(res, tmp)

    print(res + 1)
else:
    print(n)