Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
matrix = [[0] * (N+1) for i in range(N+1)]
min_distance = [0] * (N+1)
for i in range(M):
    L, R, C = map(int, input().split())
    for l in range(L,R):
        for r in range(l+1, R+1):
            if matrix[l][r] != 0:
                now = matrix[l][r]
                matrix[l][r] = min(now, C)
            else:
                matrix[l][r] = C
# print(matrix)

for i in range(1, N+1):
    for j in range(1, i):
        if min_distance[i] != 0 and matrix[j][i] != 0 and min_distance[j] != 0:
            min_distance[i] = min(min_distance[j] + matrix[j][i], min_distance[i])
        elif min_distance[i] == 0 and matrix[j][i] != 0 and min_distance[j] > 0:
            min_distance[i] = min_distance[j] + matrix[j][i]
        elif min_distance[i] == 0 and matrix[j][i] != 0 and j == 1:
            min_distance[i] = matrix[j][i]
        # print(i, j, min_distance[j], matrix[j][i], min_distance[i])

if min_distance[-1] == 0:
    print(-1)
else:
    print(min_distance[-1])

Fixed submission:
import heapq
N, M = map(int, input().split())
edge_list = [[] for i in range(N+1)]
for i in range(2, N + 1):
    edge_list[i].append((0, i-1))
for i in range(M):
    L, R, C = map(int, input().split())
    edge_list[L].append((C, R))
def solve(s, t):
    fixed = {}
    q = []
    heapq.heappush(q, (0, s))
    while q:
        w, x = heapq.heappop(q)
        if x == t:
            return w
        if x in fixed:
            continue
        fixed[x] = w
        for c, y in edge_list[x]:
            if y not in fixed:
                heapq.heappush(q, (w + c, y))
    return None

answer = solve(1, N)
if answer is None:
    print(-1)
else:
    print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()

def count(s):
    count_bigger = s.count('<')
    count_smaller = s.count('>')
    max_count = max(count_bigger, count_smaller)
    return (count_bigger*(count_bigger-1))/2 + (count_smaller*(count_smaller-1))/2 + max_count

ss = ""
answer = 0

for i in range(len(S)):
    if i == len(S)-1:
        ss += S[i]
        answer += count(ss)
    elif S[i] == ">" and S[i+1] == "<":
        ss += S[i]
        answer += count(ss)
        ss = ""
    else:
        ss += S[i]
print(int(answer))

Fixed submission:
S = input()

def count(up, down):
    max_count = max(up, down)
    return (up * (up - 1)) / 2 + (
                down * (down - 1)) / 2 + max_count

up = 0
down = 0
answer = 0

for i in range(len(S)):
    if i == len(S) - 1:
        if S[i] == ">":
            down += 1
        elif S[i] == "<":
            up += 1
        answer += count(up, down)
        up = 0
        down = 0
    elif S[i] == ">" and S[i + 1] == "<":
        if S[i] == ">":
            down += 1
        elif S[i] == "<":
            up += 1
        answer += count(up, down)
        up = 0
        down = 0
    else:
        if S[i] == ">":
            down += 1
        elif S[i] == "<":
            up += 1
print(int(answer))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()

def count(s):
    count_bigger = s.count('<')
    count_smaller = s.count('>')
    max_count = max(count_bigger, count_smaller)
    return (count_bigger*(count_bigger-1))/2 + (count_smaller*(count_smaller-1))/2 + max_count

s_list = []
ss = ""
for i in range(len(S)):
    if i == len(S)-1:
        ss += S[i]
        s_list.append(ss)
    elif S[i] == ">" and S[i+1] == "<":
        ss += S[i]
        s_list.append(ss)
        ss = ""
    else:
        ss += S[i]
answer = 0
for s in s_list:
    answer += count(s)
print(int(answer))

Fixed submission:
S = input()

def count(up, down):
    max_count = max(up, down)
    return (up * (up - 1)) / 2 + (
                down * (down - 1)) / 2 + max_count

up = 0
down = 0
answer = 0

for i in range(len(S)):
    if i == len(S) - 1:
        if S[i] == ">":
            down += 1
        elif S[i] == "<":
            up += 1
        answer += count(up, down)
        up = 0
        down = 0
    elif S[i] == ">" and S[i + 1] == "<":
        if S[i] == ">":
            down += 1
        elif S[i] == "<":
            up += 1
        answer += count(up, down)
        up = 0
        down = 0
    else:
        if S[i] == ">":
            down += 1
        elif S[i] == "<":
            up += 1
print(int(answer))
Buggy python submission (verdict: Time Limit Exceeded):
N = input()
S = input()
new_S = ""
for i in range(int(N)):
    if i == 0:
        new_S += S[i]
    else:
        if S[i] != S[i-1]:
            new_S += S[i]
print(len(new_S))

Fixed submission:
N = input()
S = input()
answer = 0
for i in range(int(N)):
    if i == 0:
        answer += 1
    else:
        if S[i] != S[i-1]:
            answer += 1
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N, K, Q = map(int, input().split())
A_list = []
i = 0
while i < Q:
  A_list.append(int(input()))
  i += 1

N_list = np.array([K] * N)

for idx, A in enumerate(A_list):
  minus_list = np.array([-1] * N)
  minus_list[A-1] += 1
  N_list = N_list + minus_list

for N in N_list:
  if N <= 0:
    print("No")
  else:
    print("Yes")
    

Fixed submission:
import numpy as np

N, K, Q = map(int, input().split())
A_list = np.array([0] * N)
i = 0
while i < Q:
  A_list[int(input()) - 1] += 1
  i += 1

N_list = np.array([K] * N)
N_list = N_list + A_list - Q

for N in N_list:
  if N <= 0:
    print("No")
  else:
    print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)

for i in range(M):
  max_index = A.index(max(A))
  A[max_index] = A[max_index]//2

print(sum(A))

Fixed submission:
import heapq

N, M = map(int, input().split())
A = [-i for i in map(int, input().split())]
heapq.heapify(A)
for i in range(M):
  tmp = -((-heapq.heappop(A))//2)
  heapq.heappush(A, tmp)

print(-sum(A))

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)

for i in range(M):
  A[A.index(max(A))] = A[A.index(max(A))]//2

print(sum(A))

Fixed submission:
import heapq

N, M = map(int, input().split())
A = [-i for i in map(int, input().split())]
heapq.heapify(A)
for i in range(M):
  tmp = -((-heapq.heappop(A))//2)
  heapq.heappush(A, tmp)

print(-sum(A))
Buggy python submission (verdict: Runtime Error):
N = input()

print(N**3)

Fixed submission:
N = int(input())
print(N**3)
Buggy python submission (verdict: Runtime Error):
N = int(input())

print(sum(list(range(N))))

Fixed submission:
N = int(input())

print(N*(N-1)//2)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

P = [i for i in range(1, N)]
print(sum(P))

Fixed submission:
N = int(input())

print(N*(N-1)//2)
Buggy python submission (verdict: Runtime Error):
    a = int(input())
    s = input()
    if a >= 3200:
        print(s)
    else:
        print("red")

Fixed submission:
a = int(input())
s = input()
if a >= 3200:
  print(s)
else:
  print("red")
Buggy python submission (verdict: Runtime Error):
a = int(input())
s = input()
    if a >= 3200:
        print(s)
    else:
        print("red")

Fixed submission:
A, B = map(int, input().split())
print(max([A + B, A - B, A * B]))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
import itertools

def verify_anagrams(first_word, second_word):
    return Counter(first_word) == Counter(second_word)

N = int(input())
S = [str(Counter(sorted(input()))) for _ in range(N)]
print(sum((x * (x - 1)) // 2 for x in Counter(S).values()))

Fixed submission:
from collections import Counter
import itertools

N = int(input())
S = ["".join(sorted(input())) for _ in range(N)]
print(sum((x * (x - 1)) // 2 for x in Counter(S).values()))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
import itertools

def verify_anagrams(first_word, second_word):
    return Counter(first_word) == Counter(second_word)

N = int(input())
S = [Counter(input()) for _ in range(N)]
sum = 0

x = itertools.combinations(S, 2)
for combi in x:
    if combi[0] == combi[1]:
        sum += 1
# print(Counter(S))
print(sum)

Fixed submission:
from collections import Counter
import itertools

N = int(input())
S = ["".join(sorted(input())) for _ in range(N)]
print(sum((x * (x - 1)) // 2 for x in Counter(S).values()))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
import itertools

def verify_anagrams(first_word, second_word):
    return Counter(first_word) == Counter(second_word)

N = int(input())
S = []
for _ in range(N):
    S.append(Counter(input()))
sum = 0

x = itertools.combinations(S, 2)
for combi in x:
    if combi[0] == combi[1]:
        sum += 1
# print(Counter(S))
print(sum)

Fixed submission:
from collections import Counter
import itertools

N = int(input())
S = ["".join(sorted(input())) for _ in range(N)]
print(sum((x * (x - 1)) // 2 for x in Counter(S).values()))
Buggy python submission (verdict: Runtime Error):
N = input()
P = list(map(int, input().split()))
sort_P = sorted(P)
new_P = []
for idx, p in enumerate(P):
    new_P.append(sort_P[idx] - p)
new_new_P = set(new_P)
new_new_P.remove(0)
if len(new_new_P) > 2:
    print("NO")
else:
    print("YES")

Fixed submission:
N = input()
P = list(map(int, input().split()))
flag = 0
for idx, p in enumerate(P):
    if p != idx + 1:
        flag += 1

if flag > 2:
    print("NO")
else:
    print("YES")
Buggy python submission (verdict: Time Limit Exceeded):
import heapq
import copy
N = input()
A = [-int(input()) for _ in range(int(N))]
A_heap = copy.deepcopy(A)
for idx, a in enumerate(A):
    heapq.heapify(A_heap)
    pop_A = heapq.heappop(A_heap)
    pop_A_list = []
    pop_A_list.append(pop_A)
    if pop_A == a:
        pop_A2 = heapq.heappop(A_heap)
        print(-(pop_A2))
        heapq.heappush(A_heap, pop_A)
        heapq.heappush(A_heap, pop_A2)
        continue

    print(-(pop_A))
    heapq.heappush(A_heap, pop_A)

Fixed submission:
import heapq
import copy
N = input()
A = [-int(input()) for _ in range(int(N))]
A_heap = copy.deepcopy(A)
heapq.heapify(A_heap)
for idx, a in enumerate(A):
    pop_A = heapq.heappop(A_heap)
    pop_A_list = []
    pop_A_list.append(pop_A)
    if pop_A == a:
        pop_A2 = heapq.heappop(A_heap)
        print(-(pop_A2))
        heapq.heappush(A_heap, pop_A)
        heapq.heappush(A_heap, pop_A2)
        continue

    print(-(pop_A))
    heapq.heappush(A_heap, pop_A)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
import copy
N = input()
A = [-int(input()) for _ in range(int(N))]
A_heap = copy.deepcopy(A)
for idx, a in enumerate(A):
    heapq.heapify(A_heap)
    pop_A = heapq.heappop(A_heap)
    pop_A_list = []
    pop_A_list.append(pop_A)
    if pop_A == a:
        pop_A = heapq.heappop(A_heap)
        pop_A_list.append(pop_A)

    print(-(pop_A))
    for i in pop_A_list:
        heapq.heappush(A_heap, i)

Fixed submission:
import heapq
import copy
N = input()
A = [-int(input()) for _ in range(int(N))]
A_heap = copy.deepcopy(A)
heapq.heapify(A_heap)
for idx, a in enumerate(A):
    pop_A = heapq.heappop(A_heap)
    pop_A_list = []
    pop_A_list.append(pop_A)
    if pop_A == a:
        pop_A2 = heapq.heappop(A_heap)
        print(-(pop_A2))
        heapq.heappush(A_heap, pop_A)
        heapq.heappush(A_heap, pop_A2)
        continue

    print(-(pop_A))
    heapq.heappush(A_heap, pop_A)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
import copy
N = input()
A = [-int(input()) for _ in range(int(N))]
for idx, a in enumerate(A):
    A_heap = copy.deepcopy(A)
    A_heap.pop(idx)
    heapq.heapify(A_heap)
    pop_A = heapq.heappop(A_heap)
    print(-(pop_A))

Fixed submission:
import heapq
import copy
N = input()
A = [-int(input()) for _ in range(int(N))]
A_heap = copy.deepcopy(A)
heapq.heapify(A_heap)
for idx, a in enumerate(A):
    pop_A = heapq.heappop(A_heap)
    pop_A_list = []
    pop_A_list.append(pop_A)
    if pop_A == a:
        pop_A2 = heapq.heappop(A_heap)
        print(-(pop_A2))
        heapq.heappush(A_heap, pop_A)
        heapq.heappush(A_heap, pop_A2)
        continue

    print(-(pop_A))
    heapq.heappush(A_heap, pop_A)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
 
answer_list = []
for i in range(N):
    counter = 0
    i_num = N - i
    for j in range(i_num, N+1, i_num):
        if j in answer_list:
            counter += 1
    if counter % 2 == A[i_num - 1]:
        continue
    else:
        answer_list.append(i_num)
print(len(answer_list))
if answer_list:
    print(" ".join(map(str, answer_list)))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
flag = [-1] * (N+1)
answer_list = []
for i in range(N):
    counter = 0
    i_num = N - i
    for j in range(i_num, N+1, i_num):
        if j == i_num:
            continue
        else:
            if flag[j] == 1:
                counter += 1
    if counter % 2 == A[i_num - 1]:
        flag[i_num] = 0
    else:
        flag[i_num] = 1
        answer_list.append(i_num)
print(len(answer_list))
if answer_list:
    print(" ".join(map(str, answer_list)))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

answer_list = []
for i in range(N):
    counter = 0
    i_num = N - i

    for j in range(i):
        j_num = i_num + j + 1
        if j_num // i_num == 0 and j_num in answer_list:
            counter += 1
    if counter // 2 == A[i_num - 1]:
        continue
    else:
        answer_list.append(i_num)
print(len(answer_list))
if answer_list:
    print(" ".join(map(str, answer_list)))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
flag = [-1] * (N+1)
answer_list = []
for i in range(N):
    counter = 0
    i_num = N - i
    for j in range(i_num, N+1, i_num):
        if j == i_num:
            continue
        else:
            if flag[j] == 1:
                counter += 1
    if counter % 2 == A[i_num - 1]:
        flag[i_num] = 0
    else:
        flag[i_num] = 1
        answer_list.append(i_num)
print(len(answer_list))
if answer_list:
    print(" ".join(map(str, answer_list)))
Buggy python submission (verdict: Time Limit Exceeded):
L, R = map(int, input().split())

answer = 5000
for i in range(L, R+1):
    for j in range(i+1, R+1):
        if (i*j)%2019 < answer:
            answer = (i*j)%2019
print(answer)

Fixed submission:
import heapq

L, R = map(int, input().split())

if R - L >= 2019:
    print(0)
else:
    answer = 5000
    for i in range(L, R + 1):
        for j in range(i + 1, R + 1):
            if (i * j) % 2019 < answer:
                answer = (i * j) % 2019
    print(answer)

Buggy python submission (verdict: Runtime Error):
L, R = map(int, input().split())

answer = 5000
for i in range(L, R+1):
    for j in range(i+1, R+1):
        if (i*j)%2019 < answer:
            answer = (i*j)%2019
print(answer

Fixed submission:
import heapq

L, R = map(int, input().split())

if R - L >= 2019:
    print(0)
else:
    answer = 5000
    for i in range(L, R + 1):
        for j in range(i + 1, R + 1):
            if (i * j) % 2019 < answer:
                answer = (i * j) % 2019
    print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

answer_list = []

for i in range(N):
    answer = 0
    for j in range(N):
        # print(i, j, i-1-j, A[i-1-j])
        if j % 2 == 0:
            answer += A[i-1-j]
        else:
            answer -= A[i-1-j]

    answer_list.append(answer)
print(" ".join(map(str, answer_list)))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))

answer_list = []

for i in range(N):
    answer = 0
    if i == 0:
        for j in range(N):
            # print(i, j, i-1-j, A[i-1-j])
            if j % 2 == 0:
                answer += A[i-1-j]
            else:
                answer -= A[i-1-j]
    else:
        answer = 2*A[i-1] - answer_list[i-1]

    answer_list.append(answer)
print(" ".join(map(str, answer_list)))
Buggy python submission (verdict: Time Limit Exceeded):
A, B, C, D = map(int, input().split())

count = 0
for i in range(A, B+1):
  if i % C != 0 and i % D != 0:
    count += 1
print(count)

Fixed submission:
A, B, C, D = map(int, input().split())

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd (a, b)

C_ok = (B // C) - ((A-1) // C) 
D_ok = (B // D) - ((A-1) // D)
C_D_ok = (B // lcm(C, D)) - ((A-1) // lcm(C, D))
print((B-A+1)-C_ok-D_ok+C_D_ok)
Buggy python submission (verdict: Runtime Error):
import itertools
import collections

N = int(input())
x_y = [list(map(int, input().split())) for _ in range(N)]

count = collections.defaultdict(int)
for i in itertools.combinations(x_y, 2):
    count[(i[0][0]-i[1][0], i[0][1]-i[1][1])] += 1
    count[(i[1][0]-i[0][0], i[1][1]-i[0][1])] += 1

print(N-max(count.values()))

Fixed submission:
import itertools
import collections

N = int(input())
x_y = [list(map(int, input().split())) for _ in range(N)]

count = collections.defaultdict(int)
for i in itertools.combinations(x_y, 2):
    count[(i[0][0]-i[1][0], i[0][1]-i[1][1])] += 1
    count[(i[1][0]-i[0][0], i[1][1]-i[0][1])] += 1
if not count:
    print(N)
else:
    print(N-max(count.values()))

Buggy python submission (verdict: Runtime Error):
import itertools
import collections

N = int(input())
x_y = [list(map(int, input().split())) for _ in range(N)]

count = collections.defaultdict(int)
for i in itertools.combinations(x_y, 2):
    count[(i[0][0]-i[1][0], i[0][1]-i[1][1])] += 1
    count[(i[1][0]-i[0][0], i[1][1]-i[0][1])] += 1

print(N-max(count.values()))

Fixed submission:
import itertools
import collections

N = int(input())
x_y = [list(map(int, input().split())) for _ in range(N)]

count = collections.defaultdict(int)
for i in itertools.combinations(x_y, 2):
    count[(i[0][0]-i[1][0], i[0][1]-i[1][1])] += 1
    count[(i[1][0]-i[0][0], i[1][1]-i[0][1])] += 1
if not count:
    print(N)
else:
    print(N-max(count.values()))
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

a = {i for i in range(1, N+1)}
for i in range(M):
    L, R = map(int, input().split())
    # print(a, set([i for i in range(L, R+1)]))
    a = a & {i for i in range(L, R+1)}
    # print(a, set([i for i in range(L, R+1)]))

print(len(a))

Fixed submission:
N, M = map(int, input().split())

a = {i for i in range(1, N+1)}
L_list = []
R_list = []
for i in range(M):
    L, R = map(int, input().split())
    L_list.append(L)
    R_list.append(R)
    # print(a, set([i for i in range(L, R+1)]))
    # a = a & {i for i in range(L, R+1)}
    # print(a, set([i for i in range(L, R+1)]))

print(max(min(R_list) - max(L_list) + 1, 0))
Buggy python submission (verdict: Runtime Error):
import math

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

answer = 0

for i in range(1, N+1):
    if K > i:
        answer += (1/N) * (1/2)**(math.ceil(math.log2(K/i)))
    else:
        answer += (1 / N) 
print(answer)

Fixed submission:
import math

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

answer = 0

for i in range(1, N+1):
    if K > i:
        answer += (1/N) * (1/2)**(math.ceil(math.log2(K/i)))
    else:
        answer += (1 / N) 
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
import fractions

a = list(map(int, input().split()))

ans_max = 0
for i in range(N):
    if i == 0:
        ans = 0
    else:
        ans = a[0]
    for j in range(1, N):
        if i == j:
            ans = fractions.gcd(ans, 0)
        else:
            ans = fractions.gcd(ans, a[j])
    ans_max = max(ans, ans_max)

print(ans_max)

Fixed submission:
N = int(input())
import fractions

a = list(map(int, input().split()))

gcd_start = [0]
gcd_end = [0]

ans = a[0]
gcd_start.append(ans)
for i in range(1, N-1):
    ans = fractions.gcd(ans, a[i])
    gcd_start.append(ans)

ans = a[-1]
gcd_end.append(ans)
for i in range(-2, -N, -1):
    ans = fractions.gcd(ans, a[i])
    gcd_end.append(ans)

ans_max = 0
for i in range(N):
    ans = fractions.gcd(gcd_end[-i-1], gcd_start[i])
    ans_max = max(ans, ans_max)

print(ans_max)

Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
from fractions import gcd
from collections import deque
N = int(input())
A = list(map(int, input().split()))

A_deque = deque(A)


def func_gcd(numbers):
    return reduce(gcd, numbers)

ans = 0
for _ in range(N):
    a = A_deque.popleft()
    ans = max(ans, func_gcd(A_deque))
    A_deque.append(a)

print(ans)

Fixed submission:
N = int(input())
import fractions

a = list(map(int, input().split()))

gcd_start = [0]
gcd_end = [0]

ans = a[0]
gcd_start.append(ans)
for i in range(1, N-1):
    ans = fractions.gcd(ans, a[i])
    gcd_start.append(ans)

ans = a[-1]
gcd_end.append(ans)
for i in range(-2, -N, -1):
    ans = fractions.gcd(ans, a[i])
    gcd_end.append(ans)

ans_max = 0
for i in range(N):
    ans = fractions.gcd(gcd_end[-i-1], gcd_start[i])
    ans_max = max(ans, ans_max)

print(ans_max)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
S = input()
S += "#"
S_list = []
if S[0] == "0":
    S_list.append(0)

count = 1
before_s = S[0]
for s in S[1:]:
    count += 1
    if before_s != s:
        S_list.append(count-1)
        count = 1
    before_s = s

if S[-2] == "0":
    S_list.append(0)

# print(S_list)

if len(S_list) < 2 * K:
    print(sum(S_list))
else:
    ans = 0
    for i in range(0, len(S_list) - (2 * K), 2):
        left = i
        right = i + 2 * K
        # print(S_list[left:right+1])
        ans = max(ans, sum(S_list[left:right+1]))
    print(ans)

Fixed submission:
N, K = map(int, input().split())
S = input()
S += "#"
S_list = []
if S[0] == "0":
    S_list.append(0)

count = 1
before_s = S[0]
for s in S[1:]:
    count += 1
    if before_s != s:
        S_list.append(count-1)
        count = 1
    before_s = s

if S[-2] == "0":
    S_list.append(0)

# print(S_list)

if len(S_list) < 2 * K:
    print(sum(S_list))
else:
    ans = 0
    ans_list = []
    for i in range(0, len(S_list) - (2 * K), 2):
        left = i
        right = i + 2 * K
        # print(S_list[left:right+1])
        if i == 0:
            ans = sum(S_list[left:right+1])
            ans_list.append(ans)
        else:
            # print(S_list[left-2:left], S_list[right-1:right+1])
            ans = ans - sum(S_list[left-2:left]) + sum(S_list[right-1:right+1])
            ans_list.append(ans)
    print(max(ans_list))

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
S = input()
S += "#"
S_list = []
if S[0] == "0":
    S_list.append(0)

count = 0
for idx, s in enumerate(S[:-1]):
    count += 1
    if s != S[idx+1]:
        S_list.append(count)
        count = 0

if S[-2] == "0":
    S_list.append(0)

# print(S_list)

if len(S_list) < 2 * K:
    print(sum(S_list))
else:
    ans = 0
    for i in range(0, len(S_list) - (2 * K), 2):
        left = i
        right = i + 2 * K
        # print(S_list[left:right+1])
        ans = max(ans, sum(S_list[left:right+1]))
    print(ans)

Fixed submission:
N, K = map(int, input().split())
S = input()
S += "#"
S_list = []
if S[0] == "0":
    S_list.append(0)

count = 1
before_s = S[0]
for s in S[1:]:
    count += 1
    if before_s != s:
        S_list.append(count-1)
        count = 1
    before_s = s

if S[-2] == "0":
    S_list.append(0)

# print(S_list)

if len(S_list) < 2 * K:
    print(sum(S_list))
else:
    ans = 0
    ans_list = []
    for i in range(0, len(S_list) - (2 * K), 2):
        left = i
        right = i + 2 * K
        # print(S_list[left:right+1])
        if i == 0:
            ans = sum(S_list[left:right+1])
            ans_list.append(ans)
        else:
            # print(S_list[left-2:left], S_list[right-1:right+1])
            ans = ans - sum(S_list[left-2:left]) + sum(S_list[right-1:right+1])
            ans_list.append(ans)
    print(max(ans_list))