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

current_length = 1
sections = []  # (start_i, end_i)
current_section = (S[0], 1)

max_length = 0

k = 0


def display_section(sections, current_section):
    a = sections[:]
    b = current_section[:]
    a += b
    s = ''
    for section in a:
        s += section[0] * section[1]
    return s


for i in range(1, len(S)):
    t = display_section(sections, [current_section, (S[i], 1)])
    # print(t)
    if S[i - 1] == S[i]:
        current_section = (S[i], current_section[1] + 1)
        current_length += 1
    else:
        if current_section[0] == '0':
            k += 1
            while k > K:
                if sections[0][0] == '0':
                    k -= 1
                current_length -= sections[0][1]
                sections.pop(0)
        sections.append(current_section)

        if current_length > max_length:
            max_length = current_length

        current_section = (S[i], 1)
        current_length += 1

print(max_length)


Fixed submission:
_, K = map(int, input().split())
S = input() + '2'

current_length = 1
sections = []  # (start_i, end_i)
current_section = (S[0], 1)

max_length = 0

k = 0


# def display_section(sections, current_section):
#     a = sections[:]
#     b = current_section[:]
#     a += b
#     s = ''
#     for section in a:
#         s += section[0] * section[1]
#     return s


for i in range(1, len(S)):
    # t = display_section(sections, [current_section, (S[i], 1)])
    # print(t)
    if S[i - 1] == S[i]:
        current_section = (S[i], current_section[1] + 1)
        current_length += 1
    else:
        if current_section[0] == '0':
            if len(sections) > 0 and sections[-1][0] == '1':
                pop = sections.pop(-1)
                sections.append((0, pop[1] + current_section[1]))
            else:
                sections.append(current_section)
            k += 1
            if k > K:
                current_length -= sections[0][1]
                sections.pop(0)
        else:
            sections.append(current_section)

        if current_length > max_length:
            max_length = current_length

        current_section = (S[i], 1)
        current_length += 1

print(max_length)

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

current_length = 1
sections = []  # (start_i, end_i)
current_section = (S[0], 1)

max_length = 0

k = 0


def display_section(sections, current_section):
    a = sections[:]
    b = current_section[:]
    a += b
    s = ''
    for section in a:
        s += section[0] * section[1]
    return s


for i in range(1, len(S)):
    t = display_section(sections, [current_section, (S[i], 1)])
    # print(t)
    if S[i - 1] == S[i]:
        current_section = (S[i], current_section[1] + 1)
        current_length += 1
    else:
        if current_section[0] == '0':
            k += 1
            while k > K:
                if sections[0][0] == '0':
                    k -= 1
                current_length -= sections[0][1]
                sections.pop(0)
        sections.append(current_section)

        if current_length > max_length:
            max_length = current_length

        current_section = (S[i], 1)
        current_length += 1

print(max_length)


Fixed submission:
_, K = map(int, input().split())
S = input() + '2'

current_length = 1
sections = []  # (start_i, end_i)
current_section = (S[0], 1)

max_length = 0

k = 0


# def display_section(sections, current_section):
#     a = sections[:]
#     b = current_section[:]
#     a += b
#     s = ''
#     for section in a:
#         s += section[0] * section[1]
#     return s


for i in range(1, len(S)):
    # t = display_section(sections, [current_section, (S[i], 1)])
    # print(t)
    if S[i - 1] == S[i]:
        current_section = (S[i], current_section[1] + 1)
        current_length += 1
    else:
        if current_section[0] == '0':
            if len(sections) > 0 and sections[-1][0] == '1':
                pop = sections.pop(-1)
                sections.append((0, pop[1] + current_section[1]))
            else:
                sections.append(current_section)
            k += 1
            if k > K:
                current_length -= sections[0][1]
                sections.pop(0)
        else:
            sections.append(current_section)

        if current_length > max_length:
            max_length = current_length

        current_section = (S[i], 1)
        current_length += 1

print(max_length)