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

kukan = []
cnt0 = 0
cnt1 = 0
for n in range(N):
        if S[n] == '0':
                cnt0 +=1
                if cnt1 > 0:
                        kukan.append(cnt1)
                cnt1 = 0
        if S[n] == '1':
                cnt1 +=1
                if cnt0 > 0:
                        kukan.append(cnt0)
                cnt0 = 0
kukan.append(max(cnt1,cnt0))

#print(kukan)
ans = []

if S[0] == '0':
        start = 1
else:
        start = 0
l = len(kukan)
if l == 1:
        print(N)
        exit()

for i in range(l-K):
        if (i+start)%2 == 0:
                #print(i+2*K)
                ans.append(sum(kukan[i:min(l+1,i+2*K+1)]))
        else:
                #print(i+2*K-1)
                ans.append(sum(kukan[i:min(l+1,i+2*K)]))

print(max(ans))

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

kukan = []
cnt0 = 0
cnt1 = 0
for n in range(N):
        if S[n] == '0':
                cnt0 +=1
                if cnt1 > 0:
                        kukan.append(cnt1)
                cnt1 = 0
        if S[n] == '1':
                cnt1 +=1
                if cnt0 > 0:
                        kukan.append(cnt0)
                cnt0 = 0

kukan.append(max(cnt1,cnt0))

#print(kukan)
ans = []

if S[0] == '0':
        start = 1
else:
        start = 0

l = len(kukan)

if l == 1:
        print(N)
        exit()

cnt = [0]*(l+1)
for i in range(1,l+1):
        cnt[i] = cnt[i-1] + kukan[i-1]

#print(cnt)
        


for i in range(1,l-K+1):
        if (i+start)%2 == 1:
                #print(i+2*K)
                ans.append(cnt[min(l,i+2*K)]-cnt[i-1])
        else:
                #print(i+2*K-1)
                ans.append(cnt[min(l,i+2*K-1)]-cnt[i-1])


print(max(ans))

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

kukan = []
cnt0 = 0
cnt1 = 0
for n in range(N):
        if S[n] == '0':
                cnt0 +=1
                if cnt1 > 0:
                        kukan.append(cnt1)
                cnt1 = 0
        if S[n] == '1':
                cnt1 +=1
                if cnt0 > 0:
                        kukan.append(cnt0)
                cnt0 = 0
kukan.append(max(cnt1,cnt0))

#print(kukan)
ans = []

if S[0] == '0':
        start = 1
else:
        start = 0
l = len(kukan)
if l == 1:
        print(N)
        exit()

for i in range(l-K):
        if (i+start)%2 == 0:
                #print(i+2*K)
                ans.append(sum(kukan[i:min(l+1,i+2*K+1)]))
        if (i+start)%2 == 1:
                #print(i+2*K-1)
                ans.append(sum(kukan[i:min(l+1,i+2*K)]))

print(max(ans))

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

kukan = []
cnt0 = 0
cnt1 = 0
for n in range(N):
        if S[n] == '0':
                cnt0 +=1
                if cnt1 > 0:
                        kukan.append(cnt1)
                cnt1 = 0
        if S[n] == '1':
                cnt1 +=1
                if cnt0 > 0:
                        kukan.append(cnt0)
                cnt0 = 0

kukan.append(max(cnt1,cnt0))

#print(kukan)
ans = []

if S[0] == '0':
        start = 1
else:
        start = 0

l = len(kukan)

if l == 1:
        print(N)
        exit()

cnt = [0]*(l+1)
for i in range(1,l+1):
        cnt[i] = cnt[i-1] + kukan[i-1]

#print(cnt)
        


for i in range(1,l-K+1):
        if (i+start)%2 == 1:
                #print(i+2*K)
                ans.append(cnt[min(l,i+2*K)]-cnt[i-1])
        else:
                #print(i+2*K-1)
                ans.append(cnt[min(l,i+2*K-1)]-cnt[i-1])


print(max(ans))

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

kukan = []
cnt0 = 0
cnt1 = 0
for n in range(N):
        if S[n] == '0':
                cnt0 +=1
                if cnt1 > 0:
                        kukan.append(cnt1)
                cnt1 = 0
        if S[n] == '1':
                cnt1 +=1
                if cnt0 > 0:
                        kukan.append(cnt0)
                cnt0 = 0
kukan.append(max(cnt1,cnt0))

#print(kukan)
ans = []

if S[0] == '0':
        start = 1
else:
        start = 0
l = len(kukan)
if l == 1:
        print(N)
        exit()

for i in range(l-K):
        if (i+start)%2 == 0:
                #print(i+2*K)
                ans.append(sum(kukan[i:min(l+1,i+2*K+1)]))
        if (i+start)%2 == 1:
                #print(i+2*K-1)
                ans.append(sum(kukan[i:min(l+1,i+2*K)]))

print(max(ans))

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

kukan = []
cnt0 = 0
cnt1 = 0
for n in range(N):
        if S[n] == '0':
                cnt0 +=1
                if cnt1 > 0:
                        kukan.append(cnt1)
                cnt1 = 0
        if S[n] == '1':
                cnt1 +=1
                if cnt0 > 0:
                        kukan.append(cnt0)
                cnt0 = 0

kukan.append(max(cnt1,cnt0))

#print(kukan)
ans = []

if S[0] == '0':
        start = 1
else:
        start = 0

l = len(kukan)

if l == 1:
        print(N)
        exit()

cnt = [0]*(l+1)
for i in range(1,l+1):
        cnt[i] = cnt[i-1] + kukan[i-1]

#print(cnt)
        


for i in range(1,l-K+1):
        if (i+start)%2 == 1:
                #print(i+2*K)
                ans.append(cnt[min(l,i+2*K)]-cnt[i-1])
        else:
                #print(i+2*K-1)
                ans.append(cnt[min(l,i+2*K-1)]-cnt[i-1])


print(max(ans))