Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
people = list(input())
lst = []
count = 0
flag = people[0]
if flag == '1':
	lst.append(0)
for i in range(len(people)):
	if i == len(people) - 1:
		lst.append(count + 1)
	elif people[i] == flag and people[i+1] != flag:
		lst.append(count + 1)
		count = 0
		flag = people[i + 1]
	else:
		count += 1

maximum = 0
l = len(lst)
for i in range(l):
	if i % 2 == 0:
		end = i+2*K
		if i != 0:
			maximum = max(maximum, sum(lst[i-1:end]))
		else:
			maximum = max(maximum, sum(lst[i:end]))
		if end > l:
			break
	else:
		end = 2*K+1
		maximum = max(maximum, sum(lst[i:end]))
		if end > l:
			break
print(maximum)


Fixed submission:
N, K = map(int, input().split())
people = list(input())
lst = []
count = 0
flag = people[0]
if flag == '1':
	lst.append(0)
for i in range(len(people)):
	if i == len(people) - 1:
		lst.append(count + 1)
	elif people[i] == flag and people[i+1] != flag:
		lst.append(count + 1)
		count = 0
		flag = people[i + 1]
	else:
		count += 1

maximum = 0
l = len(lst)
temp = sum(lst[0:2*K])
maximum = max(maximum, temp)
for i in range(2, l, 2):
	end = i+2*K
	temp = temp - lst[i-2] + sum(lst[end-2:end])
	if i != 2:
		temp -= lst[i-3]
	maximum = max(maximum, temp)

print(maximum)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
people = list(input())
lst = []
count = 0
flag = people[0]
for i in range(len(people)):
	if i == len(people) - 1:
		lst.append(count + 1) if flag == '1' else lst.append(count * -1 - 1)
	elif people[i] == flag and people[i+1] != flag:
		lst.append(count + 1) if flag == '1' else lst.append(count * -1 - 1)
		count = 0
		flag = people[i + 1]
	else:
		count += 1

maximum = 0
l = len(lst)
for i in range(l):
	if lst[i] < 0:
		end = i+2*K
		if i != 0:
			temp = list(map(abs, lst[i-1:end]))
		else:
			temp = list(map(abs, lst[i:end]))
		maximum = max(maximum, sum(temp))
		if end > l:
			break
	else:
		end = 2*K+1
		temp = list(map(abs, lst[i:end]))
		maximum = max(maximum, sum(temp))
		if end > l:
			break
print(maximum)


Fixed submission:
N, K = map(int, input().split())
people = list(input())
lst = []
count = 0
flag = people[0]
if flag == '1':
	lst.append(0)
for i in range(len(people)):
	if i == len(people) - 1:
		lst.append(count + 1)
	elif people[i] == flag and people[i+1] != flag:
		lst.append(count + 1)
		count = 0
		flag = people[i + 1]
	else:
		count += 1

maximum = 0
l = len(lst)
temp = sum(lst[0:2*K])
maximum = max(maximum, temp)
for i in range(2, l, 2):
	end = i+2*K
	temp = temp - lst[i-2] + sum(lst[end-2:end])
	if i != 2:
		temp -= lst[i-3]
	maximum = max(maximum, temp)

print(maximum)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
people = list(input())
lst = []
count = 0
flag = people[0]
for i in range(len(people)):
	if i == len(people) - 1:
		lst.append(count + 1) if flag == '1' else lst.append(count * -1 - 1)
	elif people[i] == flag and people[i+1] != flag:
		lst.append(count + 1) if flag == '1' else lst.append(count * -1 - 1)
		count = 0
		flag = people[i + 1]
	else:
		count += 1

maximum = 0
for i in range(len(lst)):
	if lst[i] < 0:
		if i != 0:
			temp = list(map(abs, lst[i-1:i+2*K]))
		else:
			temp = list(map(abs, lst[i:i+2*K]))
		maximum = max(maximum, sum(temp))
	else:
		temp = list(map(abs, lst[i:2*K+1]))
		maximum = max(maximum, sum(temp))
print(maximum)


Fixed submission:
N, K = map(int, input().split())
people = list(input())
lst = []
count = 0
flag = people[0]
if flag == '1':
	lst.append(0)
for i in range(len(people)):
	if i == len(people) - 1:
		lst.append(count + 1)
	elif people[i] == flag and people[i+1] != flag:
		lst.append(count + 1)
		count = 0
		flag = people[i + 1]
	else:
		count += 1

maximum = 0
l = len(lst)
temp = sum(lst[0:2*K])
maximum = max(maximum, temp)
for i in range(2, l, 2):
	end = i+2*K
	temp = temp - lst[i-2] + sum(lst[end-2:end])
	if i != 2:
		temp -= lst[i-3]
	maximum = max(maximum, temp)

print(maximum)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
people = list(input())
lst = []
count = 0
flag = people[0]
for i in range(len(people)):
	if i == len(people) - 1:
		lst.append(count + 1) if flag == '1' else lst.append(count * -1 - 1)
	elif people[i] == flag and people[i+1] != flag:
		lst.append(count + 1) if flag == '1' else lst.append(count * -1 - 1)
		count = 0
		flag = people[i + 1]
	else:
		count += 1

maximum = 0
for i in range(len(lst)):
	if lst[i] < 0:
		if i != 0:
			temp = list(map(abs, lst[i-1:i+2*K]))
		else:
			temp = list(map(abs, lst[i:i+2*K]))
		maximum = max(maximum, sum(temp))
	else:
		temp = list(map(abs, lst[i:2*K+1]))
		maximum = max(maximum, sum(temp))
print(maximum)


Fixed submission:
N, K = map(int, input().split())
people = list(input())
lst = []
count = 0
flag = people[0]
if flag == '1':
	lst.append(0)
for i in range(len(people)):
	if i == len(people) - 1:
		lst.append(count + 1)
	elif people[i] == flag and people[i+1] != flag:
		lst.append(count + 1)
		count = 0
		flag = people[i + 1]
	else:
		count += 1

maximum = 0
l = len(lst)
temp = sum(lst[0:2*K])
maximum = max(maximum, temp)
for i in range(2, l, 2):
	end = i+2*K
	temp = temp - lst[i-2] + sum(lst[end-2:end])
	if i != 2:
		temp -= lst[i-3]
	maximum = max(maximum, temp)

print(maximum)