AtCoder Beginner Contest 124 - Handstand

N people are arranged in a row from left to right.
You are given a string S of length N consisting of 0 and 1, and a positive integer K.
The i-th person from the left is standing on feet if the i-th character of S is 0, and standing on hands if that character is 1.
You will give the following direction at most K times (possibly zero):
Direction: Choose integers l and r satisfying 1 \leq l \leq r \leq N, and flip the l-th, (l+1)-th, ..., and r-th persons. That is, for each i = l, l+1, ..., r, the i-th person from the left now stands on hands if he/she was standing on feet, and stands on feet if he/she was standing on hands.
Find the maximum possible number of consecutive people standing on hands after at most K directions.

-----Constraints-----
 - N is an integer satisfying 1 \leq N \leq 10^5.
 - K is an integer satisfying 1 \leq K \leq 10^5.
 - The length of the string S is N.
 - Each character of the string S is 0 or 1.

-----Input-----
Input is given from Standard Input in the following format:
N K
S

-----Output-----
Print the maximum possible number of consecutive people standing on hands after at most K directions.

-----Sample Input-----
5 1
00010

-----Sample Output-----
4

We can have four consecutive people standing on hands, which is the maximum result, by giving the following direction:
 - Give the direction with l = 1, r = 3, which flips the first, second and third persons from the left.

Difficulty: MEDIUM

Starter code:

Solutions:
(N, K) = map(int, input().split())
s = input()
ls = []
for i in range(N):
	if i != N - 1 and s[i] != s[i + 1]:
		ls += [i]
length = len(ls)
ls += [N - 1] * (2 * K + 2)
m = 0
if s[0] == '0':
	for i in range(0, length, 2):
		x = ls[i + 2 * K + 1] - ls[i]
		if x > m:
			m = x
	x = ls[2 * K - 1] + 1
	if x > m:
		m = x
else:
	for i in range(1, length, 2):
		x = ls[i + 2 * K + 1] - ls[i]
		if x > m:
			m = x
	x = ls[2 * K] + 1
	if x > m:
		m = x
print(m)


(n, k) = map(int, input().split())
s = input()
loc = [1]
for i in range(1, n):
	if s[i] != s[i - 1]:
		loc.append(i + 1)
loc.append(n + 1)
r = len(loc)
x = []
for j in range(r - 1):
	y = loc[j]
	if s[y - 1] == str(0):
		x.append(loc[min(r - 1, j + 2 * k)] - loc[j])
	else:
		x.append(loc[min(r - 1, j + 2 * k + 1)] - loc[j])
print(max(x))


(n, k) = map(int, input().split())
s = input()
l = [['1', 0]]
for i in s:
	if l[-1][0] == i:
		l[-1][1] += 1
	else:
		l.append([i, 1])
if l[-1][0] == '0':
	l.append(['1', 0])
e = [0]
for i in range(len(l)):
	e.append(e[i] + l[i][1])
ans = 0 if k < len(l) // 2 else e[-1]
for i in range(2 * k - 1, len(l), 2):
	ans = max(ans, e[i + 2] - e[i - 2 * k + 1])
print(ans)


(n, k) = map(int, input().split())
s = list(map(int, list(str(input()))))
c = 0
ran = [0, 0]
for i in range(n):
	if s[c] == s[i]:
		ran[-1] += 1
	else:
		ran.append(i + 1)
		c = i
result = []
for i in range(1, len(ran)):
	if s[ran[i - 1]] == 1:
		result.append(ran[min(i + 2 * k, len(ran) - 1)] - ran[i - 1])
	else:
		result.append(ran[min(i + 2 * k - 1, len(ran) - 1)] - ran[i - 1])
print(max(result))


(n, k) = map(int, input().split())
s = input()
c = s[0]
t = 0
l = [0]
for x in s:
	if x == c:
		t += 1
	else:
		l.append(t)
		c = x
		t = 1
f = s[0] == '0'
l.append(t)
m = len(l)
for i in range(1, m):
	l[i] += l[i - 1]
l += [n] * 2 * (k + 1)
ans = l[2 * k] - l[0]
for i in range(f, m + 1, 2):
	ans = max(ans, l[i + 2 * k + 1] - l[i])
print(ans)


from itertools import groupby
(n, k) = list(map(int, input().split()))
s = input()
grouped = groupby(s)
res = []
if s[0] == '0':
	res.append((1, 0))
for (l, v) in grouped:
	res.append((l, len(list(v))))
if s[len(s) - 1] == '0':
	res.append((1, 0))
if len(res) <= 2 * k + 1:
	ans = 0
	for d in res:
		ans += d[1]
	print(ans)
	return
now = 0
ans = 0
for i in range(2 * k + 1):
	now += res[i][1]
ans = max(ans, now)
for i in range(2 * k + 1, len(res), 2):
	now -= res[i - 2 * k - 1][1]
	now -= res[i - 2 * k][1]
	now += res[i][1]
	now += res[i + 1][1]
	ans = max(ans, now)
print(ans)


(n, k) = map(int, input().split())
s = input()
l = [0]
for i in range(n - 1):
	if s[i + 1] != s[i]:
		l.append(i + 1)
l.append(n)
ans = 0
for i in range(len(l) - 1):
	ind = min(i + 2 * k + int(s[l[i]] == '1'), len(l) - 1)
	ans = max(ans, l[ind] - l[i])
print(ans)


(n, k) = map(int, input().split())
s = input()
c = 1
l = []
l += [0, 0] if s[0] == '0' else [0]
for i in range(1, n):
	if s[i - 1] != s[i]:
		l += [c + l[-1]]
		c = 1
	else:
		c += 1
l += [c + l[-1]]
if s[-1] == '0':
	l += [l[-1]]
ll = len(l)
pl = 2 * k + 1
if ll <= pl:
	print(n)
else:
	m = 0
	for i in range(0, ll - pl + 1, 2):
		t = l[pl + i] - l[i]
		m = t if t > m else m
	print(m)


(t, s) = open(0)
(n, k) = map(int, t.split())
i = 0
for j in range(n):
	k -= '1' > s[j] and '0' != s[j - 1]
	if k < 0:
		k += '1' > s[i] and '0' < s[i + 1]
		i += 1
print(n - i)


(N, K) = map(int, input().split())
S = list(map(int, input().strip()))
tmp = S[0]
l = [0]
for i in range(N):
	if S[i] != tmp:
		l.append(i)
		tmp = S[i]
r = len(l)
l.extend([N] * (K * 2 + 1))
x = [0] * r
for i in range(r):
	if S[l[i]] == 0:
		x[i] = l[i + K * 2] - l[i]
	else:
		x[i] = l[i + K * 2 + 1] - l[i]
print(max(x))


(n, k) = map(int, input().split())
s = input()
index_lst = []
num_lst = []
before = '-1'
for (K, i) in enumerate(s):
	if i != before:
		before = i
		index_lst.append(K)
		num_lst.append(int(i))
N = len(index_lst)
index_lst += [n] * (2 * k + 10)
S = 0
for i in range(N):
	S = max(S, index_lst[i + 2 * k] - index_lst[i]) if num_lst[i] == 0 else max(S, index_lst[i + 2 * k + 1] - index_lst[i])
print(S)


from itertools import groupby
from math import ceil
(n, k) = list(map(int, input().split()))
s = input()
block = [sum((1 for _ in it)) for (k, it) in groupby(s)]
if s[0] != '1':
	block.insert(0, 0)
m = len(block)
(left, right) = (0, 2 * k)
res = val = sum(block[left:right - 1])
while right <= m:
	val += block[right - 1] if right == m else block[right - 1] + block[right]
	res = max(res, val)
	val -= block[left] + block[left + 1]
	left += 2
	right += 2
print(res)


from itertools import groupby
(N, K) = [int(i) for i in input().split()]
S = input()
A = [(int(k), len(tuple(v))) for (k, v) in groupby(S)]
M = len(A)
(ans, count) = (0, 0)
r = 0
for (l, (kl, al)) in enumerate(A):
	bound = 2 * K + kl
	while r < M and r - l < bound:
		count += A[r][1]
		r += 1
	ans = max(ans, count)
	count -= al
print(ans)


(n, k) = map(int, input().split())
(*s,) = input()
g = []
t = 1
for i in range(1, n):
	if s[i] == s[i - 1]:
		t += 1
	else:
		g.append(t)
		t = 1
g.append(t)
for i in range(1, len(g)):
	g[i] += g[i - 1]
g = [0] + g + [g[-1]]
a = 0
for i in range(s[0] == '1', len(g), 2):
	a = max(a, g[i] - g[max(0, i - 2 * k - 1)])
print(a)


(n, k) = map(int, input().split())
s = input()
l = []
c = 1
for i in range(n - 1):
	if s[i] != s[i + 1]:
		l.append(c)
		c = 0
	c += 1
l.append(c)
l += [0]
if s[0] == '0':
	l = [0] + l
tmp = sum(l[:2 * k + 1])
rslt = tmp
for i in range(0, len(l) - 2 * k - 2, 2):
	tmp = tmp - l[i] - l[i + 1] + l[i + 2 * k + 1] + l[i + 2 * k + 2]
	rslt = max(tmp, rslt)
print(rslt)


k = int(input().split(' ')[1])
s = input()
arr = []
if s[0] is '0':
	arr.append(0)
arr.append(1)
for i in range(1, len(s)):
	if s[i - 1] is s[i]:
		arr[-1] += 1
	else:
		arr.append(1)
if s[-1] is '0':
	arr.append(0)
sums = [0]
for i in range(len(arr)):
	sums.append(sums[i] + arr[i])
t = 2 * k + 1
m = 0
for i in range(0, len(arr), 2):
	m = max(m, sums[min(len(sums) - 1, i + t)] - sums[i])
print(m)


(N, K) = map(int, input().split())
s = input()
if '0' not in s:
	print(len(s))
else:
	s2 = [0]
	count = 0
	for i in range(len(s) - 1):
		count += 1
		if s[i] != s[i + 1]:
			s2.append(count)
	s2.append(count + 1)
	if s[0] == '0':
		s2.insert(0, 0)
	ans = 0
	for i in range(0, len(s2) - 1, 2):
		ans = max(ans, s2[min(len(s2) - 1, i + 2 * K + 1)] - s2[i])
	print(ans)


(N, K) = map(int, input().split())
S = input()
l = [1]
for i in range(N - 1):
	if S[i] == S[i + 1]:
		l[-1] += 1
	else:
		l.append(1)
if S[0] == '0':
	l = [0] + l
if S[-1] == '0':
	l += [0]
n = len(l)
ans = sum(l[:min(K * 2 + 1, n + 1)])
i = 0
M = ans
while True:
	if K * 2 + i + 1 >= n:
		break
	M = M + l[K * 2 + 1 + i] + l[K * 2 + 1 + i + 1] - l[i] - l[i + 1]
	ans = max(ans, M)
	i += 2
print(ans)


(n, k) = map(int, input().split())
s = '#' + input()
B = []
L = []
for i in range(n):
	if s[i] != s[i + 1]:
		B.append(int(s[i + 1]))
		L.append(i + 1)
ans = 0
for (j, b) in enumerate(B):
	if b == 0:
		if j + 2 * k >= len(L):
			ans = max(ans, n + 1 - L[j])
		else:
			ans = max(ans, L[j + 2 * k] - L[j])
	elif j + 2 * k + 1 >= len(L):
		ans = max(ans, n + 1 - L[j])
	else:
		ans = max(ans, L[j + 2 * k + 1] - L[j])
print(ans)


(n, k) = map(int, input().split())
s = input()
a = []
c = 1
for i in range(n - 1):
	if s[i] == s[i + 1]:
		c += 1
	else:
		a.append(c)
		c = 1
a.append(c)
b = [0]
for i in range(len(a)):
	b.append(b[-1] + a[i])
b.append(b[-1])
n = len(b)
l = 2 * k + 1
st = int(s[0])
ans = 0
for i in range(st, n, 2):
	ans = max(ans, b[i] - b[max(0, i - l)])
print(ans)


(N, K) = map(int, input().split())
S = '0' + input() + '0'
Sl = [0] + [i for i in range(N + 1) if S[i:i + 2] == '01'] + [N]
Sr = [0] + [i for i in range(N + 1) if S[i:i + 2] == '10'] + [N]
if len(Sl) - K >= 1:
	print(max([Sr[i + K] - Sl[i] for i in range(len(Sl) - K)]))
else:
	print(N)


from collections import *
(n, k) = map(int, input().split())
s = input()
q = deque()
tt = 0
f = False
t = 0
ans = 0
tmp = 0
for i in range(n):
	if f:
		if s[i] == '0':
			tmp += 1
			tt += 1
			if tmp > ans:
				ans = tmp
		else:
			q.append(tt)
			f = False
			tt = 1
			tmp += 1
			if tmp > ans:
				ans = tmp
	elif f == False:
		if s[i] == '1':
			tmp += 1
			tt += 1
			if tmp > ans:
				ans = tmp
		else:
			t += 1
			f = True
			if t > k:
				d = q.popleft()
				tmp -= d
			tmp += 1
			tt += 1
print(ans)


(n, k) = map(int, input().split())
s = input()
prev_R = '1'
for R in range(n):
	if (prev_R, s[R]) == ('1', '0'):
		k -= 1
		if k < 0:
			R -= 1
			break
	prev_R = s[R]
ans = R + 1
for L in range(n - 1):
	if (s[L], s[L + 1]) != ('0', '1'):
		continue
	R += 1
	while R < n - 1 and (s[R], s[R + 1]) != ('1', '0'):
		R += 1
	if ans < R - L:
		ans = R - L
print(ans)


(N, K) = map(int, input().split())
S = input() + 'w'
A = []
if S[0] == '0':
	A.append(0)
(a, b) = (0, '')
for s in S:
	if b != '' and b != s:
		A.append(a)
		a = 1
	else:
		a += 1
	b = s
if S[-2] == '0':
	A.append(0)
B = [0]
for i in range(len(A)):
	B.append(B[i] + A[i])
ans = 0
N = len(B)
for i in range(2 * K + 1, N):
	if i % 2 == 0:
		continue
	ans = max(ans, B[i] - B[i - 2 * K - 1])
print(ans if ans else B[N - 1])


(n, k) = map(int, input().split())
s = input()
l = 1
w = 0
a = []
for c in s:
	if l ^ int(c):
		l = int(c)
		a.append(w)
		w = 1
	else:
		w += 1
else:
	a.append(w)
m = 2 * k + 1
ans = [sum(a[0:m])]
i = 2
while i + m <= len(a):
	ans.append(-sum(a[i - 2:i]) + ans[-1] + sum(a[i + m - 2:i + m]))
	i += 2
else:
	ans.append(-sum(a[i - 2:i]) + ans[-1] + sum(a[i + m - 2:]))
print(max(ans))


from itertools import groupby
(N, K) = map(int, input().split())
S = '1' + input() + '1'
acc = [0]
for (i, (k, v)) in enumerate(groupby(S)):
	acc.append(acc[i] + len(list(v)))
sz = len(acc)
l = [acc[min(sz - 1, i + 2 * K + 1)] - acc[i] - (i == 0) - (i + 2 * K + 1 >= sz - 1) for i in range(sz)]
print(max(l[::2]))


(N, K) = list(map(int, input().split()))
S = list(input())
S_zero = {}
S_zero_group = 0
s_befor = ''
for (s_idx, s) in enumerate(S):
	if s != s_befor:
		if s == '0':
			S_zero_group += 1
			S_zero[S_zero_group] = [s_idx - 1]
		elif s == '1':
			if S_zero_group in S_zero.keys():
				S_zero[S_zero_group].append(s_idx)
	s_befor = s
if S[-1] == '0':
	S_zero[S_zero_group].append(N)
if S_zero_group <= K:
	ans_ = N
else:
	ans_ = 0
	for g_s in range(1, S_zero_group - K + 2):
		g_e = g_s + K - 1
		s = 0
		e = N - 1
		if g_s != 1:
			s = S_zero[g_s - 1][1]
		if g_e != S_zero_group:
			e = S_zero[g_e + 1][0]
		ans = e - s + 1
		if ans > ans_:
			ans_ = ans
print(ans_)


(n, k) = map(int, input().split())
s = input()
b = [1]
if s[0] == '0':
	b = [0, 1]
for i in range(1, n):
	if s[i - 1] != s[i]:
		b += [1]
	else:
		b[-1] += 1
if s[-1] == '0':
	b += [0]
if len(b) // 2 <= k:
	print(n)
	exit()
x = a = sum(b[:k * 2 + 1])
for i in range(k, len(b) // 2):
	a += b[i * 2 + 1] + b[(i + 1) * 2]
	a -= b[(i - k) * 2] + b[(i - k) * 2 + 1]
	x = max(a, x)
print(x)


import itertools

def s():
	return input()

def I():
	return map(int, input().split())
(N, K) = I()
S = list(s())
num = 1
cnt = 0
L = []
for i in range(N - 1):
	if S[i] != S[i + 1]:
		L.append(num)
		num = 0
		if S[i] == '0':
			cnt += 1
	num += 1
L.append(num)
if S[-1] == '0':
	cnt += 1
ruiseki = [0] + list(itertools.accumulate(L))
l = len(ruiseki)
if cnt <= K:
	print(N)
	return
start = 0
ans = 0
if S[0] == '0':
	start = 1
for i in range(start, l, 2):
	if i + K * 2 + 1 > l - 1:
		break
	ans = max(ans, ruiseki[i + K * 2 + 1] - ruiseki[i])
if S[0] == '0':
	ans = max(ans, ruiseki[K * 2])
if S[-1] == '0':
	ans = max(ans, ruiseki[-1] - ruiseki[l - K * 2 - 1])
print(ans)


import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

def I():
	return int(input())

def F():
	return float(input())

def SS():
	return input()

def LI():
	return [int(x) for x in input().split()]

def LI_():
	return [int(x) - 1 for x in input().split()]

def LF():
	return [float(x) for x in input().split()]

def LSS():
	return input().split()

def resolve():
	(N, K) = LI()
	S = SS()
	l = []
	if S[0] == '1':
		l.append(0)
	else:
		l.append(0)
		l.append(0)
	for i in range(N - 1):
		if S[i] == '0' and S[i + 1] == '1':
			l.append(i + 1)
		elif S[i] == '1' and S[i + 1] == '0':
			l.append(i + 1)
	if S[-1] == '1':
		l.append(N)
	else:
		l.append(N)
		l.append(N)
	ans = 0
	if len(l) // 2 - 1 < K:
		ans = N
	else:
		for i in range(len(l) // 2 - K):
			ans = max(l[2 * i + 2 * K + 1] - l[2 * i], ans)
	print(ans)

def __starting_point():
	resolve()
__starting_point()


(N, K) = map(int, input().split())
S = input()
X = []
now = 1
tmp = 0
for i in range(N):
	if int(S[i]) - 0 == now:
		tmp += 1
	else:
		now = 1 - now
		X.append(tmp)
		tmp = 1
if tmp != 0:
	X.append(tmp)
n = len(X)
R = [0] * (n + 1)
for i in range(n):
	R[i + 1] = X[i] + R[i]
add = 2 * K + 1
ans = 0
for i in range(0, n + 1, 2):
	left = i
	right = min(i + add, n)
	ans = max(ans, R[right] - R[left])
print(ans)


(N, K) = map(int, input().split())
S = list(input())
l = [0, 0] if S[0] == '0' else [0]
l += [i for i in range(1, N) if S[i - 1] != S[i]]
l += [N] if S[-1] == '1' else [N, N]
ll = len(l)
p = 2 * K + 1
if ll < p:
	print(N)
else:
	print(max((l[p + i] - l[i] for i in range(0, ll - p + 1, 2))))


(N, K) = [int(_) for _ in input().split()]
S = input()
O = [[0, 0]]
is1 = False
for i in range(N):
	if S[i] == '1':
		if not is1:
			O += [[i, N]]
		is1 = True
	elif S[i] == '0':
		if is1:
			O[-1][-1] = i
		is1 = False
O += [[N, N]]
K = min([len(O) - 1, K])
ans = 0
for i in range(len(O) - K):
	ans = max([ans, O[i + K][1] - O[i][0]])
print(ans)


def main():
	(N, K) = map(int, input().split())
	S = input()
	A = []
	if S[0] == '1':
		nw = 1
	else:
		nw = -1
	for i in range(1, N):
		if S[i] == '1' and nw < 0:
			A.append(nw)
			nw = 1
		elif S[i] == '0' and nw > 0:
			A.append(nw)
			nw = -1
		else:
			nw += 2 * (S[i] == '1') - 1
	A.append(nw)
	if len(A) == 1:
		print(N)
		return
	B = [0] * (len(A) + 1)
	for i in range(len(A)):
		B[i + 1] = B[i] + abs(A[i])
	if A[0] < 0:
		fm = 0
	else:
		fm = 1
	ret = 0
	for i in range(fm, len(A), 2):
		ret = max(ret, B[min(i + 2 * K, len(B) - 1)] - B[max(i - 1, 0)])
	print(ret)

def __starting_point():
	main()
__starting_point()


from itertools import groupby
(n, k) = map(int, input().split())
S = input().strip()
L = [len(list(g)) for (v, g) in groupby(S)]
if S[0] == '0':
	L = [0] + L
if S[-1] == '0':
	L = L + [0]
A = [sum(L[:2 * k + 1])]
for i in range(0, len(L) - 2 * k - 1, 2):
	A += (A[-1] - L[i] - L[i + 1] + L[i + 2 * k + 1] + L[i + 2 * k + 2],)
print(max(A))


(n, k) = map(int, input().split())
s = input()
l = [0, 0] if s[0] == '0' else [0]
for i in range(1, n):
	if s[i - 1] != s[i]:
		l += [i]
l += [n] if s[-1] == '1' else [n, n]
ll = len(l)
pl = 2 * k + 1
if ll <= pl:
	print(n)
else:
	print(max((l[pl + i] - l[i] for i in range(0, ll - pl + 1, 2))))


(N, K) = map(int, input().split())
S = input()
if S[0] == '0':
	Sc = [0]
else:
	Sc = []
c = 1
for i in range(N - 1):
	if S[i] != S[i + 1]:
		Sc.append(c)
		c = 1
	else:
		c += 1
Sc.append(c)
if S[-1] == '0':
	Sc.append(0)
ansp = [sum(Sc[:2 * K + 1])]
for i in range(2 * K + 1, len(Sc), 2):
	ansp.append(ansp[-1] - Sc[i - 2 * K - 1] - Sc[i - 2 * K] + Sc[i] + Sc[i + 1])
ans = max(ansp)
print(ans)


(n, k) = list(map(int, input().split()))
s = input()
on = []
off = []
acnt = 0
bcnt = 0
for i in s:
	if i == '0':
		if bcnt > 0:
			off.append(bcnt)
			bcnt = 0
		acnt += 1
	else:
		if acnt > 0:
			on.append(acnt)
			acnt = 0
		bcnt += 1
if bcnt > 0:
	off.append(bcnt)
	bcnt = 0
if acnt > 0:
	on.append(acnt)
	acnt = 0
ans = 0
if s[0] == '1':
	for i in range(len(on) - k + 1):
		s = 0
		if i == 0:
			a = sum(on[i:i + k])
			b = sum(off[i:i + k + 1])
		else:
			a += on[i + k - 1]
			a -= on[i - 1]
			if i + k <= len(off) - 1:
				b += off[i + k]
			b -= off[i - 1]
		s = a + b
		ans = max(ans, s)
else:
	for i in range(len(on) - k + 1):
		if i == 0:
			a = sum(on[i:i + k])
			b = sum(off[i:i + k])
		elif i == 1:
			a = sum(on[i:i + k])
			b = sum(off[i - 1:i + k])
		else:
			a += on[i + k - 1]
			a -= on[i - 1]
			if i + k - 1 <= len(off) - 1:
				b += off[i + k - 1]
			b -= off[i - 2]
		s = a + b
		ans = max(ans, s)
if ans == 0:
	print(n)
else:
	print(ans)


(n, k) = map(int, input().split())
s = input().rstrip()
s = '1' + s
k_pt = 0
cur_tail = 0
for cur in range(1, len(s)):
	if s[cur - 1] == '1' and s[cur] == '0':
		k_pt += 1
	if k_pt > k:
		cur_tail += 1
		if s[cur_tail] == '0' and s[cur_tail + 1] == '1':
			k_pt -= 1
print(cur - cur_tail)


(n, k) = map(int, input().split())
s = input()
st = [0]
for i in range(1, n):
	if s[i] != s[i - 1]:
		st.append(i)
st.append(n)
a = len(st) - 1
if s[0] == '0':
	ans = st[min(2 * k, a)]
	for i in range(1, a + 1, 2):
		ans = max(ans, st[min(2 * k + 1 + i, a)] - st[i])
elif s[0] == '1':
	ans = 0
	for i in range(0, a + 1, 2):
		ans = max(ans, st[min(2 * k + 1 + i, a)] - st[i])
print(ans)


(N, K) = map(int, input().split())
x = 1
c = [0]
for s in input():
	if int(s) == x:
		c[-1] += 1
	else:
		x ^= 1
		c.append(1)
if not x:
	c.append(0)
m = len(c)
h = min(K * 2 + 1, m)
r = [c[0]]
for i in range(1, m):
	r.append(r[-1] + c[i])
r.append(0)
ans = 0
for i in range(0, m - h + 1, 2):
	ans = max(r[i + h - 1] - r[i - 1], ans)
print(ans)


import itertools
(N, K) = map(int, input().split())
S = input()
gr = itertools.groupby(S)
li = [] if S[0] == '1' else [0]
for (key, group) in gr:
	li.append(len(list(group)))
res = 0
cum = [0] * (len(li) + 1)
for i in range(len(li)):
	cum[i + 1] = cum[i] + li[i]
for i in range(0, len(li), 2):
	r = i + 2 * K + 1
	if r >= len(cum):
		r = len(cum) - 1
	res = max(res, cum[r] - cum[i])
print(res)


(N, K) = map(int, input().split())
S = input()
p = 1
l = 0
a = []
for i in S:
	if int(i) != p:
		a.append(l)
		p = 1 - p
		l = 1
	else:
		l += 1
a.append(l)
a.append(0)
s = sum(a[:2 * K + 1])
ans = s
for i in range(0, len(a) - 2 * K - 1, 2):
	if i + 2 * K + 3 > len(a):
		break
	s = s - a[i] - a[i + 1] + a[i + 2 * K + 1] + a[i + 2 * K + 2]
	ans = max(ans, s)
print(ans)


(N, K) = map(int, input().split())
s = input()
L = 2 * K + 1
X = [0] * (2 - int(s[0])) + [i + 1 for i in range(N - 1) if s[i] != s[i + 1]] + [N] * L
print(max([X[i + L] - X[i] for i in range(0, len(X) - L, 2)]))


(N, K) = map(int, input().split())
S = input()
a = [0]
if S[0] == '0':
	a.append(0)
for i in range(N - 1):
	if S[i] != S[i + 1]:
		a.append(i + 1)
a.append(N)
if S[N - 1] == '0':
	a.append(N)
r = len(a) // 2 - 1
if K >= r:
	print(N)
else:
	print(max((a[2 * (i + K) + 1] - a[2 * i] for i in range(r - K + 1))))


(N, K) = map(int, input().split())
S = input()
dp = []
(p, q) = (0, 0)
for i in S:
	if i == '1':
		if 0 < q:
			dp.append(q)
		p += 1
		q = 0
	else:
		if 0 < p:
			dp.append(p)
		p = 0
		q += 1
if 0 < p:
	dp.append(p)
else:
	dp.append(q)
if S[0] == '0':
	if len(dp) <= 2 * K:
		print(sum(dp))
	else:
		if S[N - 1] == '0':
			dp.append(0)
		dp.insert(0, 0)
		ans = sum(dp[:2 * K + 1])
		bns = ans
		for i in range(2 * K, len(dp), 2):
			if i == 2 * K:
				continue
			bns += dp[i] + dp[i - 1] - dp[i - 2 * K - 1] - dp[i - 2 * K - 2]
			ans = max(ans, bns)
		print(ans)
elif len(dp) <= 2 * K + 1:
	print(sum(dp))
else:
	if S[N - 1] == '0':
		dp.append(0)
	ans = sum(dp[:2 * K + 1])
	bns = ans
	for i in range(2 * K, len(dp), 2):
		if i == 2 * K:
			continue
		bns += dp[i] + dp[i - 1] - dp[i - 2 * K - 1] - dp[i - 2 * K - 2]
		ans = max(ans, bns)
	print(ans)


(n, k) = map(int, input().split())
s = input()
a = [i for i in range(1, n) if s[i] != s[i - 1]]
a = [0] + a if s[0] == '1' else [0, 0] + a
a += [n] if s[-1] == '1' else [n, n]
(l, x) = (len(a), k * 2 + 1)
if l <= x:
	print(n)
else:
	ans = max((a[i + x] - a[i] for i in range(0, l - x + 1, 2)))
	print(ans)


(N, K) = map(int, input().split())
S = input()
s = []
if S[0] == '0':
	s = [0]
for x in S.replace('01', '0,1').replace('10', '1,0').split(','):
	s.append(len(x))
M = len(s)
ans = [0] * M
ans[0] = sum(s[:2 * K + 1])
for i in range(2, M, 2):
	ans[i] = ans[i - 2] - s[i - 2] - s[i - 1] + sum(s[min(i + 2 * K - 1, M):i + 2 * K + 1])
print(max(ans))


(N, K) = map(int, input().split())
S = [int(_) for _ in input()]
now = 1
cnt = 0
one_zero = [0]
for i in S:
	if i == now:
		cnt += 1
	else:
		one_zero.append(cnt)
		now = 1 - now
		cnt += 1
if cnt != 0:
	one_zero.append(cnt)
add = 2 * K + 1
ans = 0
for i in range(0, len(one_zero), 2):
	right = min(i + add, len(one_zero) - 1)
	ans = max(ans, one_zero[right] - one_zero[i])
print(ans)


from itertools import *
(N, K) = map(int, input().split())
S = input()
C = []
now = 1
cnt = 0
for i in range(N):
	if S[i] == str(now):
		cnt += 1
	else:
		C.append(cnt)
		now = 1 - now
		cnt = 1
C.append(cnt)
if len(C) % 2 == 0:
	C.append(0)
S = [0] + list(accumulate(C))
m = len(C)
ans = 0
for i in range(0, m, 2):
	left = i
	right = min(i + 2 * K + 1, m)
	ans = max(ans, S[right] - S[left])
print(ans)


(n, k) = map(int, input().split())
s = input()
il = [0]
for i in range(1, n):
	if s[i] != s[i - 1]:
		il.append(i)
res = -1
for i in range(len(il)):
	if s[il[i]] == '0':
		ri = i + 2 * k
	else:
		ri = i + 2 * k + 1
	if ri >= len(il):
		r = n
	else:
		r = il[ri]
	res = max(res, r - il[i])
print(res)


(n, k) = map(int, input().split())
s = input()
b = [0]
for i in range(n - 1):
	if s[i] != s[i + 1]:
		b.append(i + 1)
b.append(len(s))
if s[0] == '0':
	b.insert(0, 0)
if s[-1] == '0':
	b.append(len(s))
ans = 0
stride = k * 2 + 1
if len(b) - stride < 1:
	stride = len(b) - 1
for i in range(0, len(b) - stride, 2):
	ans = max(ans, b[i + stride] - b[i])
print(ans)


(n, k) = map(int, input().split())
s = list(map(int, list(input())))
l = [0]
for i in range(0, n - 1):
	if s[i] != s[i + 1]:
		l.append(i + 1)
t = len(l)
for x in range(0, 2 * k + 1):
	l.append(n)
can = []
for j in range(0, t):
	if s[l[j]] == 0:
		can.append(l[j + 2 * k] - l[j])
	elif s[l[j]] == 1:
		can.append(l[j + 2 * k + 1] - l[j])
	else:
		break
print(max(can))


import sys, math, collections, itertools
input = sys.stdin.readline
(N, K) = list(map(int, input().split()))
S = input().rstrip()
stand = []
s_or_r = []
s_bf = '.'
cnt = 0
for i in range(N):
	if s_bf != S[i] and i != 0:
		stand.append(cnt)
		s_or_r.append(s_bf)
		cnt = 1
		s_bf = S[i]
	else:
		cnt += 1
		s_bf = S[i]
stand.append(cnt)
s_or_r.append(s_bf)
if s_or_r.count('0') <= K:
	print(len(S))
	return
if s_or_r[0] == '0':
	s_or_r = ['1'] + s_or_r
	stand = [0] + stand
if s_or_r[-1] == '0':
	s_or_r.append('1')
	stand.append(0)
tmp = sum(stand[0:2 * K + 1])
ans = tmp
for i in range(2, len(stand) - 2 * K, 2):
	tmp += -(stand[i - 1] + stand[i - 2]) + stand[i + 2 * K - 1] + stand[i + 2 * K]
	ans = max(ans, tmp)
print(ans)


(n, k) = map(int, input().split())
s = []
count = 0
last = 1
for i in input():
	if i == '1':
		if last == 1:
			count += 1
		else:
			s.append(count)
			count = 1
		last = 1
	else:
		if last == 0:
			count += 1
		else:
			s.append(count)
			count = 1
		last = 0
s.append(count)
if last == 0:
	s.append(0)
k = min(k, len(s) // 2)
ans = 0
for j in range(len(s) // 2 - k + 1):
	if j == 0:
		now = sum(s[:k * 2 + 1])
		ans = now
	else:
		now = now - s[j * 2 - 1] - s[j * 2 - 2] + s[(j + k) * 2] + s[(j + k) * 2 - 1]
		ans = max(ans, now)
print(ans)


(N, K) = list(map(int, input().split(' ')))
S = input()
lengths = []
if S.startswith('0'):
	lengths.append(0)
cont = 0
for (s0, s1) in zip(S, S[1:] + 'x'):
	cont += 1
	if s0 != s1:
		lengths.append(cont)
		cont = 0
if S.endswith('0'):
	lengths.append(0)
window = 2 * K + 1
buf = sum(lengths[0:window])
ans = buf
for i in range(window, len(lengths)):
	buf += lengths[i]
	buf -= lengths[i - window]
	if i % 2 == 0:
		ans = max(ans, buf)
print(ans)


(n, k) = map(int, input().split())
s = input() + '#'
num = [0]
for i in range(1, n + 1):
	if s[i - 1] != s[i]:
		num.append(i)
(ans, lennum) = (num[1], len(num))
for i in range((s[0] == '1') + 1, lennum, 2):
	(r, l) = (max(i - 2, 0), min(i + 2 * k, lennum) - 1)
	ans = max(ans, num[l] - num[r])
print(ans)


from itertools import groupby
import sys
(N, K) = list(map(int, input().split()))
S = input()
S = [[i, len(list(j))] for (i, j) in groupby(S)]
if len(S) // 2 <= K:
	if len(S) % 2 == 1 and S[-1][0] == '0':
		if len(S) == 1:
			print(sum([j for (i, j) in S]))
			return
	else:
		print(sum([j for (i, j) in S]))
		return
ans = 0
cnt = 0
lidx = -1
for (i, j) in S:
	lidx += 1
	if cnt == K and i == '0':
		break
	ans += j
	if i == '0':
		cnt += 1
sidx = 0
mans = ans
for i in range(lidx, len(S)):
	ans += S[i][1]
	if i == len(S) - 1 or S[i][0] == '1':
		while True:
			ans -= S[sidx][1]
			sidx += 1
			if S[sidx][0] == '1':
				break
		mans = max(mans, ans)
print(mans)


(N, K) = map(int, input().split())
s = input()
X = [0]
if s[0] == '0':
	X.append(0)
for i in range(N):
	if i == N - 1 or s[i] != s[i + 1]:
		X.append(i + 1)
if s[-1] == '0':
	X.append(X[-1])
if len(X) <= K * 2 + 1:
	print(N)
else:
	ma = 0
	for i in range(0, len(X) - K * 2 - 1, 2):
		ma = max(X[i + K * 2 + 1] - X[i], ma)
	print(ma)


(N, K) = map(int, input().split())
S = input()
a = []
if S[0] == '0':
	a.append(0)
cnt = 1
for i in range(1, N):
	if S[i] != S[i - 1]:
		a.append(cnt)
		cnt = 1
	else:
		cnt += 1
a.append(cnt)
a.append(0)
a.append(0)
ans = s = sum(a[:2 * K + 1])
for i in range(2 * K + 2, len(a), 2):
	s += a[i] + a[i - 1] - a[i - 2 * K - 1] - a[i - 2 * K - 2]
	ans = max(ans, s)
print(ans)


(N, K) = map(int, input().split())
S = input()
l = [0]
curr = '1'
for c in S:
	if c != curr:
		l.append(1)
		curr = c
	else:
		l[-1] += 1
if curr == '0':
	l.append(0)
n_group = len(l) // 2
sum_ = 0
k = min(K, n_group)
sum_ = sum(l[0:2 * k + 1])
max_ = sum_
for i in range(k, n_group):
	sum_ -= l[2 * i - 2 * K] + l[2 * i + 1 - 2 * K]
	sum_ += l[2 * i + 1] + l[2 * i + 2]
	max_ = max(max_, sum_)
print(max_)


(N, K) = map(int, input().split())
s = input()
l = []
index = 0
pre = '1'
for i in range(len(s)):
	if s[i] != pre:
		l.append(i - index)
		pre = s[i]
		index = i
else:
	l.append(i - index + 1 if i != index else 1)
	if s[-1] == '0':
		l.append(0)
Max = sum(l[:min(2 * K + 1, len(l))])
cur = Max
for i in range(2 * K + 1, len(l)):
	cur = cur + l[i] - l[i - 2 * K - 1] - l[i - 2 * K] if i % 2 else cur + l[i]
	if cur > Max:
		Max = cur
print(Max)


(n, k) = map(int, input().split())
S = input().replace('01', '0 1').replace('10', '1 0').split()
S = [''] * ('0' in S[0]) + S + [''] * ('0' in S[-1])
(*L,) = map(len, S)
A = [sum(L[:2 * k + 1])]
for i in range(0, len(S) - 2 * k - 1, 2):
	A += (A[-1] - L[i] - L[i + 1] + L[i + 2 * k + 1] + L[i + 2 * k + 2],)
print(max(A))


(n, k) = map(int, input().split())
s = input()
start = [0] * (k + 1)
c = '1'
ret = 0
for i in range(len(s)):
	if c == '0' and s[i] == '1':
		start.append(i)
	elif c == '1' and s[i] == '0':
		ret = max(ret, i - start.pop(0))
	c = s[i]
ret = max(ret, n - start.pop(0))
print(ret)


(N, K) = map(int, input().split())
S = list(input())
beg = [0]
end = []
for i in range(N):
	if len(beg) != len(end):
		if S[i] == '0':
			end.append(i - 1)
	elif S[i] == '1':
		beg.append(i)
if len(beg) != len(end):
	end.append(N - 1)
beg.append(N - 1)
end.append(N - 1)
ans = [1 + end[i + K] - beg[i] for i in range(len(beg) - K)]
print(max(ans) if len(ans) > 0 else N)


(N, K) = map(int, input().split())
S = '1' + input() + '1'
A = []
now = '1'
C = 0
for s in S:
	if s == now:
		C += 1
	else:
		A.append(C)
		now = s
		C = 1
A.append(C)
A[0] -= 1
A[-1] -= 1
B = [sum(A[:2 * K + 1])]
i = 0
j = 2 * (K + 1)
while j < len(A):
	b = B[-1] + sum(A[j - 1:j + 1]) - sum(A[i:i + 2])
	B.append(b)
	i += 2
	j += 2
print(max(B))


(n, k) = map(int, input().split())
s = '1' + input()
i = j = 0
while j < n:
	k -= '10' == s[j:j + 2]
	i += k < 0
	k += k < 0 and '01' == s[i:i + 2]
	j += 1
print(n - i)


(N, K) = map(int, input().split())
S = input()
S += '2'
A = []
if S[0] == '0':
	A.append(0)
cnt = 1
for i in range(1, len(S)):
	if S[i] == S[i - 1]:
		cnt += 1
	else:
		A.append(cnt)
		cnt = 1
ans = 0
tot = 0
r = 0
for l in range(len(A)):
	while r < len(A) and r - l < 2 * K + 1:
		tot += A[r]
		r += 1
	if l % 2 == 0:
		ans = max(ans, tot)
	if l == r:
		r += 1
	else:
		tot -= A[l]
print(ans)


(n, k) = map(int, input().split())
s = input()
s += 'X'
ans = 0
r = 0
l = 0
count = 1 if s[0] == '0' else 0
while r < n:
	if count <= k:
		ans = max(ans, r - l + 1)
		if s[r] == '1' and s[r + 1] == '0':
			count += 1
		r += 1
	else:
		if s[l] == '0' and s[l + 1] == '1':
			count -= 1
		l += 1
print(ans)


(n, k) = map(int, input().split())
s = list(input())
a = [0]
if s[0] == '0':
	a.append(0)
for i in range(n):
	if i == n - 1 or s[i + 1] != s[i]:
		a.append(i + 1)
if s[-1] == '0':
	a.append(a[-1])
if len(a) <= 2 * k + 1:
	print(n)
else:
	ans = 0
	for j in range(0, len(a) - 2 * k - 1, 2):
		ans = max(ans, a[j + 2 * k + 1] - a[j])
	print(ans)


(N, K) = list(map(int, input().split()))
S = input()
left = 0
right = 0
numofturn = 0
if N == 1:
	print(int(S))
else:
	if S[0] == '0':
		while right < N:
			if S[right] == '0':
				right += 1
			else:
				break
	right = max(right, 1)
	while right < N and numofturn < K:
		if S[right] == '1' and S[right - 1] == '0':
			numofturn += 1
		right += 1
	while right < N:
		if S[right] == '1':
			right += 1
		else:
			break
	ans = right
	while right < N and left < N:
		if numofturn == K:
			while 1:
				left += 1
				if left < N:
					if S[left] != '1' or S[left - 1] != '0':
						continue
				numofturn -= 1
				break
		else:
			while 1:
				right += 1
				if right < N:
					if S[right] != '0' or S[right - 1] != '1':
						continue
				numofturn += 1
				if right == N:
					ans = max(ans, right - left)
				else:
					ans = max(ans, right - left)
				break
	print(ans)


(n, k) = map(int, input().split())
s = list(str(input()))
r = []
l = []
c = 0
d = 1
for i in range(n):
	if s[i] == '1' and d == 1:
		r.append(i)
		c = 1
		d = 0
	elif s[i] == '0' and c == 1:
		l.append(i - 1)
		c = 0
		d = 1
if c > 0:
	l.append(i)
if len(r) <= k + 1:
	r = [0] * (k + 1 - len(r)) + r + [n - 1] * (k + 1 - len(r))
	l = [0] * (k + 1 - len(l)) + l + [n - 1] * (k + 1 - len(l))
r = [0] + r + [n - 1]
l = [0] + l + [n - 1]
ans = 0
for i in range(len(r) - k):
	ans = max(ans, l[i + k] - r[i] + 1)
print(ans)


(n, k) = map(int, input().split())
s = input()
z = []
c = 1
if n == 1:
	print(1)
	exit()
for i in range(1, n):
	if s[i] == s[i - 1]:
		c += 1
	else:
		z += [c]
		c = 1
z += [c]
if s[0] == '0':
	z = [0] + z
if s[-1] == '0':
	z = z + [0]
lz = len(z)
pre = sum(z[0:2 * k + 1])
mx = pre
for i in range(2, lz - 2 * k, 2):
	pre = pre - z[i - 2] - z[i - 1] + z[i + 2 * k - 1] + z[i + 2 * k]
	if pre > mx:
		mx = pre
print(mx)


(n, k) = map(int, input().split())
s = list(input())
cl = 0
cr = 0
a = []
ans = 0
if s[0] == '1':
	ck = 0
	ans = 1
else:
	ck = 1
	a.append([0, 0])
while True:
	while ck <= k and cr < n - 1:
		cr += 1
		if s[cr - 1] == '1' and s[cr] == '0':
			if ck < k:
				ck += 1
				a.append([cr, cr])
			else:
				break
		elif s[cr - 1] == '0' and s[cr] == '1':
			a[-1][1] = cr
		ans = max(ans, cr - cl + 1)
	if cr < n - 1:
		(tl, tr) = a.pop(0)
		cl = tr
		cr -= 1
		ck -= 1
	else:
		break
print(ans)


from itertools import *
from numpy import *
(n, k) = map(int, input().split())
k = 2 * k + 1
s = input()
x = [0] * (s[0] == '0') + [len(list(v)) for (k, v) in groupby(s)] + [0] * (s[-1] == '0')
x1 = array(x[k:])
x2 = array(x[:-k])
x3 = sum(x[:k])
y = [x3] + list(x3 + cumsum(x1 - x2))
print(max(y[::2]))


(n, k) = map(int, input().split())
s = [int(i) for i in input()]
(l1, l0) = ([], [])
(b, c) = (1, 0)
for i in s:
	if b == i:
		c += 1
	else:
		if b:
			l1 += [c]
		else:
			l0 += [c]
		c = 1
	b = i
if b:
	l1 += [c]
	l0 += [0]
else:
	l0 += [c]
S = [0]
for (i, j) in zip(l1, l0):
	S += [S[-1] + i + j]
l1 += [0]
m = len(S)
if m <= k:
	print(n)
	exit()
a = 0
for i in range(k, m):
	a = max(a, S[i] - S[i - k] + l1[i])
print(a)


(N, K) = map(int, input().split())
S = input()
L = S.replace('01', '0,1')
L = L.replace('10', '1,0')
L = L.split(',')
L = [len(l) for l in L]
if S[0] == '0':
	L = [0] + L
R = []
for i in range(max(1, len(L) // 2 + 1 - K)):
	if i == 0:
		R.append(sum(L[2 * i:2 * (i + K) + 1]))
	else:
		R.append(R[-1] - sum(L[2 * (i - 1):2 * (i - 1) + 2]) + sum(L[2 * (i + K) - 1:2 * (i + K) + 1]))
print(max(R))


(n, k) = map(int, input().split())
s = list(map(int, list(input())))
t = [0] + [1 if s[0] == 1 else -1]
ans = 0
for i in range(1, n):
	if s[i] == s[i - 1]:
		t[-1] = i + 1 if s[i] == 1 else -i - 1
	else:
		t += [i + 1 if s[i] == 1 else -i - 1]
for i in range(len(t) - 1):
	temp = 0
	l = k * 2 + 1 if t[i + 1] > 0 else k * 2
	temp = abs(t[min(len(t) - 1, i + l)]) - abs(t[i])
	ans = max(ans, temp)
print(ans)


from itertools import groupby, accumulate
(N, K) = map(int, input().split())
S = input()
g_cnt = [len(list(v)) for (k, v) in groupby(S)]
ans = 1
if S[0] == '0':
	g_cnt = [0] + g_cnt
if S[-1] == '0':
	g_cnt = g_cnt + [0]
accum = [0] + list(accumulate(g_cnt))
ans = 0
for i in range(0, len(accum), 2):
	r = i + 2 * K + 1
	if r >= len(accum):
		r = len(accum) - 1
	ans = max(ans, accum[r] - accum[i])
print(ans)


(n, k) = map(int, input().split())
s = input()
a = []
b = []
c = 0
d = '1'
for i in s:
	if d == i:
		c += 1
	elif d == '1':
		b.append(c)
		d = '0'
		c = 1
	else:
		a.append(c)
		d = '1'
		c = 1
if d == '1':
	b.append(c)
else:
	a.append(c)
	b.append(0)
if k >= len(a):
	print(n)
else:
	e = sum(a[:k]) + sum(b[:k + 1])
	ans = e
	for i in range(len(a) - k):
		e = e - a[i] - b[i] + a[i + k] + b[i + k + 1]
		ans = max(ans, e)
	print(ans)


(n, k) = map(int, input().split())
s = input()
from itertools import groupby
a = [len(list(j)) for (i, j) in groupby(s)]
if s[0] == '0':
	a = [0] + a
if s[n - 1] == '0':
	a = a + [0]
w = 2 * k + 1
if len(a) <= w:
	print(n)
	exit()
m = sum(a[:w])
x = m
for i in range(2, len(a) - 2 * k, 2):
	m = m - a[i - 1] - a[i - 2] + a[i + w - 1] + a[i + w - 2]
	x = max(x, m)
print(x)


(n, k) = map(int, input().split())
w = input()
l = []
c = 0
w = '1' + w
for i in range(1, 1 + n):
	if w[i] != w[i - 1]:
		l.append(c)
		c = 1
	else:
		c += 1
l.append(c)
if k >= len(l) // 2:
	print(n)
else:
	if w[-1] == '0':
		l.append(0)
	s = l[0]
	for i in range(1, 1 + k):
		s += l[2 * i] + l[2 * i - 1]
	s1 = s
	c1 = l[0] + l[1]
	for i in range(1, (len(l) + 1) // 2 - k):
		s1 = s1 - l[2 * i - 2] - l[2 * i - 1] + l[2 * i - 1 + 2 * k] + l[2 * i + 2 * k]
		if s1 > s:
			s = s1
	print(s)


(N, K) = map(int, input().split())
S = input()
q = [(S[0], 0)]
cur = S[0]
for i in range(1, N):
	if S[i] != cur:
		q.append((S[i], i))
		cur = S[i]
lim = len(q)
ans = []
for i in range(lim):
	if q[i][0] == '0':
		j = i + 2 * K
	else:
		j = i + 2 * K + 1
	if j < lim:
		ans.append(q[j][1] - q[i][1])
	else:
		ans.append(N - q[i][1])
print(max(ans))


(N, K) = map(int, input().split())
S = input()
l = 0
count = 0
ans = 0
for r in range(N):
	if S[r] == '0':
		if r == 0 or S[r - 1] == '1':
			count += 1
	if count > K:
		while S[l] == '1':
			l += 1
		while S[l] == '0':
			l += 1
		count -= 1
	ans = max(ans, r - l + 1)
print(ans)


import itertools
(N, K) = map(int, input().split())
lsS = list(input())
gr = itertools.groupby(lsS)
ls = [['0', 0]]
for (key, group) in gr:
	ls.append([key, len(list(group))])
lengr = len(ls)
lssum = []
sum1 = 0
for i in range(lengr):
	sum1 += ls[i][1]
	lssum.append([ls[i][0], sum1])
lsans = []
for i in range(1, lengr):
	if ls[i][0] == '0':
		lsans.append(lssum[min(lengr - 1, i + 2 * K - 1)][1] - lssum[i - 1][1])
	elif ls[i][0] == '1':
		lsans.append(lssum[min(lengr - 1, i + 2 * K)][1] - lssum[i - 1][1])
print(max(lsans))


(n, k) = map(int, input().split())
S = list(input())
if '0' not in S:
	print(n)
	return
cnt = []
if S[0] == '0':
	cnt.append(0)
i = 0
while i < n:
	j = i
	while j < n and S[i] == S[j]:
		j += 1
	cnt.append(j - i)
	i = j
if S[-1] == '0':
	cnt.append(0)
cumCnt = [0]
for c in cnt:
	cumCnt.append(cumCnt[-1] + c)
lenCnt = len(cnt)
lenCumCnt = len(cumCnt)
ans = 0
for left in range(0, lenCumCnt, 2):
	right = min(left + 2 * k + 1, lenCumCnt - 1)
	ans = max(ans, cumCnt[right] - cumCnt[left])
print(ans)


(n, k) = map(int, input().split())
s = input()
L = []
from itertools import groupby
for (key, value) in groupby(s):
	L.append((key, len(list(value))))
c = []
for i in range(len(L)):
	c.append(L[i][1])
c = [0] + c
for i in range(1, len(c)):
	c[i] += c[i - 1]
l = 0
r = 2 * k
ans = 0
while True:
	if L[l][0] == '1':
		if l + r + 1 < len(L):
			ans = max(ans, c[l + r + 1] - c[l])
		else:
			ans = max(ans, c[len(L)] - c[l])
	elif L[l][0] == '0':
		if l + r < len(L):
			ans = max(ans, c[l + r] - c[l])
		else:
			ans = max(ans, c[len(L)] - c[l])
	if l == len(L) - 1:
		break
	l += 1
print(ans)


(n, k) = map(int, input().split())
s = input()
ms = 0
ps = 0
temp = [0]
if s[0] == '0':
	temp.append(0)
for i in s:
	if i == '0':
		ms += 1
		if ps:
			temp.append(ps)
			ps = 0
	else:
		ps += 1
		if ms:
			temp.append(ms)
			ms = 0
if ms:
	temp.append(ms)
else:
	temp.append(ps)
temp.append(0)
for i in range(len(temp) - 1):
	temp[i + 1] += temp[i]
ans = 0
if len(temp) - (2 * k + 1) <= 0:
	ans = temp[-1]
else:
	for i in range(0, len(temp) - (2 * k + 1), 2):
		ans = max(ans, temp[i + 2 * k + 1] - temp[i])
print(ans)


def run_length_compress(S):
	res = [[S[0], 1]]
	for c in S[1:]:
		if c == res[-1][0]:
			res[-1][1] += 1
		else:
			res.append([c, 1])
	return res
(N, K) = list(map(int, input().split()))
S = input()
cs = run_length_compress(S)
M = len(cs)
ans = 0
tot = 0
right = 0
zeros = 0
for left in range(M):
	while right < M and zeros + (cs[right][0] == '0') <= K:
		if cs[right][0] == '0':
			zeros += 1
		tot += cs[right][1]
		right += 1
	ans = max(ans, tot)
	if left == right:
		right += 1
	else:
		if cs[left][0] == '0':
			zeros -= 1
		tot -= cs[left][1]
print(ans)


(N, K) = map(int, input().split())
s = str(input())
l = []
(tmp, cnt) = (s[0], 1)
for i in range(1, N):
	if s[i] == tmp:
		cnt += 1
	else:
		tmp = s[i]
		l.append(cnt)
		cnt = 1
l.append(cnt)
(start, goal) = (0, len(l))
if s[0] == '0':
	start += 1
if s[-1] == '0':
	goal -= 1
ans = sum(l[start:start + 2 * K + 1])
tmp = ans
for i in range(start, goal - 2 * K - 2, 2):
	tmp += l[i + 2 * K + 1] + l[i + 2 * K + 2] - l[i] - l[i + 1]
	ans = max(ans, tmp)
if ans < sum(l[:2 * K]):
	ans = sum(l[:2 * K])
if ans < sum(l[-2 * K:]):
	ans = sum(l[-2 * K:])
print(ans)


import sys
(N, K) = map(int, sys.stdin.readline().strip().split())
S = sys.stdin.readline().strip()
l = x = ans = 0
for r in range(N):
	if S[r] == '0':
		if r == 0 or S[r - 1] == '1':
			x += 1
	if x > K:
		while S[l] == '1':
			l += 1
		while S[l] == '0':
			l += 1
		x -= 1
	ans = max(ans, r - l + 1)
print(ans)


from itertools import accumulate
(N, K) = map(int, input().split())
S = input() + '2'
T = []
i = 0
for j in range(1, len(S)):
	if S[i] != S[j]:
		T.append(j - i)
		i = j
U = [0] + list(accumulate(T))
ans = 0
for i in range(len(T)):
	if (i + int(S[0])) % 2 == 0:
		j = i + 2 * (K - 1) + 1
	else:
		j = i + 2 * K
	j = min(j, len(T) - 1)
	ans = max(ans, U[j + 1] - U[i])
print(ans)


def resolve():
	(N, K) = map(int, input().split())
	S = input()
	L = []
	pre = '1'
	cnt = 0
	for i in range(N):
		if pre == S[i]:
			cnt += 1
		else:
			L.append(cnt)
			cnt = 1
		pre = S[i]
	L.append(cnt)
	if pre == '0':
		L.append(0)
	length = 2 * K + 1
	if len(L) <= length:
		return print(N)
	left = 0
	right = 0
	tmp = 0
	ans = 0
	for i in range(0, len(L), 2):
		nextL = i
		nextR = min(i + length, len(L))
		while nextL > left:
			tmp -= L[left]
			left += 1
		while nextR > right:
			tmp += L[right]
			right += 1
		ans = max(ans, tmp)
	print(ans)

def __starting_point():
	resolve()
__starting_point()


(N, K) = list(map(int, input().split()))
S = input()
flag = False
cnt = []
l = 0
r = 0
cnt.append([0, 0])
for i in range(N):
	if flag:
		if S[i] == '0':
			r = i
			cnt.append([l, r])
			flag = False
	elif S[i] == '1':
		l = i
		flag = True
if flag:
	cnt.append([l, N])
cnt.append([N, N])
ans = 0
n = len(cnt)
for i in range(n):
	j = min(n - 1, i + K)
	ans = max(cnt[j][1] - cnt[i][0], ans)
print(ans)


import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
(n, k) = list(map(int, input().split()))
s = input()
ans = 0
cnt = 0
right = 1
for left in range(0, n):
	if left == 0 and s[left] == '0':
		cnt += 1
	if left > 0 and s[left] == '1' and (s[left - 1] == '0'):
		cnt -= 1
	while right <= n - 1:
		if s[right] == '0' and s[right - 1] == '1':
			if cnt < k:
				cnt += 1
			else:
				break
		right += 1
	ans = max(ans, right - left)
print(ans)


(N, K) = map(int, input().split())
s = input()
ls = []
i = 0
c = 0
while i < N and s[i] == '1':
	c += 1
	i += 1
if i == N:
	print(N)
	return
while i < N:
	l = c
	c = 0
	while i < N and s[i] == '0':
		c += 1
		i += 1
	m = c
	c = 0
	while i < N and s[i] == '1':
		c += 1
		i += 1
	r = c
	ls.append((l, m, r))
K = min(K, len(ls))
from itertools import accumulate
acc = list(accumulate([0] + ls, lambda x, y: x + y[1] + y[2]))
ans = 0
for i in range(len(ls) - K + 1):
	ans = max(ans, acc[i + K] - acc[i] + ls[i][0])
print(ans)


(N, K) = map(int, input().split())
S = input()
l = [1]
for i in range(N - 1):
	if S[i] == S[i + 1]:
		l[-1] += 1
	else:
		l.append(1)
if S[0] == '0':
	l = [0] + l
if S[-1] == '0':
	l += [0]
s = [0]
for i in range(len(l)):
	s.append(s[-1] + l[i])
if len(l) <= 2 * K + 1:
	print(s[-1])
else:
	cnt = 0
	for i in range((len(l) - 2 * K - 1) // 2 + 1):
		cnt = max(cnt, s[2 * K + 2 * i + 1] - s[2 * i])
	print(cnt)


from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

def main():
	(N, K) = list(map(int, input().split()))
	S = input()
	nums = []
	if S[0] == '0':
		nums.append(0)
	i = 0
	while i < N:
		j = i
		while j < N and S[i] == S[j]:
			j += 1
		nums.append(j - i)
		i = j
	if S[-1] == '0':
		nums.append(0)
	nums = [0] + list(accumulate(nums))
	ans = 0
	for i in range(0, len(nums), 2):
		ans = max(ans, nums[min(i + 2 * K + 1, len(nums) - 1)] - nums[i])
	print(ans)

def __starting_point():
	main()
__starting_point()


(N, K) = map(int, input().split())
s = input()
cnt = 0
d = s[0]
ss = []
for i in range(N):
	if s[i] == d:
		cnt += 1
	else:
		ss.append(cnt)
		cnt = 1
		d = s[i]
ss.append(cnt)
ss.append(0)
ss.append(0)
ss.append(0)
cs = [0]
if s[0] == '0':
	cs.append(0)
for x in ss:
	cs.append(cs[-1] + x)
ans = 0
for i in range(1, len(cs) - 2 * K, 2):
	ans = max(ans, cs[2 * K + i] - cs[i - 1])
if 2 * K + 1 >= len(cs):
	ans = cs[-1]
print(ans)


(N, K) = list(map(int, input().split()))
S = str(input())
man_groups = []
same_cnt = 0
last_man = ''
for i in range(N):
	cur_man = S[i]
	if cur_man != last_man:
		if same_cnt > 0:
			if last_man == '0':
				same_cnt *= -1
			man_groups.append(same_cnt)
		same_cnt = 1
	else:
		same_cnt += 1
	last_man = cur_man
if same_cnt > 0:
	if last_man == '0':
		same_cnt *= -1
	man_groups.append(same_cnt)
sum_list = []
end_pos = 2 * K if man_groups[0] > 0 else 2 * K - 1
max_man_groups_idx = len(man_groups) - 1
end_pos = min(end_pos, max_man_groups_idx)
last_max = sum(map(abs, man_groups[0:end_pos + 1]))
sum_list.append(last_max)
start_pos = 2 if man_groups[0] > 0 else 1
for i in range(start_pos, len(man_groups), 2):
	if end_pos >= max_man_groups_idx:
		break
	for j in range(2):
		idx = i - j - 1
		if idx >= 0:
			last_max -= abs(man_groups[idx])
	for j in range(2):
		end_pos += 1
		if end_pos <= max_man_groups_idx:
			last_max += abs(man_groups[end_pos])
	sum_list.append(last_max)
print(max(sum_list))


(n, k) = map(int, input().split())
s = list(input())
memo = [0]
for i in range(1, n):
	if s[i] != s[i - 1]:
		memo.append(i)
ans = 0
kyoukai_math = len(memo)
for i in range(kyoukai_math):
	if s[memo[i]] == '1':
		hasi = i + k * 2 + 1
	else:
		hasi = i + k * 2
	if hasi < kyoukai_math:
		ans = max(ans, memo[hasi] - memo[i])
	else:
		ans = max(ans, n - memo[i])
print(ans)


(N, K) = list(map(int, input().split()))
S = input()
beforeChar = S[0]
sectionList = []
count = 0
for i in range(N):
	if S[i] == beforeChar:
		count += 1
	else:
		sectionList.append([beforeChar, count])
		count = 1
		beforeChar = S[i]
sectionList.append([beforeChar, count])
sectionNumber = len(sectionList)
zeroSectionNumber = 0
oneSectionNumber = 0
if sectionNumber % 2 == 0:
	zeroSectionNumber = sectionNumber // 2
	oneSectionNumber = sectionNumber // 2
elif sectionList[0][0] == '0':
	zeroSectionNumber = sectionNumber // 2 + 1
	oneSectionNumber = sectionNumber // 2
else:
	zeroSectionNumber = sectionNumber // 2
	oneSectionNumber = sectionNumber // 2 + 1
if zeroSectionNumber <= K:
	print(N)
	return
sumLengthList = []
sumLength = 0
for i in range(sectionNumber):
	sumLength += sectionList[i][1]
	sumLengthList.append(sumLength)

def sumLengthByRange(rangeStartSection, rangeEndSection):
	if rangeStartSection == 0:
		return sumLengthList[rangeEndSection]
	else:
		return sumLengthList[rangeEndSection] - sumLengthList[rangeStartSection - 1]
startSection = 0
endSection = 0
lengthList = []
if sectionList[0][0] == '1':
	endSection = K * 2
else:
	endSection = K * 2 - 1
	lengthList.append(sumLengthByRange(startSection, endSection))
	startSection = 1
	endSection += 2
while endSection < sectionNumber:
	lengthList.append(sumLengthByRange(startSection, endSection))
	startSection += 2
	endSection += 2
if sectionList[-1][0] == '0':
	endSection -= 1
	lengthList.append(sumLengthByRange(startSection, endSection))
print(max(lengthList))


import sys
icase = 0
if icase == 0:
	(n, k) = list(map(int, input().split()))
	s = input()
if n == 1:
	print(1)
	return
ss = []
if s[0] == '1' and s[1] == '1':
	zcnt = 1
elif s[0] == '1' and s[1] == '0':
	zcnt = 1
elif s[0] == '0' and s[1] == '0':
	ss.append(0)
	zcnt = 1
elif s[0] == '0' and s[1] == '1':
	ss.append(0)
	zcnt = 1
for i in range(1, n - 1):
	if s[i] == '0' and s[i - 1] == '0':
		zcnt += 1
	elif s[i] == '0' and s[i - 1] == '1':
		ss.append(zcnt)
		zcnt = 1
	elif s[i] == '1' and s[i - 1] == '1':
		zcnt += 1
	elif s[i] == '1' and s[i - 1] == '0':
		ss.append(zcnt)
		zcnt = 1
for i in range(n - 1, n):
	if s[i] == '0' and s[i - 1] == '0':
		zcnt += 1
		ss.append(zcnt)
		ss.append(0)
	elif s[i] == '0' and s[i - 1] == '1':
		ss.append(zcnt)
		ss.append(1)
		ss.append(0)
	elif s[i] == '1' and s[i - 1] == '1':
		zcnt += 1
		ss.append(zcnt)
	elif s[i] == '1' and s[i - 1] == '0':
		ss.append(zcnt)
		ss.append(1)
if len(ss) <= 2 * k + 1:
	print(n)
	return
smax = 0
for i in range(2 * k + 1):
	smax += ss[i]
ssum = smax
kk = 2 * k
for i in range(2, len(ss) - kk, 2):
	ssum = ssum - ss[i - 2] - ss[i - 1] + ss[i + kk - 1] + ss[i + kk]
	smax = max(smax, ssum)
print(smax)


(n, k) = map(int, input().split())
s = input()
h = list()
h.append(0)
for i in range(n - 1):
	if s[i] != s[i + 1]:
		h.append(i + 1)
m = len(h)
for i in range(2 * k + 1):
	h.append(n)
mx = 0
for i in range(m):
	if s[h[i]] == '0':
		mx = max(mx, h[i + 2 * k] - h[i])
	else:
		mx = max(mx, h[i + 2 * k + 1] - h[i])
print(mx)


(n, k) = map(int, input().split())
s = input()
cnt = []
now = s[0]
p = 0
for i in range(n):
	if s[i] == now:
		p += 1
	else:
		cnt.append(p)
		now = s[i]
		p = 1
cnt.append(p)
ans = 0
r = []
cum_sum = 0
for i in range(len(cnt)):
	cum_sum += cnt[i]
	r.append((cnt[i], cum_sum))
for i in range(len(r)):
	if s[r[i][1] - r[i][0]] == '1':
		e = r[min(i + 2 * k, len(r) - 1)][1] - r[i][1] + r[i][0]
	else:
		e = r[min(i + 2 * k - 1, len(r) - 1)][1] - r[i][1] + r[i][0]
	ans = max(ans, e)
print(ans)


(n, k) = map(int, input().split())
S = input()
start = []
end = [0]
if S[0] == '0':
	start.append(0)
for i in range(n):
	if S[i:i + 2] == '10':
		start.append(i + 1)
	elif S[i:i + 2] == '01':
		end.append(i + 1)
if len(start) <= k:
	print(len(S))
else:
	start.append(len(S))
	ans = []
	for i in range(len(start) - k):
		ans.append(start[i + k] - end[i])
	print(max(ans))


(N, K) = map(int, input().split())
S = input()
L = [0]
X = ['1']
pos = 0
for i in range(N):
	if S[i] != X[pos]:
		L.append(1)
		X.append(S[i])
		pos += 1
	else:
		L[pos] += 1
while pos < 2 * K + 4:
	L.append(0)
	X.append('1')
	pos += 1
L.append(0)
X.append('1')
n = len(L)
for i in range(1, n):
	L[i] += L[i - 1]
M = L[2 * K]
for i in range(1, n - 2 * K):
	if X[i] == '1':
		M = max(L[2 * K + i] - L[i - 1], M)
print(M)


import bisect
(n, k) = map(int, input().split())
s = list(map(int, input()))
f = [0 for i in range(n)]
f[0] = 1 - s[0]
for i in range(1, n):
	f[i] = (1 - s[i]) * (s[i - 1] ^ s[i])
for i in range(n - 1):
	f[i + 1] += f[i]
ans = 0
for l in range(n):
	r = bisect.bisect_right(f, k + f[l] * s[l])
	ans = max(ans, r - l)
print(ans)


(n, k) = map(int, input().split())
s = input()
if s[0] == '1':
	l = [1]
else:
	l = [0, 1]
for i in range(1, n):
	if s[i] == s[i - 1]:
		l[-1] += 1
	else:
		l.append(1)
prev = sum(l[0:2 * k + 1])
ans = prev
for i in range(len(l) // 2 + 1):
	prev = prev - sum(l[2 * i:2 * i + 2]) + sum(l[2 * i + 2 * k + 1:2 * i + 2 * k + 3])
	ans = max(ans, prev)
print(ans)


(n, k) = map(int, input().split())
s = input()
cand_index = [0]
for i in range(n - 1):
	if s[i] != s[i + 1]:
		cand_index.append(i + 1)
cand_index.append(n)
count = []
for i in range(len(cand_index) - 1):
	index = min(i + 2 * k + int(s[cand_index[i]] == '1'), len(cand_index) - 1)
	count.append(cand_index[index] - cand_index[i])
print(max(count))


(N, K) = map(int, input().split())
S = input()
X = []
j = '1'
num = 0
for i in S:
	if j != i:
		X.append(num)
		j = i
		num = 1
	else:
		num += 1
X.append(num)
if j == '0':
	X.append(0)
Y = [0]
for i in X:
	Y.append(Y[-1] + i)
ans = 0
for i in range(1, len(Y), 2):
	t = min(i + 2 * K, len(Y) - 1)
	ans = max(ans, Y[t] - Y[i - 1])
print(ans)


from itertools import *
(n, k) = map(int, input().split())
s = input()
t = [0] * (s[0] == '0') + [len(list(g)) for (_, g) in groupby(s)] + [0] * (s[-1] == '0' or 1 - ('1' in s))
(a, b) = (t[::2], t[1::2])
l = len(t) // 2
k = min(k, l)
t = r = sum(a[:k + 1] + b[:k])
for (w, x, y, z) in zip(a, b, a[k + 1:], b[k:]):
	t += -w - x + y + z
	r = max(r, t)
print(r)


(n, k) = list(map(int, input().split()))
s = input()
d = []
if s[0] == '0':
	zero = True
	iti = False
else:
	iti = True
	zero = False
count = 0
for i in range(0, len(s)):
	if zero and s[i] == '0':
		count += 1
	elif zero and s[i] == '1':
		d.append(count)
		iti = True
		zero = False
		count = 1
	elif iti and s[i] == '0':
		d.append(count)
		zero = True
		iti = False
		count = 1
	elif iti and s[i] == '1':
		count += 1
d.append(count)
d.append(0)
import itertools
acum = list(itertools.accumulate([0] + d))
hantei = 0
ans = 0
if s[0] == '0':
	ks1 = min(k * 2, len(d))
	ks2 = min(k * 2 + 1, len(d))
else:
	ks1 = min(k * 2 + 1, len(d))
	ks2 = min(k * 2, len(d))
for i in range(0, len(d) - ks1 + 1, 2):
	ans = max(acum[i + ks1] - acum[i], ans)
for i in range(1, len(d) - ks2 + 1, 2):
	ans = max(acum[i + ks2] - acum[i], ans)
print(ans)


(n, k) = map(int, input().split())
s = list(map(int, list(input())))
x = [-1]
for i in range(n - 1):
	if s[i] != s[i + 1]:
		x.append(i)
x.append(n - 1)
t = len(x)
ans = 1
for i in range(t - 1):
	if i % 2 == s[0]:
		ans = max(ans, x[min(t - 1, i + 2 * k)] - x[i])
	else:
		ans = max(ans, x[min(t - 1, i + 2 * k + 1)] - x[i])
print(ans)


(N, K) = list(map(int, input().split()))
S = input()
S = S + 'E'
ans = -1
if S[0] == '0':
	stand = 1
else:
	stand = 0
L = 0
R = 0
while R < N:
	if stand <= K:
		if S[R] == '1' and S[R + 1] == '0':
			stand += 1
		ans = max(ans, R - L + 1)
		R += 1
	elif L == R:
		L += 1
		R += 1
	else:
		if S[L] == '0' and S[L + 1] == '1':
			stand -= 1
		L += 1
print(ans)


(n, k) = (int(i) for i in input().split())
s = input()
change = []
leng = len(s)
flag = ''
ans = 0
w = 2 * k + 1
if s[0] == '0':
	change.append(0)
for i in range(leng):
	if s[i] != flag:
		flag = s[i]
		change.append(i)
change.append(leng)
if s[-1] == '0':
	change.append(leng)
leng = len(change)
if leng <= w:
	print(n)
	exit()
for i in range(0, leng - w, 2):
	ans = max(ans, change[i + w] - change[i])
print(ans)


(N, K) = map(int, input().split())
S = input()
A = []
B = []
for i in range(N - 1):
	if S[i] == '0' and S[i + 1] == '1':
		B.append(i)
if S[-1] == '0':
	B.append(N - 1)
if S[0] == '0':
	A.append(0)
for i in range(N - 1):
	if S[i] == '1' and S[i + 1] == '0':
		A.append(i + 1)
if len(A) <= K:
	print(N)
else:
	y = A[K]
	z = N - B[-1 * (K + 1)] - 1
	l = 0
	ans = 0
	for i in range(len(A) - K - 1):
		l = A[i + K + 1] - B[i] - 1
		ans = max(l, ans)
	print(max(ans, y, z))


(n, k) = map(int, input().split())
s = list(input())
idx = []
idx.append(0)
for i in range(1, n):
	if s[i] != s[i - 1]:
		idx.append(i)
arr = idx + [n] * (2 * k + 1)
ans = -10 ** 18
z = 0
for m in idx:
	if s[m] == '0':
		ans = max(ans, arr[z + 2 * k] - arr[z])
	else:
		ans = max(ans, arr[z + 2 * k + 1] - arr[z])
	z += 1
print(ans)


(N, K) = map(int, input().split())
S = input()
o = []
l = [0]
prev = '1'
for s in S:
	if s == '1':
		if prev == '0':
			l.append(1)
		else:
			l[-1] += 1
	elif prev == '1':
		o.append(1)
	else:
		o[-1] += 1
	prev = s
l.append(0)
agg = sum(l[0:K + 1]) + sum(o[0:K])
max_agg = agg
for i in range(1, len(o) - K + 1):
	agg -= l[i - 1] + o[i - 1]
	agg += l[i + K] + o[i + K - 1]
	max_agg = max(max_agg, agg)
print(max_agg)


(n, k) = map(int, input().split())
l = [0]
s = input()
cnt = 0
for c in s:
	if len(l) % 2 ^ (c == '0'):
		cnt += 1
	else:
		l.append(cnt)
		cnt += 1
l.append(cnt)
if len(l) % 2:
	l.append(cnt)
k = min(k, (len(l) - 1) // 2)
ans = 0
for i in range(0, len(l) - 2 * k - 1, 2):
	ans = max(ans, l[i + 2 * k + 1] - l[i])
print(ans)


(N, K) = map(int, input().split())
S = input()
a = [0]
for i in range(1, N):
	if S[i - 1] != S[i]:
		a.append(i)
a.append(N)
l = len(a)
ans = []
for i in range(l - 1):
	if S[a[i]] == '0':
		ans.append(a[min(i + 2 * K, l - 1)] - a[i])
	else:
		ans.append(a[min(i + 2 * K + 1, l - 1)] - a[i])
print(max(ans))


import sys
sys.setrecursionlimit(10 ** 6)
(n, k) = map(int, input().split())
s = input()
nums = []
now = 1
cnt = 0
for i in range(n):
	if s[i] == str(now):
		cnt += 1
	else:
		nums.append(cnt)
		now ^= 1
		cnt = 1
if cnt != 0:
	nums.append(cnt)
if len(nums) % 2 == 0:
	nums.append(0)
add = 2 * k + 1
ans = 0
left = 0
right = 0
tmp = 0
for i in range(0, len(nums), 2):
	nextleft = i
	nextright = min(i + add, len(nums))
	while nextleft > left:
		tmp -= nums[left]
		left += 1
	while nextright > right:
		tmp += nums[right]
		right += 1
	ans = max(tmp, ans)
print(ans)


(n, k) = map(int, input().split())
s = input()
s += 'X'
i = 0
j = 0
zero = 1 if s[0] == '0' else 0
ans = 0
while j < n:
	if zero <= k:
		ans = max(ans, j - i + 1)
		if s[j] == '1' and s[j + 1] == '0':
			zero += 1
		j += 1
	else:
		if s[i] == '0' and s[i + 1] == '1':
			zero -= 1
		i += 1
print(ans)


(N, K) = [int(_) for _ in input().split()]
S = input()
S = '0' + S + '0'
X = []
for i in range(N + 1):
	if S[i] == '0' and S[i + 1] == '1':
		st = i + 1
	if S[i] == '1' and S[i + 1] == '0':
		en = i
		X.append((st, en))
M = len(X)
ans = 0
for i in range(len(X) - K):
	st = X[i][0]
	en = X[i + K][1]
	ans = max(ans, en - st + 1)
if M == 0 or M + 2 < K:
	ans = N
if K <= M:
	en = X[K - 1][1]
	ans = max(ans, en - 1 + 1)
	st = X[-K][0]
	ans = max(ans, N - st + 1)
print(ans)


(n, k) = map(int, input().split())
s = list(map(int, input()))
cnt = 0
ans = 0
start = 0
for i in range(n):
	if s[i] == 0 and (i == 0 or s[i - 1] == 1):
		cnt += 1
	if cnt == k + 1:
		while True:
			start += 1
			if s[start - 1] == 0 and s[start] == 1:
				break
		cnt -= 1
	ans = max(ans, i - start + 1)
print(ans)


(N, K) = [int(i) for i in input().split()]
S = input()
si = [1]
si.extend((2 + i for (i, (s1, s2)) in enumerate(zip(S, S[1:])) if s1 != s2))
si.append(N + 1)

def f(i, si):
	return si[min(i + 2 * K + 1, len(si)) - 1] - si[i - 1]
j0 = min(1 + 2 * K + (1 if S[0] == '1' else 0), len(si)) - 1
x0 = si[j0] - 1
x = [x0]
x.extend((f(i + 1, si) for i in range(2 if S[0] == '1' else 1, len(si), 2)))
print(max(x))


(N, K) = map(int, input().split())
S = '1' + input() + '1'
s = 0
t = 0
k = 0
l = 0
while s < N:
	while s < N:
		s += 1
		if S[s] == '0' and S[s + 1] == '1':
			k += 1
		if k == K and S[s] == '1' and (S[s + 1] == '0'):
			break
	l = max(s - t, l)
	while t < s:
		t += 1
		if S[t] == '0' and S[t + 1] == '1':
			k -= 1
			break
print(l)


(n, k) = map(int, input().split())
s = input()
ls = []
now = 1
cnt = 0
for ele in s:
	if int(ele) == now:
		cnt += 1
	else:
		ls.append(cnt)
		now = 1 - now
		cnt = 1
ls.append(cnt)
if len(ls) % 2 == 0:
	ls.append(0)
Add = 2 * k + 1
ans = 0
left = 0
right = 0
tmp = 0
for i in range(0, len(ls), 2):
	nextLeft = i
	nextRight = min(i + Add, len(ls))
	while nextLeft > left:
		tmp -= ls[left]
		left += 1
	while nextRight > right:
		tmp += ls[right]
		right += 1
	ans = max(tmp, ans)
print(ans)


(n, k) = map(int, input().split())
s = input()
l = []
if s[0] == '0':
	l.append(0)
from itertools import groupby, accumulate
gr = groupby(s)
for (K, g) in gr:
	l.append(len(list(g)))
l_sum = list(accumulate(l))
l_sum = [0] + l_sum
add = 2 * k + 1
ans = 0
for i in range(0, len(l) + 1, 2):
	left = i
	right = min(i + add, len(l))
	tmp = l_sum[right] - l_sum[left]
	ans = max(tmp, ans)
print(ans)


(n, k) = map(int, input().split())
sl = list(input())
l = []
l.append(0)
ans = 0
before = ''
count = 0
if sl[0] == '0':
	l.append(0)
for (idx, s) in enumerate(sl):
	if s != before:
		before = s
		if idx > 0:
			l.append(idx)
			if len(l) == 2 * k + 2:
				ans = max(l[-1] - l[0], ans)
				l.pop(0)
				l.pop(0)
l.append(n)
ans = max(l[-1] - l[0], ans)
print(ans)


(N, K) = map(int, input().split())
S = input()
po = [0]
X = []
i = 0
for i in range(N - 1):
	if not S[i] == S[i + 1]:
		po.append(i + 1)
po.append(len(S))
for i in range(len(po)):
	if 2 * K + 1 >= len(po):
		X.append(po[-1])
		break
	elif 2 * K + i + 1 >= len(po):
		X.append(po[2 * K + i] - po[i])
		break
	elif S[po[i]] == '0':
		X.append(po[2 * K + i] - po[i])
	else:
		X.append(po[2 * K + 1 + i] - po[i])
print(max(X))


def func():
	(N, K) = map(int, input().split())
	S = input()
	L = []
	L.append(0) if S[0] == '0' else 0
	num = '2'
	for i in range(N):
		if num != S[i]:
			L.append(i)
			num = S[i]
	L.append(N)
	L.append(N)
	ans = 0
	for i in range(0, len(L) - K * 2 - 1, 2):
		ans = max(ans, L[i + K * 2 + 1] - L[i])
	return N if N < 3 or K >= len(L) // 2 else ans
print(func())


(n, k) = map(int, input().split())
s = list(input())
L = [0]
R = []
for (i, (a, b)) in enumerate(zip(s, s[1:])):
	if (a, b) == ('0', '1'):
		L.append(i + 1)
	if (a, b) == ('1', '0'):
		R.append(i)
else:
	R.append(n - 1)
ans = R[0] - L[0] + 1
if s[0] == '0':
	k -= 1
k = min(k, len(R) - 1)
for (l, r) in zip(L, R[k:]):
	x = r - l + 1
	if ans < x:
		ans = x
print(ans)


(n, k) = map(int, input().split())
s = input()
I = [0]
for i in range(n - 1):
	if s[i] != s[i + 1]:
		I.append(i + 1)
r = len(I)
for _ in range(10 ** 6):
	I.append(n)
X = []
for i in range(r):
	if s[I[i]] == '0':
		X.append(I[i + 2 * k] - I[i])
	else:
		X.append(I[i + 2 * k + 1] - I[i])
print(max(X))


(nim, mike) = map(int, input().split())
data = input()
X = []
Y = [0]
_s = '2'
for (i, s) in enumerate(data):
	if _s != s:
		_s = s
		X.append(i)
		Y.append((int(s) + 1) % 2)
import itertools
Y = list(itertools.accumulate(Y))
ans = []
for (i, x) in enumerate(X):
	if Y[-1] - Y[i] <= mike:
		ans.append(nim - x)
		break
	elif data[x] == '0':
		ans.append(X[i + 2 * mike] - x)
	else:
		ans.append(X[i + 2 * mike + 1] - x)
print(max(ans))


(n, k) = map(int, input().split())
S = input() + '*'
A = [0] if S[0] == '1' else [0, 0]
(cnt, num) = (0, S[0])
for i in range(n + 1):
	if num == S[i]:
		cnt += 1
	else:
		A.append(cnt)
		cnt = 1
		num = S[i]
for i in range(1, len(A)):
	A[i] = A[i] + A[i - 1]
ans = 0
for i in range(0, len(A), 2):
	ans = max(ans, A[min(i + k * 2 + 1, len(A) - 1)] - A[i])
print(ans)


from itertools import accumulate

def resolve():
	(N, K) = map(int, input().split())
	S = input()
	L = []
	pre = '1'
	cnt = 0
	for i in range(N):
		if pre == S[i]:
			cnt += 1
		else:
			L.append(cnt)
			cnt = 1
		pre = S[i]
	L.append(cnt)
	if pre == '0':
		L.append(0)
	length = 2 * K + 1
	if len(L) <= length:
		return print(N)
	acc = [0] + list(accumulate(L))
	ans = 0
	for i in range(0, len(L) - length + 1, 2):
		ans = max(ans, acc[i + length] - acc[i])
	print(ans)

def __starting_point():
	resolve()
__starting_point()


(N, K) = list(map(int, input().split()))
S = input()
S += 'X'
i = 0
j = 0
max_len = 0
change = 0 if S[0] != '0' else 1
while j < len(S) - 1:
	if change <= K:
		max_len = max([j - i + 1, max_len])
		if S[j:j + 2] == '10':
			change += 1
		j += 1
	else:
		if S[i:i + 2] == '01':
			change -= 1
		i += 1
print(max_len)


def main():
	(n, k) = list(map(int, input().split()))
	s = input()
	L = []
	if s[0] == '0':
		z = 1
		l = 0
	else:
		z = 0
	for i in range(n):
		if s[i] == '0' and z == 0:
			l = i
			z = 1
		elif s[i] == '1' and z == 1:
			L.append([l, i - 1])
			z = 0
	if z == 1:
		L.append([l, n - 1])
	ans = 0
	if len(L) <= k:
		ans = n
	else:
		l = 0
		r = L[k][0] - 1
		if r - l + 1 > ans:
			ans = r - l + 1
		for i in range(1, len(L) - k):
			l = L[i - 1][1] + 1
			r = L[i + k][0] - 1
			if r - l + 1 > ans:
				ans = r - l + 1
		l = L[-k - 1][1] + 1
		r = n - 1
		if r - l + 1 > ans:
			ans = r - l + 1
	print(ans)

def __starting_point():
	main()
__starting_point()


(N, K) = [int(a) for a in input().split()]
S = '1' + str(input()) + '0'
ans = 0
cnt = 1 if S[1] == '0' else 0
num = 0
(l, r) = (1, 1)
while r <= N:
	while cnt <= K and r <= N:
		if S[r] == '1' and S[r + 1] == '0':
			cnt += 1
		num += 1
		r += 1
	ans = max(num, ans)
	while cnt > K and l <= N:
		num -= 1
		l += 1
		if S[l] == '1' and S[l - 1] == '0':
			cnt -= 1
print(ans)


(t, s) = open(0)
(n, k) = map(int, t.split())
l = 2 * k + 1
x = [0] * (2 + int(s[0])) + [i + 1 for i in range(n - 1) if s[i] != s[i + 1]] + [n] * l
print(max((x[i + l] - x[i] for i in range(0, len(x) - l, 2))))


import sys

def f(S):
	(c, n) = (S[0], 1)
	for cc in S[1:]:
		if c == cc:
			n += 1
		else:
			yield (c, n)
			(c, n) = (cc, 1)
	yield (c, n)

def solve(N: int, K: int, S: str):
	from itertools import zip_longest
	A = list(f(S))
	M = len(A)
	(i, j, k, su, ans) = (0, 0, 0, 0, 0)
	while i < M:
		while j < M and (k < K or A[j][0] == '1'):
			su += A[j][1]
			k += 1 if A[j][0] == '0' else 0
			j += 1
		ans = max(ans, su)
		su -= A[i][1]
		k -= 1 if A[i][0] == '0' else 0
		i += 1
	return ans

def main():

	def iterate_tokens():
		for line in sys.stdin:
			for word in line.split():
				yield word
	tokens = iterate_tokens()
	N = int(next(tokens))
	K = int(next(tokens))
	S = next(tokens)
	print(solve(N, K, S))

def test():
	import doctest
	doctest.testmod()

def __starting_point():
	main()
__starting_point()


(N, K) = list(map(int, input().split()))
S = input()
list10 = []
head = S[0]
cnt = 0
if S[0] == '0':
	list10.append(0)
for i in range(N):
	if S[i] == head:
		cnt += 1
	else:
		list10.append(cnt)
		cnt = 1
		head = S[i]
	if i == N - 1:
		list10.append(cnt)
if S[-1] == '0':
	list10.append(0)
ans = 0
cumsum = [0]
for li in list10:
	cumsum.append(cumsum[-1] + li)
for j in range(1, len(cumsum), 2):
	h = j
	t = min(j + 2 * K, len(cumsum) - 1)
	ans = max(ans, cumsum[t] - cumsum[max(h - 1, 0)])
print(ans)


(N, K) = map(int, input().split())
s = input()
I = []
for j in range(len(s)):
	if j == 0:
		I.append(0)
	elif s[j - 1] != s[j]:
		I.append(j)
r = len(I)
I = I + [N] * (3 * K)
x = []
for k in range(r):
	if s[I[k]] == '0':
		x.append(I[k + 2 * K] - I[k])
	else:
		x.append(I[k + 2 * K + 1] - I[k])
print(max(x))


(n, k) = map(int, input().split())
l = list(input())
ans = 0
check = [[0]]
i = 0
while i < n:
	if l[i] == '1':
		a = i
		while i < n and l[i] == '1':
			i += 1
		check.append([a, i - 1])
	i += 1
check.append([n - 1])
if len(check) - k < 1:
	print(n)
	exit()
for i in range(len(check) - k):
	ans = max(ans, check[i + k][-1] - check[i][0] + 1)
print(ans)


(n, k) = map(int, input().split())
s = input()
seq = []
pre = '1'
count = 0
for c in s:
	if c == pre:
		count += 1
	else:
		pre = c
		seq.append(count)
		count = 1
seq.append(count)
n = len(seq)
sum = sum(seq[:2 * k + 1])
ans = sum
seq.append(0)
for i in range(0, n - 2 * k - 1, 2):
	sum -= seq[i] + seq[i + 1]
	sum += seq[i + 2 * k + 1] + seq[i + 2 * k + 2]
	ans = max(ans, sum)
print(ans)


(n, k) = map(int, input().split())
s = input()
c = [0]
import itertools
for (_, g) in itertools.groupby(s):
	c.append(c[-1] + len(list(g)))
c = c[1:]
if s[0] == '1':
	c = [0] + c
else:
	c = [0, 0] + c
if s[-1] == '0':
	c = c + [c[-1]]
ans = 0
for i in range(0, len(c), 2):
	end = min(i + 2 * k + 1, len(c) - 1)
	ans = max(ans, c[end] - c[i])
print(ans)


(n, k) = map(int, input().split())
s = input()
ss = []
ss.append(0)
for i in range(n - 1):
	a = s[i]
	if a == s[i + 1]:
		continue
	ss.append(i + 1)
ss.append(n)
ans = 0
for i in range(len(ss)):
	p = ss[i]
	if p == n:
		break
	if s[p] == '0':
		ans = max(ans, ss[min(2 * k + i, len(ss) - 1)] - ss[i])
	else:
		ans = max(ans, ss[min(2 * k + 1 + i, len(ss) - 1)] - ss[i])
print(ans)


def solve(N, K, S):
	S = [int(s) for s in S]
	point_l = 0
	point_r = 0
	num_0 = 0 if S[0] == 1 else 1
	flg = S[0]
	for i in range(N):
		if S[i] != flg:
			if flg == 1:
				num_0 += 1
				if num_0 > K:
					point_r = i - 1
					break
			flg = S[i]
		if i == N - 1:
			point_r = i
			break
	ans = point_r - point_l + 1
	while point_r < N - 1:
		for i in range(0, N):
			if S[point_l + i] != S[point_l + i + 1]:
				if S[point_l + i + 1] == 1:
					point_l += i + 1
					break
		for i in range(1, N):
			if point_r + i == N - 1:
				point_r = N - 1
				break
			if S[point_r + i] != S[point_r + i + 1]:
				if S[point_r + i + 1] == 0:
					point_r += i
					break
		ans = max(ans, point_r - point_l + 1)
	print(ans)

def __starting_point():
	(N, K) = list(map(int, input().split()))
	S = input()
	solve(N, K, S)
__starting_point()


def solve(string):
	(n, k, s) = string.split()
	(n, k) = map(int, [n, k])
	flip = [0] + [i for (i, (s0, s1)) in enumerate(zip(s, s[1:]), start=1) if s0 != s1] + [n]
	start = int(s[0])
	l = len(flip) - 1
	return str(max([flip[min(l, i + 2 * k + (i % 2 ^ start))] - flip[i] for i in range(l + 1)]))
print(solve('\n'.join([input(), input()])))


(n, k) = map(int, input().split())
s = input()
s = '01' + s + '10'
S = []
E = []
ans = []
for i in range(n + 3):
	if s[i:i + 2] == '01':
		S.append(i + 1)
	if s[i:i + 2] == '10':
		E.append(i)
if S == [] and E == []:
	print(n)
else:
	for j in range(len(E) - k):
		ans.append(abs(S[j] - E[j + k]))
	if ans != []:
		ans[0] -= 1
		ans[len(ans) - 1] -= 1
		print(max(ans) + 1)
	else:
		print(n)


(n, k) = map(int, input().split())
s = input()
ban = []
if s[0] == '0':
	ban.append(0)
cnt = 1
for (i, val) in enumerate(s[:-1]):
	if val != s[i + 1]:
		ban.append(cnt)
		cnt = 0
	cnt += 1
if cnt > 0:
	ban.append(cnt)
if s[n - 1] == '0':
	ban.append(0)
ans = sum(ban[0:2 * k + 1])
su = ans
now = 0
while now + 2 * k + 2 <= len(ban):
	su -= ban[now] + ban[now + 1]
	su += ban[now + 2 * k + 1] + ban[now + 2 * k + 2]
	if su > ans:
		ans = su
	now += 2
print(ans)


(N, K) = map(int, input().split())
S = input()
(A, B) = ([], [])
(cnt_0, cnt_1) = (0, 0)
for i in range(N):
	if S[i] == '0':
		cnt_0 += 1
		if cnt_1 > 0:
			A.append(cnt_1)
		cnt_1 = 0
	else:
		cnt_1 += 1
		if cnt_0 > 0:
			A.append(-cnt_0)
		cnt_0 = 0
if cnt_1 > 0:
	A.append(cnt_1)
if cnt_0 > 0:
	A.append(-cnt_0)
M = len(A)
minus_cnt = 0
s = 0
right = M
for i in range(M):
	if A[i] < 0 and minus_cnt == K:
		right = i
		break
	if A[i] < 0:
		minus_cnt += 1
	s += abs(A[i])
left = 0
ans = s
while right < M:
	for i in range(2):
		if not right < M:
			break
		s += abs(A[right])
		right += 1
	while left < M:
		if A[left] < 0:
			s -= abs(A[left])
			left += 1
			break
		s -= abs(A[left])
		left += 1
	ans = max(ans, s)
print(ans)


(N, K) = map(int, input().split())
S = input()
X = []
Y = [0]
_s = '2'
for (i, s) in enumerate(S):
	if _s != s:
		_s = s
		X.append(i)
		Y.append((int(s) + 1) % 2)
import itertools
Y = list(itertools.accumulate(Y))
ans = []
for (i, x) in enumerate(X):
	if Y[-1] - Y[i] <= K:
		ans.append(N - x)
		break
	elif S[x] == '0':
		ans.append(X[i + 2 * K] - x)
	else:
		ans.append(X[i + 2 * K + 1] - x)
print(max(ans))


(N, K) = map(int, input().split())
S = input()
l = 0
alt = 0
cnt = 0
for r in range(N):
	if S[r] == '0' and (r == 0 or S[r - 1] == '1'):
		alt += 1
	if alt > K:
		while S[l] == '1':
			l += 1
		while S[l] == '0':
			l += 1
		alt -= 1
	cnt = max(cnt, r - l + 1)
print(cnt)


(n, k) = list(map(int, input().split()))
s = list(input())
cnt = []
if s[0] == '0':
	cnt.append(0)
i = 0
while i < n:
	j = i
	while j < n and s[j] == s[i]:
		j += 1
	cnt.append(j - i)
	i = j
if s[-1] == '0':
	cnt.append(0)
m = len(cnt)
cs = [0] * (m + 1)
for i in range(m):
	cs[i + 1] = cs[i] + cnt[i]
ans = 0
for l in range(0, m + 1, 2):
	r = l + 2 * k + 1
	if r > m:
		r = m
	ans = max(ans, cs[r] - cs[l])
print(ans)


(N, K) = map(int, input().split())
S = input()
arr = []
if S[0] == '0':
	arr.append(0)
cnt = 0
for i in range(N - 1):
	if S[i] == S[i + 1]:
		cnt += 1
	else:
		arr.append(cnt + 1)
		cnt = 0
arr.append(cnt + 1)
if S[-1] == '0':
	arr.append(0)
res = 0
s = 0
i = 0
while i < 2 * K + 1 and i < len(arr):
	s += arr[i]
	i += 1
res = s
while i < len(arr) - 1:
	s += arr[i] + arr[i + 1] - arr[i - 2 * K - 1] - arr[i - 2 * K]
	res = max(s, res)
	i += 2
print(res)


(n, k) = map(int, input().split())
s = input()
ans = 0
s = s + 'E'
if s[0] == '0':
	order = 1
else:
	order = 0
(l, r) = (0, 0)
while r < n:
	if order <= k:
		if s[r] == '1' and s[r + 1] == '0':
			order += 1
		ans = max(ans, r - l + 1)
		r += 1
	elif l == r:
		l += 1
		r += 1
	else:
		if s[l] == '0' and s[l + 1] == '1':
			order -= 1
		l += 1
print(ans)


from itertools import *
(N, K) = map(int, input().split())
S = input()
nums = []
if S[0] == '0':
	nums.append(0)
i = 0
while i < len(S):
	j = i
	while j < len(S) and S[j] == S[i]:
		j += 1
	nums.append(j - i)
	i = j
if S[-1] == '0':
	nums.append(0)
sums = [0] + list(accumulate(nums))
ans = 0
for left in range(0, len(sums), 2):
	right = left + K * 2 + 1
	if len(sums) <= right:
		right = len(sums) - 1
	ans = max(ans, sums[right] - sums[left])
print(ans)


import numpy as np
(N, K) = list(map(int, input().split()))
S = list(input())
nums = []
now = 1
cnt = 0
for s in S:
	if s == str(now):
		cnt += 1
	else:
		nums.append(cnt)
		now = 1 - now
		cnt = 1
if cnt != 0:
	nums.append(cnt)
if len(nums) % 2 == 0:
	nums.append(0)
sums = [0] + list(np.cumsum(nums))
left = 0
right = left + K * 2
maxi = 0
if N < 3:
	maxi = N
while right < len(nums):
	if sums[right + 1] - sums[left] > maxi:
		maxi = sums[right + 1] - sums[left]
	right += 2
	left += 2
if maxi == 0:
	maxi = sum(nums)
print(maxi)


(N, K) = list(map(int, input().split()))
S = input()
n = 1
c = []
if S[0] == '0':
	c.append(0)
for i in range(1, N):
	if S[i] != S[i - 1]:
		c.append(n)
		n = 1
	else:
		n += 1
c.append(n)
if S[-1] == '0':
	c.append(0)
t = sum(c[:2 * K + 1])
m = t
for i in range(2 * K + 1, len(c), 2):
	t += c[i] + c[i + 1] - c[i - (2 * K + 1)] - c[i + 1 - (2 * K + 1)]
	m = max(m, t)
print(m)


(n, k) = map(int, input().split())
s = input()
start = [0]
ret = 0
first = False
for i in range(len(s)):
	if s[i] == '1' and first:
		start.append(i)
		first = False
	if s[i] == '0' and (not first):
		ret = max(ret, i - start[max(0, len(start) - k - 1)])
		first = True
if first:
	start.append(len(s))
ret = max(ret, len(s) - start[max(0, len(start) - k - 1)])
print(ret)


(n, k) = map(int, input().split(' '))
s = input()
l = []
if s[0] == '0':
	l.append((0, 0))
i = 0
while i < n:
	if s[i] == '1':
		b = i
		while i < n and s[i] == '1':
			i += 1
		l.append((b, i))
	i += 1
if s[n - 1] == '0':
	l.append((n, n))
if len(l) - 1 <= k:
	print(n)
else:
	maximum = 0
	for i in range(len(l) - k):
		maximum = max(maximum, l[i + k][1] - l[i][0])
	print(maximum)


(n, k) = list(map(int, input().split()))
s = input()
a = []
i = 0
while i < n:
	j = 1
	while i + j < n and s[i] == s[i + j]:
		j += 1
	a.append((s[i], j))
	i += j
if a[0][0] == '0':
	a = [('1', 0)] + a
if a[-1][0] == '1':
	a.append(('0', 0))
while len(a) < k * 2:
	a.append(('1', 0))
	a.append(('0', 0))
m = len(a)
s = [0] * (m + k * 5 + 1)
for i in range(m + k * 2):
	if i < m:
		s[i + 1] = s[i] + a[i][1]
	else:
		s[i + 1] = s[i]
ans = 0
for i in range(1, m, 2):
	ans = max(ans, s[i + k * 2] - s[i - 1])
print(ans)


(N, K) = map(int, input().split())
S = list(input())
j = 0
ans = 0
cnt = 0
for i in range(N):
	if S[i] == '0':
		if i == 0 or S[i - 1] == '1':
			cnt += 1
	if cnt > K:
		while S[j] == '1':
			j += 1
		while S[j] == '0':
			j += 1
		cnt -= 1
	ans = max(ans, i - j + 1)
print(ans)


(N, K) = map(int, input().split())
S = input()
bl = []
if S[0] == '0':
	bl.append(0)
bl.append(0)
for i in range(1, N):
	if S[i - 1] != S[i]:
		bl.append(i)
bl.append(N)
bl.append(N)
nbl = len(bl)
m = [bl[i + 2 * K + 1] - bl[i] for i in range(nbl - 2 * K - 1) if i % 2 == 0]
if len(m) == 0:
	print(N)
else:
	print(max(m))


(n, k) = map(int, input().split())
s = list(input())
s_0_1 = [1] * (k + int(s[0]))
s_1_0 = []
for i in range(n - 1):
	if s[i] == '0' and s[i + 1] == '1':
		s_0_1.append(i + 2)
	elif s[i] == '1' and s[i + 1] == '0':
		s_1_0.append(i + 1)
s_1_0.extend([n] * (k + int(s[-1])))
ans = 0
for i in range(len(s_0_1)):
	ans = max(ans, s_1_0[i] - s_0_1[i] + 1)
print(ans)


(n, k) = map(int, input().split())
s = input()
list10 = {'0': [], '1': []}
pre_c = '1'
c_c = 0
cur_sum = 0
cur_max = 0
for c in s:
	if c == pre_c:
		c_c += 1
	else:
		list10[pre_c].append(c_c)
		cur_sum += c_c
		c_c = 1
		pre_c = c
	if len(list10['1']) == k + 1:
		cur_max = max(cur_max, cur_sum)
		cur_sum -= list10['0'].pop(0) + list10['1'].pop(0)
print(max(cur_max, cur_sum + c_c))


from math import ceil, floor, factorial, gcd, sqrt, log2, cos, sin, tan, acos, asin, atan, degrees, radians, pi, inf
from itertools import accumulate, groupby, permutations, combinations, product, combinations_with_replacement
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
from operator import itemgetter
from heapq import heapify, heappop, heappush
from queue import Queue, LifoQueue, PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)

def input():
	return sys.stdin.readline().strip()

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST():
	return list(MAP())
(n, k) = MAP()
s = input()
count = 0
flag = 1
que = deque([0] * (2 * k + 1))
ans = 0
tmp = 0
for x in s:
	if x == '0':
		if flag == 1:
			que.append(count)
			tmp += count - que.popleft()
			ans = max(ans, tmp)
			count = 0
		flag = 0
		count += 1
	else:
		if flag == 0:
			que.append(count)
			tmp += count - que.popleft()
			count = 0
		flag = 1
		count += 1
que.append(count)
tmp += count - que.popleft()
if s[-1] == '0':
	tmp -= que.popleft()
ans = max(ans, sum(que))
print(ans)


def main():
	(N, K) = [int(x) for x in input().split(' ')]
	S = list(input())
	cnt = [0]
	a = 0
	for i in range(len(S)):
		if S[i] == '0':
			if a % 2 == 0:
				a += 1
				cnt.append(1)
			else:
				cnt[-1] += 1
		elif S[i] == '1':
			if a % 2 == 0:
				cnt[-1] += 1
			else:
				a += 1
				cnt.append(1)
	if S[-1] == '0':
		cnt.append(0)
	if K >= (len(cnt) - 1) / 2:
		print(N)
		return 0
	T = [sum(cnt[:2 * K + 1])]
	for i in range(0, len(cnt) - 2 * K - 2, 2):
		T.append(T[-1] - cnt[i] - cnt[i + 1] + cnt[i + 2 * K + 1] + cnt[i + 2 * K + 2])
	print(max(T))
main()


(n, k) = map(int, input().split())
s = input()
nums = []
if s[0] == '0':
	nums.append(0)
i = 0
while i < n:
	j = i
	while j < n and s[j] == s[i]:
		j += 1
	nums.append(j - i)
	i = j
if s[-1] == '0':
	nums.append(0)
sums = [0]
for i in range(len(nums)):
	sums.append(sums[-1] + nums[i])
res = 0
for left in range(0, len(sums), 2):
	right = left + k * 2 + 1
	if right >= len(sums):
		right = len(sums) - 1
	res = max(res, sums[right] - sums[left])
print(res)


(N, K) = [int(it) for it in input().split()]
S = [int(it) for it in input()]
li = []
v = 1
c = 0
for it in S:
	if v != it:
		li.append(c)
		c = 1
	else:
		c += 1
	v = it
li.append(c)
s = 0
lis = [0] * (len(li) + 1)
for i in range(len(li)):
	lis[i + 1] = lis[i] + li[i]
s = 0
for i in range(N):
	if i * 2 >= N:
		continue
	a = min(i * 2, len(li))
	b = min(i * 2 + 2 * K + 1, len(li))
	ds2 = lis[b] - lis[a]
	s = max(s, ds2)
print(s)


(n, k) = map(int, input().split())
s = list(input())
j = 0
ans = 0
cnt = 0
for i in range(n):
	if s[i] == '0':
		if i == 0 or s[i - 1] == '1':
			cnt += 1
	if cnt > k:
		while s[j] == '1':
			j += 1
		while s[j] == '0':
			j += 1
		cnt -= 1
	ans = max(ans, i - j + 1)
print(ans)


(N, K) = map(int, input().split())
S = input()
L = [0]
tmp = '1'
for i in range(N):
	if tmp != S[i]:
		L.append(1)
	else:
		L[-1] += 1
	tmp = S[i]
if tmp == '0':
	L.append(0)
M = len(L)
if M <= 2 * K + 1:
	print(N)
	exit()
X = [0 for i in range(M + 1)]
for i in range(M):
	X[i + 1] = L[i] + X[i]
ans = 0
for i in range(0, M - 2 * K, 2):
	ans = max(ans, X[i + 2 * K + 1] - X[i])
print(ans)


(n, k) = map(int, input().split())
s = input()
l = [0] * (k * 2 + 1)
c = '1'
p = 0
ret = 0
for i in range(len(s)):
	if s[i] != c:
		ret = max(ret, i - l[p])
		l.append(i)
		if c == '1':
			p += 2
		c = s[i]
ret = max(ret, n - l[p])
print(ret)


(n, k) = map(int, input().split())
s = input()
a = []
a.append(0)
for i in range(len(s) - 1):
	if s[i] != s[i + 1]:
		a.append(i + 1)
a.append(n)
if s[-1] == '0':
	m = 2 * k
else:
	m = 2 * k + 1
t = 4 * k + 1
_max = 0
i = len(a) - 1
if i - m < 0:
	print(n)
else:
	while i - m >= 0:
		tmp = a[i] - a[i - m]
		if tmp > _max:
			_max = tmp
		m = t - m
		i -= 1
	if a[i] > _max:
		_max = a[i]
	print(_max)


import sys
(N, K) = map(int, input().split())
S = list(map(int, input()))
T = []
t = 1
k = 0
for i in range(N):
	if t == S[i]:
		k += 1
	else:
		t ^= 1
		T.append(k)
		k = 1
T.append(k)
if S[-1] == 0:
	T.append(0)
X = len(T)
if K >= X // 2:
	print(N)
	sys.exit()
M = sum(T[:2 * K + 1])
F = M
for i in range(X // 2 - K):
	F = F - (T[2 * i] + T[2 * i + 1]) + (T[2 * (i + K) + 1] + T[2 * (i + K + 1)])
	M = max(M, F)
print(M)


(n, k) = list(map(int, input().split()))
s = input()
ans = 0
zeroes = 0
zeroIndices = []
ind = 0
lastZero = -1
for i in range(len(s)):
	if s[i] == '1' and i > 0 and (s[i - 1] == '0') or (i == len(s) - 1 and s[i] == '0' and (len(s) > 1)):
		zeroIndices.append(i - 1)
		if zeroes == k:
			lastZero = zeroIndices[ind]
			ind += 1
		else:
			zeroes += 1
	if i == len(s) - 1 or (s[i] == '1' and s[i + 1] == '0'):
		ans = max(ans, i - lastZero)
print(ans)


(N, K) = map(int, input().split())
S = input()
tp = [0, 0]
for i in range(1, N):
	if S[i] != S[i - 1]:
		tp.append(i)
tp.extend([N, N])
ranges = []
if S[0] == '1':
	l = 1
else:
	l = 0
r = l + 2 * K + 1
while r < len(tp):
	ranges.append(tp[r] - tp[l])
	l += 2
	r += 2
if len(ranges) == 0:
	ranges.append(N)
print(max(ranges))


(n, k) = map(int, input().split())
s = input().rstrip()
starts = [0]
ends = []
for i in range(1, n - 1):
	if s[i] == '1' and s[i - 1] == '0':
		starts.append(i)
	if s[i] == '1' and s[i + 1] == '0' and (len(starts) == len(ends) + 2):
		ends.append(i)
ends.append(n - 1)
ans = 0
m = len(ends)
for i in range(m - k + 1):
	ans = max(ans, ends[i + k - 1] - starts[i] + 1)
if k >= m:
	ans = n
print(ans)


(N, K) = map(int, input().split())
S = input().rstrip('\n')
S += '1' if S[N - 1] == '0' else '0'
sumz = [0] * (N + 2)
right = 1
cnt = 1
maxlen = 0
left = 0
if K == 0:
	for i in range(N):
		if S[i] == S[i + 1] and S[i] == 1:
			cnt += 1
		else:
			if maxlen < cnt:
				maxlen = cnt
			cnt = 1
else:
	cnt = 0
	while True:
		if left >= N:
			break
		if right <= left:
			right = left + 1
		while right < N and (cnt < K or (cnt == K and (S[right] == S[right - 1] or S[right] == '1'))):
			if S[right] != S[right - 1] and S[right - 1] == '0':
				cnt += 1
			right += 1
		if not (S[right - 1] == '0' and K == 0):
			if maxlen < right - left:
				maxlen = right - left
		while left < N and S[left] == S[left + 1]:
			left += 1
		if S[left] == '0':
			cnt -= 1
		left += 1
print(maxlen)


import sys

def input():
	return sys.stdin.readline()[:-1]
(N, K) = map(int, input().split())
S = input()
l = [0]
t = '1'
for i in S:
	if t == i:
		l[-1] += 1
	else:
		l.append(1)
		if t == '1':
			t = '0'
		else:
			t = '1'
if t == '0':
	l.append(0)
a = sum(l[:2 * K + 1])
A = a
for i in range(2 * K + 2, len(l), 2):
	a += l[i] + l[i - 1]
	a -= l[i - 2 * K - 2] + l[i - 2 * K - 1]
	A = max(A, a)
print(A)


(N, K) = list(map(int, input().split()))
S = str(input())
man_groups = []
same_cnt = 0
last_man = ''
for i in range(N):
	cur_man = S[i]
	if cur_man != last_man:
		if same_cnt > 0:
			if last_man == '0':
				same_cnt *= -1
			man_groups.append(same_cnt)
		same_cnt = 1
	else:
		same_cnt += 1
	last_man = cur_man
if same_cnt > 0:
	if last_man == '0':
		same_cnt *= -1
	man_groups.append(same_cnt)
sum_list = []
end_pos = 2 * K if man_groups[0] > 0 else 2 * K - 1
end_pos = min(end_pos, len(man_groups) - 1)
last_max = sum(map(abs, man_groups[0:end_pos + 1]))
sum_list.append(last_max)
for i in range(1, len(man_groups)):
	if end_pos >= len(man_groups) - 1:
		break
	last_max -= abs(man_groups[i - 1])
	if man_groups[i] > 0:
		next_end_pos = min(end_pos + 2, len(man_groups) - 1)
		man_groups_to_add = man_groups[end_pos + 1:next_end_pos + 1]
		last_max += sum(map(abs, man_groups_to_add))
		end_pos = next_end_pos
	sum_list.append(last_max)
print(max(sum_list))


(N, K) = map(int, input().split())
S = input()
S = S + 'end'
if S[0] == '0':
	stand = 1
else:
	stand = 0
r = 0
l = 0
ans = 0
while r < N:
	if stand <= K:
		if S[r] == '1' and S[r + 1] == '0':
			stand += 1
		r += 1
		ans = max(ans, r - l)
	elif l == r:
		l += 1
		r += 1
	else:
		if S[l] == '0' and S[l + 1] == '1':
			stand -= 1
		l += 1
print(ans)


(N, K) = map(int, input().split())
S = list(input())
A = {}
if S[0] == '1':
	A[1] = 0
	c = 1
else:
	A[0] = 0
	c = 0
for i in range(N - 1):
	if S[i] == '0' and S[i + 1] == '1':
		c += 1
		A[c] = i + 1
B = {}
c = 1
for i in range(N - 1):
	if S[i] == '1' and S[i + 1] == '0':
		B[c] = i
		c += 1
ans = 0
for (p, v) in A.items():
	t = B.get(p + K, N - 1)
	ans = max(t - v + 1, ans)
print(ans)


(n, k) = map(int, input().split())
s = list(input())
judge = [0]
max_ = 0
for i in range(n - 1):
	if s[i] != s[i + 1]:
		judge.append(i + 1)
judge.append(n)
if len(judge) // 2 <= k:
	print(len(s))
else:
	for i in range(len(judge) - 1):
		if s[judge[i]] == '0':
			ans = judge[min(i + 2 * k, len(judge) - 1)] - judge[i]
		else:
			ans = judge[min(i + 2 * k + 1, len(judge) - 1)] - judge[i]
		if ans > max_:
			max_ = ans
	print(max_)


(N, K) = map(int, input().split())
S = input()
Nums = []
now = 1
cnt = 0
for i in range(N):
	if S[i] == str(now):
		cnt += 1
	else:
		Nums.append(cnt)
		now = 1 - now
		cnt = 1
if cnt != 0:
	Nums.append(cnt)
if len(Nums) % 2 == 0:
	Nums.append(0)
Add = 2 * K + 1
sum = [0] * (len(Nums) + 1)
for i in range(len(Nums)):
	sum[i + 1] = sum[i] + Nums[i]
ans = 0
for i in range(0, len(Nums), 2):
	left = i
	right = min(i + Add, len(Nums))
	tmp = sum[right] - sum[left]
	ans = max(tmp, ans)
print(ans)


(n, k) = map(int, input().split())
s = input()
f = int(s[0])
d = [0]
if f == 0:
	d.append(0)
t = s[0]
for i in s:
	if i == t:
		d[-1] += 1
	else:
		d.append(1)
		t = i
if s[-1] == '0':
	d.append(0)
ans = chk = 0
for i in range(len(d)):
	chk += d[i]
	if i >= 2 * k + 1:
		chk -= d[i - (2 * k + 1)]
	if i % 2 == 0:
		ans = max(ans, chk)
print(ans)


(n, k) = map(int, input().split())
s = str(input())
v = [0]
for i in range(len(s) - 1):
	if s[i] != s[i + 1]:
		v.append(i + 1)
ans = 0
arr = v + [n] * (2 * k + 1)
for (i, j) in enumerate(v):
	if s[j] == '0':
		ans = max(ans, arr[i + 2 * k] - arr[i])
	else:
		ans = max(ans, arr[i + 2 * k + 1] - arr[i])
print(ans)


(n, k) = map(int, input().split())
s = input()
left = 0
(count, ans) = (0, 0)
for right in range(n):
	if s[right] == '0':
		if right == 0 or s[right - 1] == '1':
			count += 1
	if count > k:
		while s[left] == '1':
			left += 1
		while s[left] == '0':
			left += 1
		count -= 1
	ans = max(ans, right - left + 1)
print(ans)


import sys
import numpy as np

def input():
	return sys.stdin.readline().rstrip()

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def main():
	(n, k) = mi()
	s = input()
	a = [0]
	for i in range(1, n):
		if s[i] != s[i - 1]:
			a.append(i)
	a.append(n)
	ans = 0
	(i, e) = (0, 0)
	m = len(a)
	for i in range(m):
		e = i + 2 * k
		if s[a[i]] == '1':
			e += 1
		e = min(e, m - 1)
		ans = max(ans, a[e] - a[i])
		if e == m - 1:
			break
	print(ans)

def __starting_point():
	main()
__starting_point()


(N, K) = map(int, input().split())
S = input()
L = [0]
for i in range(N - 1):
	if S[i] != S[i + 1]:
		L.append(i + 1)
L.append(N)
if S[0] == '0':
	L.insert(0, 0)
if S[-1] == '0':
	L.append(N)
max_r = 0
step = K * 2 + 1
if len(L) - step < 1:
	step = len(L) - 1
for i in range(0, len(L) - step, 2):
	max_r = max(max_r, L[i + step] - L[i])
print(max_r)


(n, k) = map(int, input().strip().split())
s = input().strip()
l = r = 0
c = 0
while r < n and s[r] == '1':
	r += 1
while c < k:
	while r < n and s[r] == '0':
		r += 1
	while r < n and s[r] == '1':
		r += 1
	if r == n:
		print(n)
		exit()
	c += 1
ans = r - l
while r < n:
	while l < n and s[l] == '1':
		l += 1
	while l < n and s[l] == '0':
		l += 1
	while r < n and s[r] == '0':
		r += 1
	while r < n and s[r] == '1':
		r += 1
	ans = max(ans, r - l)
print(ans)


(n, k) = map(int, input().split())
s = input()
nums = []
if s[0] == '0':
	nums.append(0)
num = s[0]
numi = 0
for i in range(n):
	if s[i] == num:
		numi += 1
	else:
		nums.append(numi)
		numi = 1
		num = s[i]
else:
	nums.append(numi)
if s[-1] == '1':
	nums.append(0)
ans = 0
zero_num = len(nums) // 2
if zero_num <= k:
	print(sum(nums))
else:
	l = 2 * k
	sumi = sum(nums[:l + 1])
	ans = sumi
	i = 0
	while l + 2 < len(nums):
		sumi += nums[l + 1] + nums[l + 2]
		l += 2
		sumi -= nums[i] + nums[i + 1]
		i += 2
		ans = max(ans, sumi)
	ans = max(ans, sum(nums[-2 * k:]))
	print(ans)


(n, k) = list(map(int, input().split()))
s = input()

def rle(string):
	_rle_str = string[0]
	_rle_cnt = 1
	_ans_l = []
	for _i in range(1, len(string)):
		if _rle_str == string[_i]:
			_rle_cnt += 1
		else:
			_ans_l.append([_rle_str, _rle_cnt])
			_rle_str = string[_i]
			_rle_cnt = 1
	_ans_l.append([_rle_str, _rle_cnt])
	return _ans_l
rle_s = rle(s)
ans = -1
left = 0
wa = 0
if rle_s[0][0] == '0':
	cnt = 1
	wa = rle_s[0][1]
	right = 1
else:
	cnt = 0
	right = 0
if len(rle_s) == 1 and k >= 1:
	print(rle_s[0][1])
	return
while right < len(rle_s):
	if cnt == k:
		if rle_s[right][0] == '0':
			if rle_s[left][0] == '0':
				wa -= rle_s[left][1]
				cnt -= 1
			else:
				wa -= rle_s[left][1]
			left += 1
		else:
			wa += rle_s[right][1]
			right += 1
			ans = max(ans, wa)
	elif cnt < k:
		if rle_s[right][0] == '0':
			cnt += 1
			wa += rle_s[right][1]
		else:
			wa += rle_s[right][1]
		right += 1
		ans = max(ans, wa)
	else:
		if rle_s[left][0] == '0':
			wa -= rle_s[left][1]
			cnt -= 1
		else:
			wa -= rle_s[left][1]
		left += 1
print(ans)


import sys
(n, k) = [int(x) for x in input().split()]
s = input()
l = [0]
a = '1'
for i in range(n):
	if s[i] != a:
		l.append(i)
		a = s[i]
l.append(n)
if s[-1] == '0':
	l.append(n)
if len(l) < 2 * k + 2:
	print(n)
	sys.exit()
(a, ans) = (0, 0)
while a + 2 * k + 1 < len(l):
	b = l[a + 2 * k + 1] - l[a]
	if ans < b:
		ans = b
	a += 2
print(ans)


from itertools import *
(n, k) = map(int, input().split())
s = input()
d = [len(list(t)) for (_, t) in groupby(s)]
if s[0] == '0':
	d = [0] + d
a = [0] + list(accumulate(d))
m = l = 0
while True:
	try:
		m = max(m, a[l + 2 * k + 1] - a[l])
		l += 2
	except IndexError:
		m = max(m, a[-1] - a[l])
		break
print(m)


import itertools
(n, k) = list(map(int, input().split()))
list_S = list(input())
list_N = []
gr = itertools.groupby(list_S)
cnt = 0
for (key, group) in gr:
	list_N.append([key, len(list(group))])
	if key == '0':
		cnt += 1
if cnt <= k:
	print(n)
else:
	if list_N[0][0] == '0':
		list_N.insert(0, ['1', 0])
	if list_N[-1][0] == '0':
		list_N.append(['1', 0])
	s = 0
	for i in range(2 * k + 1):
		s += list_N[i][1]
	ans = s
	for i in range(2 * k + 2, len(list_N), 2):
		s += list_N[i][1] + list_N[i - 1][1] - list_N[i - 2 * k - 2][1] - list_N[i - 2 * k - 1][1]
		ans = max(ans, s)
	print(ans)


(n, k) = map(int, input().split())
s = input()
l = list()
s = s.replace('10', '1,0')
s = s.replace('01', '0,1')
l = [len(i) for i in s.split(',')]
r = 0
ans = 0
if s[0] == '1':
	r = min(k, len(l) - 1)
else:
	r = min(k - 1, len(l) - 1)
t = l[r]
for j in range(1, k + 1):
	if r - j >= 0:
		t += l[r - j]
	if r + j < len(l):
		t += l[r + j]
ans = t
for i in range(r + 2, len(l), 2):
	for j in range(1, 3):
		if i - j - k >= 0:
			t -= l[i - j - k]
		if i + j + k - 2 < len(l):
			t += l[i + j + k - 2]
	ans = max(ans, t)
print(ans)


(N, K) = map(int, input().split())
S = input() + '2'
L = []
cnt = 0
temp = int(S[0])
for x in S:
	if temp == int(x):
		cnt += 1
	else:
		L.append(cnt)
		cnt = 1
		temp = int(x)
if S[0] == '0':
	Lcs = [0, 0]
else:
	Lcs = [0]
for x in L:
	Lcs.append(Lcs[-1] + x)
ans = Lcs[1]
N = len(Lcs)
i = 2
if i + 2 * (K - 1) > N - 1:
	print(Lcs[-1])
else:
	while i + 2 * (K - 1) <= N - 1:
		if i + 2 * (K - 1) == N - 1:
			ans = max(ans, Lcs[i + 2 * (K - 1)] - Lcs[i - 2])
		else:
			ans = max(ans, Lcs[i + 2 * (K - 1) + 1] - Lcs[i - 2])
		i += 2
	print(ans)


(N, K) = map(int, input().split())
S = input()
Is = []
i = 0
while i < N:
	j = S.find('0', i)
	if j < 0:
		j = N
	k = S.find('1', j)
	if k < 0:
		k = N
	Is.append((i, j, k))
	i = k
Is.append((N, N, N))
if len(Is) <= K:
	r = N
	print(r)
	exit()
rs = []
for i in range(len(Is) - K):
	r = Is[i + K][1] - Is[i][0]
	rs.append(r)
r = max(rs)
print(r)


(n, k) = map(int, input().split())
s = list(map(int, input()))
x = [0]
if s[0] == 0:
	x.append(0)
for i in range(n - 1):
	if s[i] != s[i + 1]:
		x.append(i + 1)
x.append(n)
if s[n - 1] == 0:
	x.append(n)
r = len(x) // 2 - 1
if k >= r:
	print(n)
else:
	print(max((x[2 * (i + k) + 1] - x[2 * i] for i in range(r - k + 1))))


(n, k) = map(int, input().split())
s = '1' + input()
i = 0
for j in range(n):
	k -= '10' == s[j:j + 2]
	i += k < 0
	k += k < 0 and '01' == s[i:i + 2]
print(n - i)


(N, K) = map(int, input().split())
S = input()
i = 0
for j in range(N):
	if S[j] == '0' and (j == 0 or S[j - 1] == '1'):
		K -= 1
	if K < 0:
		if S[i] == '0' and S[i + 1] == '1':
			K += 1
		i += 1
print(N - i)


(N, K) = map(int, input().split())
S = input()
if N == 1:
	print(1)
	return
S2 = []
signs = []
if S[0] == '1':
	sign = 1
else:
	sign = 0
count = 1
for i in range(1, N):
	if S[i] != S[i - 1]:
		S2.append(count)
		signs.append(sign)
		sign = 1 - sign
		count = 0
	count += 1
S2.append(count)
signs.append(sign)
cumS = [0]
for i in range(len(S2)):
	cumS.append(cumS[-1] + S2[i])
k = K * 2 + 1
if len(S2) >= k:
	MAX = 0
	for i in range(len(S2) - k + 1):
		if signs[i] == 1:
			tmp = cumS[i + k] - cumS[i]
			if tmp > MAX:
				MAX = tmp
	if signs[0] == 0:
		MAX = max(MAX, cumS[k - 1] - cumS[0])
	if signs[-1] == 0:
		MAX = max(MAX, cumS[-1] - cumS[-k])
else:
	MAX = cumS[-1]
print(MAX)


(n, k) = map(int, input().split())
S = list(map(int, list(input())))
ridx = 1
cnt = 0 if S[0] == 1 else 1
ans = 0
for lidx in range(n):
	if lidx > 0 and S[lidx] == 1 and (S[lidx - 1] == 0):
		cnt -= 1
	while ridx < n:
		if S[ridx] == 0 and S[ridx - 1] == 1:
			if cnt < k:
				cnt += 1
			else:
				break
		ridx += 1
	ans = max(ans, ridx - lidx)
print(ans)


(n, k) = map(int, input().split())
s = input()
x = [0]
for i in range(n - 1):
	if s[i:i + 2] in ['01', '10']:
		x.append(i + 1)
y = []
for i in range(len(x)):
	idx = i + 2 * k
	if s[x[i]] == '0':
		if i > 0:
			continue
	else:
		idx += 1
	if idx < len(x):
		y.append(x[idx] - x[i])
	else:
		y.append(n - x[i])
		break
print(max(y))


(N, K) = map(int, input().split())
S = input()
S = '1' + S + '1'
rev = []
for i in range(N + 1):
	if S[i] != S[i + 1]:
		rev.append(i)
l = len(rev) // 2
a = [(rev[2 * i], rev[2 * i + 1]) for i in range(l)]
a = [(0, 0)] + a + [(N, N)]
K = min(K, l)
m = -1
for i in range(l - K + 1):
	x = a[i + K + 1][0] - a[i][1]
	m = max(m, x)
print(m)


(n, p) = list(map(int, input().split()))
s = list(input())
from itertools import groupby
gr = groupby(s)
cum = []
tmp = 0
for (k, v) in gr:
	if k == '0':
		cum.append(tmp + len(list(v)))
		tmp = 0
	elif k == '1':
		tmp += len(list(v))
cum = list(reversed(cum))
ans = 0
cnt = 0
tmp = 0
gr = groupby(s)
for (k, v) in gr:
	if k == '0':
		cnt += 1
		if cnt > p:
			tmp -= cum.pop()
	tmp += len(list(v))
	ans = max(ans, tmp)
print(ans)


import sys
stdin = sys.stdin
from itertools import groupby, accumulate

def ns():
	return stdin.readline().rstrip()

def ni():
	return int(ns())

def na():
	return list(map(int, stdin.readline().split()))

def main():
	(n, k) = na()
	s = ns()
	a = list()
	if s[0] == '0':
		a.append(0)
	gr = groupby(s)
	for (key, group) in gr:
		a.append(len(list(group)))
	if s[-1] == '0':
		a.append(0)
	acum = list(accumulate(a))
	m = len(acum)
	l = 2 * k + 1
	if m == 1:
		print(acum[0])
		return
	if l > m:
		print(acum[-1])
		return
	ans = acum[l - 1]
	for i in range(0, m - l + 1, 2):
		ans = max(ans, acum[i + l - 1] - acum[i - 1])
	print(ans)

def __starting_point():
	main()
__starting_point()


import sys
from itertools import groupby, accumulate
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007

def main():
	(N, K) = list(map(int, readline().split()))
	S = readline().strip()
	vec = [len(list(g)) for (_, g) in groupby(S)]
	keys = [k for (k, _) in groupby(S)]
	csum = [0]
	csum.extend(accumulate(vec))
	ans = 0
	for i in range(len(vec)):
		if keys[i] == '0':
			if i == 0:
				n = 2 * K
			else:
				continue
		else:
			n = 2 * K + 1
		if ans < csum[min(i + n, len(csum) - 1)] - csum[i]:
			ans = csum[min(i + n, len(csum) - 1)] - csum[i]
	print(ans)
	return

def __starting_point():
	main()
__starting_point()


(n, k) = map(int, input().split())
s = input()
num = []
temp = 0
count = 0
flag = True
while temp < len(s):
	if flag == True:
		if s[temp] == '1':
			count += 1
			temp += 1
		else:
			num.append(count)
			count = 1
			temp += 1
			flag = False
	elif s[temp] == '0':
		count += 1
		temp += 1
	else:
		num.append(count)
		count = 1
		temp += 1
		flag = True
num.append(count)
num2 = [sum(num[:min(2 * k + 1, len(num))])]
temp = min(2 * k + 1, len(num))
temp2 = 0
while temp < len(num):
	temp3 = num2[-1] - num[temp2] - num[temp2 + 1] + num[temp]
	if temp + 1 < len(num):
		temp3 += num[temp + 1]
	temp += 2
	temp2 += 2
	num2.append(temp3)
print(max(num2))


(n, k) = map(int, input().split())
s = input()
cnt = [0]
now = '1'
for i in range(n):
	if s[i] == now:
		cnt[-1] += 1
	else:
		now = s[i]
		cnt.append(1)
cnt = cnt + [0, 0]
m = len(cnt)
if m <= 2 * k + 1:
	print(n)
	exit()
l = 0
r = 2 * k + 1
tmp = sum(cnt[:r])
ans = tmp
while r + 2 <= m:
	tmp += cnt[r] + cnt[r + 1] - cnt[l] - cnt[l + 1]
	ans = max(ans, tmp)
	l += 2
	r += 2
print(ans)


(n, k) = map(int, input().split())
s = input()
l = x = ans = 0
for r in range(n):
	if s[r] == '0':
		if r == 0 or s[r - 1] == '1':
			x += 1
	if x > k:
		while s[l] == '1':
			l += 1
		while s[l] == '0':
			l += 1
		x -= 1
	ans = max(ans, r - l + 1)
print(ans)


def rle(string):
	_rle_str = string[0]
	_rle_cnt = 1
	_ans_l = []
	for _i in range(1, len(string)):
		if _rle_str == string[_i]:
			_rle_cnt += 1
		else:
			_ans_l.append([_rle_str, _rle_cnt])
			_rle_str = string[_i]
			_rle_cnt = 1
	_ans_l.append([_rle_str, _rle_cnt])
	return _ans_l
(n, k) = list(map(int, input().split()))
s = input()
rs = rle(s)
if rs[0][0] == '0':
	cnt = 1
	wa = rs[0][1]
	r = 1
	l = 0
else:
	cnt = 0
	wa = 0
	r = 0
	l = 0
ans = -1
if len(rs) == 1:
	print(rs[0][1])
	return
while r < len(rs):
	if cnt == k and rs[r][0] == '0':
		if rs[l][0] == '0':
			wa -= rs[l][1]
			cnt -= 1
		else:
			wa -= rs[l][1]
		l += 1
	elif cnt <= k:
		if rs[r][0] == '0':
			cnt += 1
			wa += rs[r][1]
		else:
			wa += rs[r][1]
		r += 1
		ans = max(ans, wa)
	else:
		if rs[l][0] == '0':
			wa -= rs[l][1]
			cnt -= 1
		else:
			wa -= rs[l][1]
		l += 1
print(ans)


(N, K) = map(int, input().split())
S = input()
L = [0]
ans = 0
res = '1'
i = 0
for s in S:
	if s != res:
		L.append(i)
		i += 1
	else:
		i += 1
	res = s
L.append(i)
L.append(i)
if len(L) <= 2 * K + 1:
	ans = N
for i in range(0, len(L) - K * 2 - 1, 2):
	ans = max(ans, L[i + K * 2 + 1] - L[i])
print(ans)


(n, k) = map(int, input().split())
s = input()
change = [0]
for (i, (e1, e2)) in enumerate(zip(s, s[1:])):
	e1 = int(e1)
	e2 = int(e2)
	if e1 ^ e2:
		change.append(i + 1)
change.append(n)
end = len(change) - 1
ans = 0
for (i, l) in enumerate(change[:-1]):
	if s[l] == '1':
		ri = min(i + 2 * k + 1, end)
	else:
		ri = min(i + 2 * k, end)
	r = change[ri]
	ans = max(ans, r - l)
print(ans)


(n, k) = map(int, input().split())
s = input() + 'd'
d = []
r = s[0]
c = 0
for i in range(n + 1):
	if r == s[i]:
		c += 1
	else:
		d.append(c)
		r = s[i]
		c = 1
if s[0] == '0':
	d = [0] + d
if s[-2] == '0':
	d += [0]
if len(d) <= 2 * k + 1:
	print(n)
else:
	l = sum(d[:2 * k + 1])
	p = sum(d[:2 * k + 1])
	for i in range((len(d) - 2 * k - 1) // 2):
		p = p - d[2 * i] - d[2 * i + 1] + d[2 * i + 2 * k + 1] + d[2 * i + 2 * k + 2]
		l = max(l, p)
	print(l)


(n, k) = list(map(int, input().split()))
s = input()
sento = 0
ketu = 0
tmp = '1'
zeroichi = []
cnt = 0
for i in range(n):
	if tmp == s[i]:
		cnt += 1
	else:
		zeroichi.append(cnt)
		cnt = 1
		tmp = s[i]
zeroichi.append(cnt)
if len(zeroichi) % 2 == 0:
	zeroichi.append(0)
if len(zeroichi) == 1:
	zeroichi.append(0)
	zeroichi.append(0)
i = 0
ans = 0
ans_list = []
j = 0
right = min(1 + k * 2, len(zeroichi))
left = 0
while i != right:
	ans += zeroichi[i]
	i += 1
ans_list.append(ans)
while right != len(zeroichi):
	ans -= zeroichi[left]
	ans -= zeroichi[left + 1]
	ans += zeroichi[right]
	ans += zeroichi[right + 1]
	ans_list.append(ans)
	left += 2
	right += 2
print(max(ans_list))


(n, k) = map(int, input().split())
s = input()
a = [0]
i = 0
p = '1'
for t in s:
	if t == p:
		a[i] += 1
	else:
		p = t
		i += 1
		a += [1]
a += [0]
if len(a) <= 2 * k + 1:
	print(sum(a))
	quit()
x = sum(a[:2 * k + 1])
m = x
for i in range(2 * k + 1, len(a)):
	x = x + a[i] - a[i - (2 * k + 1)]
	if i % 2 == 0:
		m = max(m, x)
print(m)


(N, K) = map(int, input().split())
S = [int(i) for i in input()]
(ans, r, l, k) = (0, 0, 0, K)
while r < N:
	while k > 0:
		while l < N and S[l] == 1:
			l += 1
		while l < N and S[l] == 0:
			l += 1
		k -= 1
	while l < N and S[l] == 1:
		l += 1
	ans = max(ans, l - r)
	while r < N and S[r] == 1:
		r += 1
	while r < N and S[r] == 0:
		r += 1
	k = 1
print(ans)