In an attempt to escape the Mischievous Mess Makers' antics, Farmer John has abandoned his farm and is traveling to the other side of Bovinia. During the journey, he and his k cows have decided to stay at the luxurious Grand Moo-dapest Hotel. The hotel consists of n rooms located in a row, some of which are occupied.

Farmer John wants to book a set of k + 1 currently unoccupied rooms for him and his cows. He wants his cows to stay as safe as possible, so he wishes to minimize the maximum distance from his room to the room of his cow. The distance between rooms i and j is defined as |j - i|. Help Farmer John protect his cows by calculating this minimum possible distance.


-----Input-----

The first line of the input contains two integers n and k (1 ≤ k < n ≤ 100 000) — the number of rooms in the hotel and the number of cows travelling with Farmer John.

The second line contains a string of length n describing the rooms. The i-th character of the string will be '0' if the i-th room is free, and '1' if the i-th room is occupied. It is guaranteed that at least k + 1 characters of this string are '0', so there exists at least one possible choice of k + 1 rooms for Farmer John and his cows to stay in.


-----Output-----

Print the minimum possible distance between Farmer John's room and his farthest cow.


-----Examples-----
Input
7 2
0100100

Output
2

Input
5 1
01010

Output
2

Input
3 2
000

Output
1



-----Note-----

In the first sample, Farmer John can book room 3 for himself, and rooms 1 and 4 for his cows. The distance to the farthest cow is 2. Note that it is impossible to make this distance 1, as there is no block of three consecutive unoccupied rooms.

In the second sample, Farmer John can book room 1 for himself and room 3 for his single cow. The distance between him and his cow is 2.

In the third sample, Farmer John books all three available rooms, taking the middle room for himself so that both cows are next to him. His distance from the farthest cow is 1.

Difficulty: MEDIUM_HARD
Tags: Sorting

Amortized analysis
Skill types: Sorting

Amortized analysis

Starter code:

Solutions:
(n, k) = [int(_) for _ in input().split()]
a = input()

def next_free(x):
	x += 1
	while x < n and a[x] == '1':
		x += 1
	return x
l = next_free(-1)
r = -1
k += 1
for _ in range(k):
	r = next_free(r)
i = l
dis = max(i - l, r - i)
next_i = next_free(i)
while True:
	cur_dis = max(i - l, r - i)
	next_dis = max(next_i - l, r - next_i)
	if cur_dis <= next_dis:
		break
	i = next_i
	dis = min(dis, next_dis)
	next_i = next_free(i)
while True:
	r = next_free(r)
	if r >= n:
		break
	l = next_free(l)
	if i < l:
		i = l
	prev_dis = max(i - l, r - i)
	dis = min(dis, prev_dis)
	m = next_free(i)
	while m <= r:
		cur_dis = max(m - l, r - m)
		if cur_dis >= prev_dis:
			break
		prev_dis = cur_dis
		i = m
		dis = min(dis, cur_dis)
		m = next_free(m)
print(dis)


import sys

def can_book(mid, n, k, accum_arr):
	for i in range(1, n + 1):
		if accum_arr[i] == accum_arr[i - 1]:
			continue
		max_idx = min(i + mid, n)
		min_idx = max(i - mid - 1, 0)
		if accum_arr[max_idx] - accum_arr[min_idx] >= k + 1:
			return True
	return False

def solve(n, k, arr):
	accum_arr = [0]
	for i in range(1, n + 1):
		accum_arr.append(accum_arr[i - 1] + (1 - arr[i - 1]))
	l = 0
	h = len(arr)
	while l + 1 < h:
		mid = (l + h) // 2
		if can_book(mid, n, k, accum_arr):
			h = mid
		else:
			l = mid
	return h
(n, k) = input().split()
n = int(n)
k = int(k)
arr = list(map(int, sys.stdin.readline().rstrip()))
print(solve(n, k, arr))


res = 1000000000.0

def next(i):
	i += 1
	while i < N and S[i] == '1':
		i += 1
	return i
(N, K) = map(int, input().split())
S = input()
l = next(-1)
m = l
r = l
for j in range(K):
	r = next(r)
while r < N:
	while max(m - l, r - m) > max(next(m) - l, r - next(m)):
		m = next(m)
	res = min(res, max(m - l, r - m))
	l = next(l)
	r = next(r)
print(res)


(n, k) = map(int, input().split())
t = [i for (i, v) in enumerate(input()) if v == '0']
(s, m) = (n, 0)
f = lambda m: max(r - t[m], t[m] - l)
for (l, r) in zip(t, t[k:]):
	while f(m) > f(m + 1):
		m += 1
	s = min(s, f(m))
print(s)


res = 1000000000.0

def next(i):
	i += 1
	while i < n and s[i] == '1':
		i += 1
	return i
(n, k) = list(map(int, input().split()))
s = input()
l = next(-1)
m = l
r = l
for i in range(k):
	r = next(r)
while r < n:
	while max(m - l, r - m) > max(next(m) - l, r - next(m)):
		m = next(m)
	res = min(res, max(m - l, r - m))
	l = next(l)
	r = next(r)
print(res)


(n, k) = list(map(int, input().split()))
s = input()
prefixes = [0]
for i in range(n):
	prefixes.append(prefixes[i] + (int(s[i]) + 1) % 2)
a = n
for i in range(n):
	if s[i] == '0':
		left = 0
		right = n
		while right - left > 1:
			middle = (right + left) // 2
			if prefixes[min(n, 1 + i + middle)] - prefixes[max(0, i - middle)] > k:
				right = middle
			else:
				left = middle
		a = min(a, right)
print(a)


(n, k) = map(int, input().split())
rooms = input()
count = [0] * (n + 1)
for i in range(n):
	count[i] = count[i - 1]
	if rooms[i] == '0':
		count[i] += 1
ans = float('inf')
for i in range(n):
	l = 0
	r = n
	while l + 1 < r:
		m = (r + l) // 2
		if rooms[i] == '0' and count[min(i + m, n - 1)] - count[max(-1, i - m - 1)] > k:
			r = m
		else:
			l = m
	ans = min(r, ans)
print(ans)


def main():
	(n, k) = list(map(int, input().split()))
	cowLocations = input()
	whereIsCow = []
	for i in range(len(cowLocations)):
		if cowLocations[i] == '0':
			whereIsCow.append(i)
	i = 0
	j = k
	fJohn = 0
	wic = len(whereIsCow)
	smallest = 1000000
	while i < wic and j < wic and (fJohn < wic):
		maxDist = max(whereIsCow[j] - whereIsCow[fJohn], whereIsCow[fJohn] - whereIsCow[i])
		while fJohn <= j and max(whereIsCow[j] - whereIsCow[fJohn + 1], whereIsCow[fJohn + 1] - whereIsCow[i]) < maxDist:
			fJohn += 1
			maxDist = max(whereIsCow[j] - whereIsCow[fJohn], whereIsCow[fJohn] - whereIsCow[i])
		if maxDist < smallest:
			smallest = maxDist
		j += 1
		i += 1
	print(smallest)

def __starting_point():
	main()
__starting_point()


from collections import deque
(rooms_number, cows_number) = map(int, input().split())
rooms = input()
free_rooms = [i for i in range(rooms_number) if rooms[i] == '0']

def binary_search(left, right, item):
	global free_rooms
	while right - left > 1:
		center = left + (right - left) // 2
		if free_rooms[center] > item:
			right = center
		else:
			left = center
	return left
min_distation_to_farthest_cow = 10 ** 20
best_min_distation_to_farthest_cow = cows_number // 2 + cows_number % 2
for i in range(len(free_rooms) - cows_number):
	left = free_rooms[i]
	right = free_rooms[i + cows_number]
	center = left + (right - left) // 2
	j = binary_search(i, i + cows_number, center)
	if free_rooms[j] == center:
		distation_to_farthest_cow = right - center
	else:
		distation_to_farthest_cow = min(right - free_rooms[j], free_rooms[j + 1] - left)
	if min_distation_to_farthest_cow > distation_to_farthest_cow:
		min_distation_to_farthest_cow = distation_to_farthest_cow
	if distation_to_farthest_cow == best_min_distation_to_farthest_cow:
		break
print(min_distation_to_farthest_cow)


(n, k) = [int(_) for _ in input().split()]
a = input()
k += 1
f = [0] * (n + 1)
f[1] = int(a[0] == '0')
for i in range(2, n + 1):
	f[i] = f[i - 1] + int(a[i - 1] == '0')

def check(dis):
	for i in range(n):
		if a[i] == '0':
			left = max(i - dis, 0)
			right = min(i + dis, n - 1)
			total = f[right + 1] - f[left]
			if total >= k:
				return True
	return False
l = 1
r = n - 1
while l < r:
	mid = (l + r) // 2
	if check(mid):
		r = mid
	else:
		l = mid + 1
print(l)


import sys
r = sys.stdin.readline
(n, k) = map(int, r().split())
rooms = list(r().strip())

def nextRoom(i):
	i += 1
	while i < n and rooms[i] == '1':
		i += 1
	return i
l = nextRoom(-1)
(r, m) = (l, l)
ans = sys.maxsize
for i in range(k):
	r = nextRoom(r)
while r < n:
	while max(m - l, r - m) > max(nextRoom(m) - l, r - nextRoom(m)):
		m = nextRoom(m)
	ans = min(ans, max(m - l, r - m))
	(l, r) = (nextRoom(l), nextRoom(r))
print(ans)


[n, k] = [int(x) for x in input().split()]
room_free = [bool(1 - int(x)) for x in input()]
closest_before = []
closest_after = []
before = -1
for i in range(n):
	if room_free[i]:
		before = i
	closest_before.append(before)
after = 11 ** 8
for i in range(n - 1, -1, -1):
	if room_free[i]:
		after = i
	closest_after.append(after)
closest_after.reverse()
l = -1
r = -1
taken = 0
ans = 10 ** 8
while True:
	if taken != k + 1:
		r += 1
		if r >= n:
			break
		if room_free[r]:
			taken += 1
	else:
		l += 1
		if room_free[l]:
			mid = int((l + r) / 2)
			ans = min(ans, closest_after[mid + 1] - l, r - closest_before[mid])
			taken -= 1
print(ans)


(n, k) = map(int, input().split())
t = [i for (i, v) in enumerate(input()) if v == '0']
(s, i) = (n, 0)
(a, b) = t[:2]
for (l, r) in zip(t, t[k:]):
	while max(r - a, a - l) > max(r - b, b - l):
		i += 1
		(a, b) = t[i:i + 2]
	s = min(s, max(r - a, a - l))
print(s)


ans = 1000000000
(n, k) = [int(i) for i in input().split()]
s = input()
l = len(s)
d = [k // 2, (k + 1) // 2]
nearl = [0] * n
nearr = [0] * n
last = 1000000000
for i in range(n):
	if s[i] == '0':
		last = i
	nearl[i] = last
for i in range(n - 1, -1, -1):
	if s[i] == '0':
		last = i
	nearr[i] = last
for i in d:
	itl = 0
	nf = 0
	itr = 0
	while s[itl] == '1':
		itl += 1
	cnt = 0
	nf = itl
	while cnt < i:
		cnt += 1
		nf += 1
		while s[nf] == '1':
			nf += 1
	cnt = 0
	itr = nf
	while cnt < k - i:
		cnt += 1
		itr += 1
		while s[itr] == '1':
			itr += 1
	while True:
		pos = (itr + itl) // 2
		pos1 = nearl[pos]
		ans = min(ans, max(pos1 - itl, itr - pos1))
		pos1 = nearr[pos]
		ans = min(ans, max(pos1 - itl, itr - pos1))
		itr += 1
		while itr < l and s[itr] == '1':
			itr += 1
		if itr == l:
			break
		itl += 1
		while s[itl] == '1':
			itl += 1
print(ans)


def main():
	from bisect import bisect
	(n, k) = map(int, input().split())
	l = [i for (i, c) in enumerate(input()) if c == '0']
	l.append(n * 3)
	for (i, j) in enumerate(range(k, len(l) - 1)):
		(lo, hi) = (l[i], l[j])
		m = bisect(l, (lo + hi) // 2)
		mid = l[m]
		(a, b) = (mid - lo, hi - mid)
		if a < b:
			a = b
		mid = l[m - 1]
		(b, c) = (mid - lo, hi - mid)
		if b < c:
			b = c
		if a > b:
			a = b
		if n > a:
			n = a
	print(n)
main()


import sys
input = sys.stdin.readline

def judge(i, x):
	return acc[min(n, i + x + 1)] - acc[max(0, i - x)] >= k + 1

def binary_search(i):
	(l, r) = (0, n)
	while l <= r:
		mid = (l + r) // 2
		if judge(i, mid):
			r = mid - 1
		else:
			l = mid + 1
	return l
(n, k) = map(int, input().split())
S = input()[:-1]
acc = [0]
for Si in S:
	acc.append(acc[-1] + (1 if Si == '0' else 0))
ans = n
for i in range(n):
	if S[i] == '0':
		ans = min(ans, binary_search(i))
print(ans)


(n, k) = list(map(int, input().split()))
a = [int(i) for i in input()]
(i, j, l) = (0, -1, 0)
z = n
b = []
c = -1
for i in range(n):
	if a[i] == 0:
		c = i
	b.append(c)
c = -1
for i in range(n - 1, -1, -1):
	if a[i] == 0:
		c = i
	if c != -1 and (b[i] == -1 or c - i < i - b[i]):
		b[i] = c
while i < n and j < n:
	if l <= k:
		j += 1
		if j < n:
			l += 1 - a[j]
		else:
			break
	else:
		z = min(z, max(j - b[(i + j) // 2], b[(i + j) // 2] - i), max(j - b[(i + j) // 2 + 1], b[(i + j) // 2 + 1] - i))
		l -= 1 - a[i]
		i += 1
print(z)