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

sl = []
c = 1
if (s[0] == "1"):
    sl.append(0)
for i in range(n):
    if (i != 0):
        if (s[i] == s[i-1]):
            c += 1
        else:
            sl.append(c)
            c = 1
sl.append(c)

ruisekiwa = [0]
sums = []
for i in range(len(sl)):
    ruisekiwa.append(ruisekiwa[i] + sl[i])
# print(sl)
# print(ruisekiwa)
for i in range(len(sl)):
    if(k % 2 == 1 and i % 2 == 0 or k % 2 == 0 and i % 2 == 1):
        left = i-k
        if (left < 0):
            left = 0
        right = i + k+1
        if (right >= len(ruisekiwa)):
            right = len(ruisekiwa)-1
        # print(ruisekiwa[right], "-", ruisekiwa[left],
        #      "=", ruisekiwa[right]-ruisekiwa[left])
        sums.append(ruisekiwa[right]-ruisekiwa[left])
print(max(sums))

Fixed submission:
n, k = map(int, input().split())
s = str(input())

sl = []
c = 1
if (s[0] == "1"):
    sl.append(0)
for i in range(n):
    if (i != 0):
        if (s[i] == s[i-1]):
            c += 1
        else:
            sl.append(c)
            c = 1
sl.append(c)

ruisekiwa = [0]
sums = []
ans = 0
w = 2*k+1

if (w > len(sl)):
    print(n)
    exit()
for i in range(len(sl)):
    ruisekiwa.append(ruisekiwa[i] + sl[i])
# print(sl)
# print(ruisekiwa)
for i in range(len(sl)):
    if(k % 2 == 1 and i % 2 == 0 or k % 2 == 0 and i % 2 == 1):
        left = i-k
        if (left < 0):
            left = 0
        right = i + k+1
        if (right >= len(ruisekiwa)):
            right = len(ruisekiwa)-1
        # print(ruisekiwa[right], "-", ruisekiwa[left],
        #      "=", ruisekiwa[right]-ruisekiwa[left])
        ans = max(ans, ruisekiwa[right]-ruisekiwa[left])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
s = input()

if(n != 1):
    sl = []
    c = 1
    if (s[0] == "1"):
        sl.append(0)
    for i in range(n):
        if (i != 0):
            if (s[i] == s[i-1]):
                c += 1
            else:
                sl.append(c)
                c = 1
    sl.append(c)
    cl = []
    c = 0
    for i in range(n):
        st = i-k
        ed = i + k+1
        if (st < 0):
            st = 0
        if (k % 2 == 1 and i % 2 == 0 or k % 2 == 0 and i % 2 == 1):  # kが奇数の時、0の箇所（すなわちiが偶数の箇所）を中心に反転
            if (c == 0):
                cl.append(sum(sl[st: ed]))
            else:
                t = cl[c - 1]
                t += sum(sl[ed - 3: ed-1])
                if (st > 0):
                    cst = st-2
                    if (cst < 0):
                        cst = 0
                    t -= sum(sl[cst: st])
                cl.append(t)
                c += 1

    print(max(cl))
else:
    print(1)

Fixed submission:
n, k = map(int, input().split())
s = str(input())

sl = []
c = 1
if (s[0] == "1"):
    sl.append(0)
for i in range(n):
    if (i != 0):
        if (s[i] == s[i-1]):
            c += 1
        else:
            sl.append(c)
            c = 1
sl.append(c)

ruisekiwa = [0]
sums = []
ans = 0
w = 2*k+1

if (w > len(sl)):
    print(n)
    exit()
for i in range(len(sl)):
    ruisekiwa.append(ruisekiwa[i] + sl[i])
# print(sl)
# print(ruisekiwa)
for i in range(len(sl)):
    if(k % 2 == 1 and i % 2 == 0 or k % 2 == 0 and i % 2 == 1):
        left = i-k
        if (left < 0):
            left = 0
        right = i + k+1
        if (right >= len(ruisekiwa)):
            right = len(ruisekiwa)-1
        # print(ruisekiwa[right], "-", ruisekiwa[left],
        #      "=", ruisekiwa[right]-ruisekiwa[left])
        ans = max(ans, ruisekiwa[right]-ruisekiwa[left])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
s = input()

if(n != 1):
    sl = []
    c = 1
    for i in range(n):
        if (i == 0):
            if (s[i] == "1"):
                sl.append(0)
        if (i != 0):
            if (s[i] == s[i-1]):
                c += 1
            else:
                sl.append(c)
                c = 1
    sl.append(c)

    cl = []
    for i in range(n):
        st = i - k
        ed = i + k+1
        if (st < 0):
            st = 0
        if (ed > len(sl)):
            ed = len(sl)
        if (k % 2 == 1):  # kが奇数の時、0の箇所（すなわちiが偶数の箇所）を中心に反転
            if (i % 2 == 0):
                cl.append(sum(sl[st:ed]))
        else:  # kが偶数の時、1の箇所（すなわちiが奇数の箇所）を中心に反転
            if (i % 2 == 1):
                cl.append(sum(sl[st:ed]))

    print(max(cl))
else:
    print(1)

Fixed submission:
n, k = map(int, input().split())
s = str(input())

sl = []
c = 1
if (s[0] == "1"):
    sl.append(0)
for i in range(n):
    if (i != 0):
        if (s[i] == s[i-1]):
            c += 1
        else:
            sl.append(c)
            c = 1
sl.append(c)

ruisekiwa = [0]
sums = []
ans = 0
w = 2*k+1

if (w > len(sl)):
    print(n)
    exit()
for i in range(len(sl)):
    ruisekiwa.append(ruisekiwa[i] + sl[i])
# print(sl)
# print(ruisekiwa)
for i in range(len(sl)):
    if(k % 2 == 1 and i % 2 == 0 or k % 2 == 0 and i % 2 == 1):
        left = i-k
        if (left < 0):
            left = 0
        right = i + k+1
        if (right >= len(ruisekiwa)):
            right = len(ruisekiwa)-1
        # print(ruisekiwa[right], "-", ruisekiwa[left],
        #      "=", ruisekiwa[right]-ruisekiwa[left])
        ans = max(ans, ruisekiwa[right]-ruisekiwa[left])
print(ans)