Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
S = input()

if S[N-1] == '1':
    S += '0'
else:
    S += '1'

memo = []
now = S[0]
cnt = 1
for i in range(N):
    if S[i+1] == now:
        cnt += 1
    else:
        memo.append(cnt)
        cnt += 1
        now = S[i+1]

m = 0
l = []
if S[0] == '1':
    for i in range(len(memo)):
        if i%2 == 0:
            l.append(memo[i+2*K+1]-memo[i])
        else:
            l.append(memo[i+2*K]-memo[i])



        # if s > m:
        #     m = s
else:
    for i in range(len(memo)):
        if i%2 == 1:
            l.append(memo[i+2*K+1]-memo[i])
        else:
            l.append(memo[i+2*K]-memo[i])


        # if s > m:
        #     m = s

print(max(l))

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

if S[N-1] == '1':
    S += '0'
else:
    S += '1'

memo = [1]
now = S[0]
cnt = 1
for i in range(N):
    if S[i+1] == now:
        cnt += 1
    else:
        cnt += 1
        memo.append(cnt)
        now = S[i+1]

n = len(memo)
for i in range(2*K+1):
    memo.append(N+1)

m = 0
l = []
if S[0] == '1':
    for i in range(n):
        if i%2 == 0:
            l.append(memo[i+2*K+1]-memo[i])
        else:
            l.append(memo[i+2*K]-memo[i])



        # if s > m:
        #     m = s
else:
    for i in range(n):
        if i%2 == 1:
            l.append(memo[i+2*K+1]-memo[i])
        else:
            l.append(memo[i+2*K]-memo[i])


        # if s > m:
        #     m = s

print(max(l))

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

if S[N-1] == '1':
    S += '0'
else:
    S += '1'

memo = []
now = S[0]
cnt = 1
for i in range(N):
    if S[i+1] == now:
        cnt += 1
    else:
        memo.append(cnt)
        cnt = 1
        now = S[i+1]

m = 0
l = []
if S[0] == '1':
    for i in range(len(memo)):
        if i%2 == 0:
            s = sum(memo[i:i+2*K+1])
            l.append(s)
        else:
            s = sum(memo[i:i+2*K])
            l.append(s)



        # if s > m:
        #     m = s
else:
    for i in range(len(memo)):
        if i%2 == 1:
            s = sum(memo[i:i+2*K+1])
            l.append(s)
        else:
            s = sum(memo[i:i+2*K])
            l.append(s)


        # if s > m:
        #     m = s

print(max(l))



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

if S[N-1] == '1':
    S += '0'
else:
    S += '1'

memo = [1]
now = S[0]
cnt = 1
for i in range(N):
    if S[i+1] == now:
        cnt += 1
    else:
        cnt += 1
        memo.append(cnt)
        now = S[i+1]

n = len(memo)
for i in range(2*K+1):
    memo.append(N+1)

m = 0
l = []
if S[0] == '1':
    for i in range(n):
        if i%2 == 0:
            l.append(memo[i+2*K+1]-memo[i])
        else:
            l.append(memo[i+2*K]-memo[i])



        # if s > m:
        #     m = s
else:
    for i in range(n):
        if i%2 == 1:
            l.append(memo[i+2*K+1]-memo[i])
        else:
            l.append(memo[i+2*K]-memo[i])


        # if s > m:
        #     m = s

print(max(l))

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

if S[N-1] == '1':
    S += '0'
else:
    S += '1'

memo = []
now = S[0]
cnt = 1
for i in range(N):
    if S[i+1] == now:
        cnt += 1
    else:
        memo.append(cnt)
        cnt = 1
        now = S[i+1]

max = 0

if S[0] == '1':
    for i in range(len(memo)):
        if i%2 == 0:
            s = sum(memo[i:i+2*K+1])
        else:
            s = sum(memo[i:i+2*K])


        if s > max:
            max = s
else:
    for i in range(len(memo)):
        if i%2 == 1:
            s = sum(memo[i:i+2*K+1])
        else:
            s = sum(memo[i:i+2*K])


        if s > max:
            max = s

print(max)


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

if S[N-1] == '1':
    S += '0'
else:
    S += '1'

memo = [1]
now = S[0]
cnt = 1
for i in range(N):
    if S[i+1] == now:
        cnt += 1
    else:
        cnt += 1
        memo.append(cnt)
        now = S[i+1]

n = len(memo)
for i in range(2*K+1):
    memo.append(N+1)

m = 0
l = []
if S[0] == '1':
    for i in range(n):
        if i%2 == 0:
            l.append(memo[i+2*K+1]-memo[i])
        else:
            l.append(memo[i+2*K]-memo[i])



        # if s > m:
        #     m = s
else:
    for i in range(n):
        if i%2 == 1:
            l.append(memo[i+2*K+1]-memo[i])
        else:
            l.append(memo[i+2*K]-memo[i])


        # if s > m:
        #     m = s

print(max(l))