Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
S = input()
last_s = "0"
count = 0
A = []
for i, s in enumerate(S):
	if i == 0:
		if s == "1":
			count += 1
		else:
			count -= 1
	else:
		if s != last_s:
			A.append(count)
			count = 0
		if s == "1":
			count += 1
		else:
			count -= 1
	last_s = s

if count != 0:
	A.append(count)

for i in range(10):
	A.append(0)


val = 0
if A[0] < 0:
	for i in range(2*K): 
		val += abs(A[i])
	currentMax = val
	old = abs(A[0])
	new = abs(A[1+2*K+1]) + abs(A[1+2*K+3])
	val += new - old
	if val > currentMax:
		currentMax = val
	for i in range(3, len(A)-2*K-2, 2):
		old_sum_of_two = abs(A[i]) + abs(A[i+1])
		sum_of_two = sum(A[i+2*K+1:i+2*K+3])
		val += sum_of_two - old_sum_of_two
		if val > currentMax:
			currentMax = val
	print(currentMax)
else:
	for i in range(2*K+1): 
		val += abs(A[i])
	currentMax = val
	for i in range(0, len(A)-2*K-2, 2):
		old_sum_of_two = abs(A[i]) + abs(A[i+2])
		sum_of_two = abs(A[i+2*K+1]) + abs(A[i+2*K+2])
		val += sum_of_two - old_sum_of_two
		if val > currentMax:
			currentMax = val
	print(currentMax)



Fixed submission:
N, K = map(int, input().split())
S = input()
last_s = "0"
count = 0
A = []
for i, s in enumerate(S):
	if i == 0:
		count += 1
	else:
		if s != last_s:
			A.append(count)
			count = 0
		count += 1
	last_s = s

if count != 0:
	A.append(count)

A.append(0)
A.append(0)

val = 0

if S[0] == "0":
	val = sum(A[:2*K])
	currentMax = val
	old = A[0]
	new = sum(A[2*K:2*K+2])
	val += new - old
	if val > currentMax:
		currentMax = val
	
	for i in range(1, len(A)-2*K, 2):
		old_sum_of_two = sum(A[i:i+2])
		sum_of_two = sum(A[i+2*K+1:i+2*K+3])
		val += sum_of_two - old_sum_of_two
		if val > currentMax:
			currentMax = val
	print(currentMax)
else:
	val = sum(A[:2*K+1])
	currentMax = val
	for i in range(0, len(A)-2*K, 2):
		old_sum_of_two = sum(A[i:i+2])
		sum_of_two = sum(A[i+2*K+1:i+2*K+3])
		val += sum_of_two - old_sum_of_two
		if val > currentMax:
			currentMax = val
	print(currentMax)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
S = input()
last_s = "0"
count = 0
A = []
for i, s in enumerate(S):
	if i == 0:
		count += 1
	else:
		if s != last_s:
			A.append(count)
			count = 0
		count += 1
	last_s = s

if count != 0:
	A.append(count)

B = []

for i in range(len(S)-(2*K+1)-1):
	B.append(sum(A[2*i:2*i+2*K+1]))

print(max(B))


Fixed submission:
N, K = map(int, input().split())
S = input()
last_s = "0"
count = 0
A = []
for i, s in enumerate(S):
	if i == 0:
		count += 1
	else:
		if s != last_s:
			A.append(count)
			count = 0
		count += 1
	last_s = s

if count != 0:
	A.append(count)

A.append(0)
A.append(0)

val = 0

if S[0] == "0":
	val = sum(A[:2*K])
	currentMax = val
	old = A[0]
	new = sum(A[2*K:2*K+2])
	val += new - old
	if val > currentMax:
		currentMax = val
	
	for i in range(1, len(A)-2*K, 2):
		old_sum_of_two = sum(A[i:i+2])
		sum_of_two = sum(A[i+2*K+1:i+2*K+3])
		val += sum_of_two - old_sum_of_two
		if val > currentMax:
			currentMax = val
	print(currentMax)
else:
	val = sum(A[:2*K+1])
	currentMax = val
	for i in range(0, len(A)-2*K, 2):
		old_sum_of_two = sum(A[i:i+2])
		sum_of_two = sum(A[i+2*K+1:i+2*K+3])
		val += sum_of_two - old_sum_of_two
		if val > currentMax:
			currentMax = val
	print(currentMax)