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

runlength_one = []
runlength_zero = []
counter = 0
prev = '1'
for s in S:
    if s == prev:
        counter += 1
    else:
        if s == '1':
            runlength_zero.append(counter)
        else:
            runlength_one.append(counter)
        counter = 1
        prev = s
if S[-1] == '1':
    runlength_one.append(counter)
else:
    runlength_zero.append(counter)


max = 0
for i in range(len(runlength_one) - K + 1):
    length = sum(runlength_one[i:i+K+1]) + sum(runlength_zero[i:i+K])
    max = length if max < length else max

if max == 0:
    max = sum(runlength_one) + sum(runlength_zero)

print(str(max))


Fixed submission:
N, K = list(map(int, input().split()))
S = input()

runlength_one = []
runlength_zero = []
counter = 0
prev = '1'
for s in S:
    if s == prev:
        counter += 1
    else:
        if s == '1':
            runlength_zero.append(counter)
        else:
            runlength_one.append(counter)
        counter = 1
        prev = s
if S[-1] == '1':
    runlength_one.append(counter)
else:
    runlength_one.append(0)
    runlength_zero.append(counter)

max = 0
sum_one = 0
sum_zero = 0
for i in range(len(runlength_one)):
    if i + K >= len(runlength_one):
        break

    if i == 0:
        sum_one = sum(runlength_one[0:K + 1])
        sum_zero = sum(runlength_zero[0:K])
    else:
        sum_one = sum_one - runlength_one[i - 1] + runlength_one[i + K]
        sum_zero = sum_zero - runlength_zero[i - 1] + runlength_zero[i + K - 1]
        
    length = sum_one + sum_zero
    max = length if max < length else max

if max == 0:
    max = sum(runlength_one) + sum(runlength_zero)

print(str(max))

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

runlength_one = []
runlength_zero = []
counter = 0
prev = '1'
for s in S:
    if s == prev:
        counter += 1
    else:
        if s == '1':
            runlength_zero.append(counter)
        else:
            runlength_one.append(counter)
        counter = 1
        prev = s
if S[-1] == '1':
    runlength_one.append(counter)
else:
    runlength_zero.append(counter)


max = 0
for i in range(len(runlength_one)):
    length = sum(runlength_one[i:i+K+1]) + sum(runlength_zero[i:i+K])
    max = length if max < length else max

if max == 0:
    max = sum(runlength_one) + sum(runlength_zero)

print(str(max))


Fixed submission:
N, K = list(map(int, input().split()))
S = input()

runlength_one = []
runlength_zero = []
counter = 0
prev = '1'
for s in S:
    if s == prev:
        counter += 1
    else:
        if s == '1':
            runlength_zero.append(counter)
        else:
            runlength_one.append(counter)
        counter = 1
        prev = s
if S[-1] == '1':
    runlength_one.append(counter)
else:
    runlength_one.append(0)
    runlength_zero.append(counter)

max = 0
sum_one = 0
sum_zero = 0
for i in range(len(runlength_one)):
    if i + K >= len(runlength_one):
        break

    if i == 0:
        sum_one = sum(runlength_one[0:K + 1])
        sum_zero = sum(runlength_zero[0:K])
    else:
        sum_one = sum_one - runlength_one[i - 1] + runlength_one[i + K]
        sum_zero = sum_zero - runlength_zero[i - 1] + runlength_zero[i + K - 1]
        
    length = sum_one + sum_zero
    max = length if max < length else max

if max == 0:
    max = sum(runlength_one) + sum(runlength_zero)

print(str(max))

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

runlength_one = []
runlength_zero = []
counter = 0
prev = '1'
for s in S:
    if s == prev:
        counter += 1
    else:
        if s == '1':
            runlength_zero.append(counter)
        else:
            runlength_one.append(counter)
        counter = 1
        prev = s
if S[-1] == '1':
    runlength_one.append(counter)
else:
    runlength_zero.append(counter)


max = 0
for i in range(len(runlength_one)):
    length = sum(runlength_one[i:i+K+1]) + sum(runlength_zero[i:i+K])
    max = length if max < length else max

if max == 0:
    max = sum(runlength_one) + sum(runlength_zero)

print(str(max))


Fixed submission:
N, K = list(map(int, input().split()))
S = input()

runlength_one = []
runlength_zero = []
counter = 0
prev = '1'
for s in S:
    if s == prev:
        counter += 1
    else:
        if s == '1':
            runlength_zero.append(counter)
        else:
            runlength_one.append(counter)
        counter = 1
        prev = s
if S[-1] == '1':
    runlength_one.append(counter)
else:
    runlength_one.append(0)
    runlength_zero.append(counter)

max = 0
sum_one = 0
sum_zero = 0
for i in range(len(runlength_one)):
    if i + K >= len(runlength_one):
        break

    if i == 0:
        sum_one = sum(runlength_one[0:K + 1])
        sum_zero = sum(runlength_zero[0:K])
    else:
        sum_one = sum_one - runlength_one[i - 1] + runlength_one[i + K]
        sum_zero = sum_zero - runlength_zero[i - 1] + runlength_zero[i + K - 1]
        
    length = sum_one + sum_zero
    max = length if max < length else max

if max == 0:
    max = sum(runlength_one) + sum(runlength_zero)

print(str(max))