Buggy python submission (verdict: Runtime Error):
import numpy as np

# s = input()
# n = int(input())

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def __call__(self, a, b=None): # calc [a, b) summation by O(1)
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[min(self.n-1, a-1)]
        return res


N, K  = map(int, input().split())

s = input()
ar = np.array(list(map(int, s)))

idx = -1
b = []

for i in np.where(ar[:-1] - ar[1:] != 0)[0]:
    b.append(i-idx)
    idx = i

b.append(N-1-idx)

b_int = Interval(b)

if s[0] == '1':
    print(max(
        b_int(i, i+2*K+1) for i in range(0, b_int.n) if i%2 == 0
    ))    
else:
    res = b_int(0, 2*K)
    print(max(res, max(
        b_int(i, i+2*K+1) for i in range(1, b_int.n) if i%2 == 1
    )))


Fixed submission:
import numpy as np

# s = input()
# n = int(input())

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def __call__(self, a, b=None): # calc [a, b) summation by O(1)
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[min(self.n-1, a-1)]
        return res


N, K  = map(int, input().split())

s = input()
ar = np.array(list(map(int, s)))

idx = -1
b = []

for i in np.where(ar[:-1] - ar[1:] != 0)[0]:
    b.append(i-idx)
    idx = i

b.append(N-1-idx)

b_int = Interval(b)

if s[0] == '1':
    print(max(
        b_int(i, i+2*K+1) for i in range(0, b_int.n) if i%2 == 0
    ))    
else:
    res = b_int(0, 2*K)
    if b_int.n > 1:
        res = max(res,max(
            b_int(i, i+2*K+1) for i in range(1, b_int.n) if i%2 == 1
        ))
    print(res)

Buggy python submission (verdict: Runtime Error):
import numpy as np

# s = input()
# n = int(input())

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def __call__(self, a, b=None): # calc [a, b) summation by O(1)
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[min(self.n-1, a-1)]
        return res


N, K  = map(int, input().split())

s = input()
ar = np.array(list(map(int, s)))

idx = -1
b = []

for i in np.where(ar[:-1] - ar[1:] != 0)[0]:
    b.append(i-idx)
    idx = i

b.append(N-1-idx)

b_int = Interval(b)

if s[0] == '1':
    print(max(
        b_int(i, i+2*K+1) for i in range(0, b_int.n) if i%2 == 0
    ))    
else:
    res = b_int(0, 2*K)
    print(max(res, max(
        b_int(i, i+2*K+1) for i in range(1, b_int.n) if i%2 == 0        
    )))


Fixed submission:
import numpy as np

# s = input()
# n = int(input())

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def __call__(self, a, b=None): # calc [a, b) summation by O(1)
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[min(self.n-1, a-1)]
        return res


N, K  = map(int, input().split())

s = input()
ar = np.array(list(map(int, s)))

idx = -1
b = []

for i in np.where(ar[:-1] - ar[1:] != 0)[0]:
    b.append(i-idx)
    idx = i

b.append(N-1-idx)

b_int = Interval(b)

if s[0] == '1':
    print(max(
        b_int(i, i+2*K+1) for i in range(0, b_int.n) if i%2 == 0
    ))    
else:
    res = b_int(0, 2*K)
    if b_int.n > 1:
        res = max(res,max(
            b_int(i, i+2*K+1) for i in range(1, b_int.n) if i%2 == 1
        ))
    print(res)