Buggy python submission (verdict: Runtime Error):

from itertools import groupby
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def ii(): return int(stdin.readline())
def li(): return map(int, stdin.readline().split())
N, K = tuple(li())
S = stdin.readline()
# use window
l, r = 0, 0
cnt = 0
r_iter = groupby(S)
l_iter = groupby(S)
r_next = next(r_iter)
l_next = next(l_iter)
while r < N:
    # print(l, r)
    if K > 0:
        if r_next[0] == '1':
            r += len(list(r_next[1]))
            r_next = next(r_iter)
            cnt = max(cnt, r - l)
            K -= 1
        elif r_next[0] == "0":
            pass
        r += len(list(r_next[1]))
        r_next = next(r_iter)
    elif K == 0 and r_next[0] == "1":
        r += len(list(r_next[1]))
        r_next = next(r_iter)
    else:
        if l_next[0] == "0":
            K += 1
        l += len(list(l_next[1]))
        l_next = next(l_iter)
if K > 0:
    cnt = max(cnt, r-l)
print(cnt)


Fixed submission:

from itertools import groupby
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def ii(): return int(stdin.readline())
def li(): return map(int, stdin.readline().split())
N, K = tuple(li())
S = stdin.readline() + "2"
# use window
l, r = 0, 0
cnt = 0
r_iter = groupby(S)
l_iter = groupby(S)
r_next = next(r_iter)
l_next = next(l_iter)
while r < N:
    # print(l, r, K)
    if K > 0:
        if r_next[0] == '1' and r > 0:
            K -= 1
        r += len(list(r_next[1]))
        r_next = next(r_iter)
        cnt = max(cnt, r - l)
    elif K == 0 and r_next[0] == "1":
        cnt = max(cnt, r - l)
        r += len(list(r_next[1]))
        r_next = next(r_iter)
        cnt = max(cnt, r - l)
    else:
        if l_next[0] == "0":
            K += 1
        l += len(list(l_next[1]))
        l_next = next(l_iter)
# print(l,r,K)
if r_next[0] == '1':
    cnt = max(cnt, r-l)
print(cnt)

Buggy python submission (verdict: Runtime Error):

from itertools import groupby
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def ii(): return int(stdin.readline())
def li(): return map(int, stdin.readline().split())
N, K = tuple(li())
S = stdin.readline() + "2"
# use window
l, r = 0, 0
cnt = 0
r_iter = groupby(S)
l_iter = groupby(S)
r_next = next(r_iter)
l_next = next(l_iter)
while r_next[0] != "2":
    # print(l, r)
    if r_next[0] == '1' and K >= 0:
        r += len(list(r_next[1]))
        r_next = next(r_iter)
        cnt = max(cnt, r - l)
        K -= 1
        continue
    elif K >=0:
        if r_next[0] == "0":
            pass
        r += len(list(r_next[1]))
        r_next = next(r_iter)
        continue
    if l_next[0] == "0":
        K += 1
    elif l_next[0] == "1":
        pass
    l += len(list(l_next[1]))
    l_next = next(l_iter)
if K > 0:
    cnt = max(cnt, r-l)
while K <= 0:
    if l_next[0] == "0":
        K += 1
    elif l_next[0] == "1":
        pass
    l += len(list(l_next[1]))
    l_next = next(l_iter)
    cnt = max(cnt, r-l)
print(cnt)


Fixed submission:

from itertools import groupby
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def ii(): return int(stdin.readline())
def li(): return map(int, stdin.readline().split())
N, K = tuple(li())
S = stdin.readline() + "2"
# use window
l, r = 0, 0
cnt = 0
r_iter = groupby(S)
l_iter = groupby(S)
r_next = next(r_iter)
l_next = next(l_iter)
while r < N:
    # print(l, r, K)
    if K > 0:
        if r_next[0] == '1' and r > 0:
            K -= 1
        r += len(list(r_next[1]))
        r_next = next(r_iter)
        cnt = max(cnt, r - l)
    elif K == 0 and r_next[0] == "1":
        cnt = max(cnt, r - l)
        r += len(list(r_next[1]))
        r_next = next(r_iter)
        cnt = max(cnt, r - l)
    else:
        if l_next[0] == "0":
            K += 1
        l += len(list(l_next[1]))
        l_next = next(l_iter)
# print(l,r,K)
if r_next[0] == '1':
    cnt = max(cnt, r-l)
print(cnt)