Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n-1):
    cnt = 1
    a_std = a[i]
    for j in range(i+1, n):
        if cnt == a_std + a[j]: ans += 1
        cnt += 1
print(ans)

Fixed submission:
from collections import Counter
n = int(input())
a1, a2 = [], []
for idx, ai in enumerate(map(int, input().split())):
    a1.append(ai+idx)
    a2.append(idx-ai)
cnt = Counter(a2)
res = 0
for idx, i in enumerate(a1):
    cnt[a2[idx]] -= 1
    res += cnt[i]
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
ans = 0
for i in range(n-3):
    i_ = s[i]
    for j in range(i+1, n-1):
        if s[j] == i_: continue
        else:
            k = 2 * j - i
            j_ = s[j]
            s_ = s[j+1:]
            ans += len(s_) - s_.count(i_) - s_.count(j_)
            if k >= n: continue
            if s[k] != i_ and s[k] != j_: ans -= 1
print(ans)

Fixed submission:
n = int(input())
s = input()
ans = s.count("R") * s.count("G") * s.count("B")
cnt = 0
for i in range(n):
    i_ = s[i]
    for j in range(i+1, n):
        if s[j] == i_: continue
        k = 2 * j - i
        j_ = s[j]
        if k >= n or s[k] == i_ or s[k] == j_: continue
        cnt += 1
print(ans - cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
ans = n
if k == 1 or n == 0:
    print(0)
    exit()
while True:
    if ans < abs(n-k):
        break
    else:
        n = abs(n-k)
        ans = n
print(ans)


Fixed submission:
n, k = map(int, input().split())
print(min(n%k, abs((n // k + 1) * k - n)))

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
ans = n
if k == 1:
    print(0)
    exit()
while True:
    if ans < abs(n-k):
        break
    else:
        n = abs(n-k)
        ans = n
print(ans)

Fixed submission:
n, k = map(int, input().split())
print(min(n%k, abs((n // k + 1) * k - n)))
Buggy python submission (verdict: Time Limit Exceeded):
s = [i for i in input()]
q = int(input())
for _ in range(q):
    s_ = input()
    if len(s_) == 1:
        s = s[::-1]
    else:
        _, f, c = map(str, s_.split())
        if f == "1": s.insert(0, c)
        else: s.append(c)
print("".join(s))

Fixed submission:
from collections import deque
s = deque([i for i in input()])
q = int(input())
cnt = 0
for _ in range(q):
    s_ = input()
    if len(s_) == 1: cnt += 1
    else:
        if (int(s_[2]) + cnt % 2) % 2 == 0: s.append(s_[4])
        else: s.appendleft(s_[4])
if cnt % 2 == 1: print("".join(list(s)[::-1]))
else: print("".join(s))
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
dic = {i: [] for i in range(1, n + 1)}
for _ in range(m):
    s_, c_ = map(int, input().split())
    if dic[s_]:
        if dic[s_][0] != c_:
            print(-1)
            exit()
        else: continue
    dic[s_].append(c_)
res = ""
if dic[1][0] == 0:
    print(-1)
    exit()
for k in dic.keys():
    if dic[k]:
        res += str(dic[k][0])
    else:
        if k == 1:
            res += "1"
        else:
            res += "0"
print(res)

Fixed submission:
n, m = map(int, input().split())
sc = []
for _ in range(m):
    s_, c_ = map(int, input().split())
    sc.append([s_-1, c_])
ans = [-1 for _ in range(n)]
for s, c in sc:
    if s == 0 and c == 0:
        if n != 1:
            print(-1)
            exit()
    if ans[s] is -1: ans[s] = c
    elif ans[s] is not None and ans[s] != c:
        print(-1)
        exit()
for i in range(n):
    if ans[i] == -1:
        if i == 0:
            if n == 1: ans[i] = 0
            else: ans[i] = 1
        else:
            ans[i] = 0
print("".join(map(str, ans)))
Buggy python submission (verdict: Runtime Error):
if a[0] == a[1] == a[2]: print("No")
elif a[0] == a[1] or a[1] == a[2]: print("Yes")
else: print("No")

Fixed submission:
a = [int(x) for x in input().split()]
a.sort()
if a[0] == a[1] == a[2]: print("No")
elif a[0] == a[1] or a[1] == a[2]: print("Yes")
else: print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n, k = (int(x) for x in input().split())
p = [(int(x)*(int(x)+1) / 2) / int(x) for x in input().split()]
print(max([sum(p[i:i+k]) for i in range(len(p)-k+1)]))

Fixed submission:
n, k = (int(x) for x in input().split())
p = [int(x) / 2 + 0.5 for x in input().split()]
ans_i = ans = sum(p[:k])
i = 0
while i < n - k:
    ans_i = ans_i - p[i] + p[i+k]
    ans = max(ans, ans_i)
    i += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = (int(x) for x in input().split())
p = [int(x) for x in input().split()]
p_sum = [sum(p[i:i+k]) for i in range(len(p)-k+1)]
idx = p_sum.index(max(p_sum))
print(sum([(p_i*(p_i+1))/2 / p_i for p_i in p[idx:idx+k]]))

Fixed submission:
n, k = (int(x) for x in input().split())
p = [int(x) / 2 + 0.5 for x in input().split()]
ans_i = ans = sum(p[:k])
i = 0
while i < n - k:
    ans_i = ans_i - p[i] + p[i+k]
    ans = max(ans, ans_i)
    i += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = (int(x) for x in input().split())
p = [int(x) for x in input().split()]
p_sum = [sum(p[i:i+k]) for i in range(len(p)-k+1)]
idx = p_sum.index(max(p_sum))
ans = 0
for p_i in p[idx:idx+k]:
    ans += ((p_i*(p_i+1))/2) / p_i
print(ans)

Fixed submission:
n, k = (int(x) for x in input().split())
p = [int(x) / 2 + 0.5 for x in input().split()]
ans_i = ans = sum(p[:k])
i = 0
while i < n - k:
    ans_i = ans_i - p[i] + p[i+k]
    ans = max(ans, ans_i)
    i += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = (int(x) for x in input().split())
p = [int(x) for x in input().split()]
p_sum = [sum(p[i:i+k]) for i in range(len(p)-k+1)]
idx = p_sum.index(max(p_sum))
ans = 0
for p_i in p[idx:idx+k]:
    b = 1 / p_i
    for i in range(1, int(p_i+1)):
        ans += i * b
print(ans)

Fixed submission:
n, k = (int(x) for x in input().split())
p = [int(x) / 2 + 0.5 for x in input().split()]
ans_i = ans = sum(p[:k])
i = 0
while i < n - k:
    ans_i = ans_i - p[i] + p[i+k]
    ans = max(ans, ans_i)
    i += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
n, k, s = map(int, input().split())
ans = [s for _ in range(n)]
for i in range(k, n):
        ans[i] = ans[i] + 1 if s < 1000000000 else ans[i] = 1
print(*ans)

Fixed submission:
n, k, s = map(int, input().split())
ans = [s for _ in range(k)]
for i in range(k, n):
        ans.append(s+1) if s < 1000000000 else ans.append(1)
print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = [int(i) for i in input().split()]
l.sort()
ans = 0
for i in range(n-2):
    a = l[i]
    for j in range(i+1, n-1):
        b = l[j]
        p = a + b
        if p > l[-1]:
            ans += sum([m for m in range(1, n - j)])
            break
        for k in range(j+1, n):
            if p > l[k]: ans += 1
            else: break
print(ans)

Fixed submission:
from bisect import bisect_left
n = int(input())
l = [int(i) for i in input().split()]
l.sort()
ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        ans += bisect_left(l, l[i]+l[j]) - j - 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = [int(i) for i in input().split()]
l.sort()
ans = 0
for i in range(n-2):
    a = l[i]
    for j in range(i+1, n-1):
        b = l[j]
        p = a + b
        for k in range(j+1, n):
            if p > l[k]: ans += 1
            else: break
print(ans)

Fixed submission:
from bisect import bisect_left
n = int(input())
l = [int(i) for i in input().split()]
l.sort()
ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        ans += bisect_left(l, l[i]+l[j]) - j - 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = [int(i) for i in input().split()]
ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            if abs(l[j] - l[k]) < l[i] < l[j] + l[k]: ans += 1
print(ans)

Fixed submission:
from bisect import bisect_left
n = int(input())
l = [int(i) for i in input().split()]
l.sort()
ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        ans += bisect_left(l, l[i]+l[j]) - j - 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = [int(i) for i in input().split()]
ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            if l[i] < l[j] + l[k] and l[j] < l[i] + l[k] and l[k] < l[i] + l[j]: ans += 1
print(ans)

Fixed submission:
from bisect import bisect_left
n = int(input())
l = [int(i) for i in input().split()]
l.sort()
ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        ans += bisect_left(l, l[i]+l[j]) - j - 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(x) for x in input().split()]
for i in range(1, n+1):
    print(a.index(i)+1)

Fixed submission:
n = int(input())
a = [int(x) for x in input().split()]
ans = [0 for _ in range(n)]
for i, v in enumerate(a):
    ans[v-1] = i+1
for i in ans: print(i)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(x) for x in input().split()]
ans = []
for i in range(1, n+1):
    ans.append(a.index(i)+1)
for i in range(n): print(ans[i])

Fixed submission:
n = int(input())
a = [int(x) for x in input().split()]
ans = [0 for _ in range(n)]
for i, v in enumerate(a):
    ans[v-1] = i+1
for i in ans: print(i)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = (int(x) for x in input().split())
a = [int(x) for x in input().split()]
for _ in range(m):
    idx = a.index(max(a))
    a[idx] //= 2
print(sum(a))

Fixed submission:
import heapq as hp
n, m = (int(x) for x in input().split())
a = [int(x)*(-1) for x in input().split()]
hp.heapify(a)
for _ in range(m):
    min = hp.heappop(a)
    hp.heappush(a, (-1)*(-min//2))
print(-sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
if n == 1: print(a[0] // (2**m))
else:
    a.sort()
    for _ in range(m):
        a[-1] //= 2
        if a[-1] >= a[-2]: continue
        else:
            a.sort()
    print(sum(a))

Fixed submission:
import heapq as hp
n, m = (int(x) for x in input().split())
a = [int(x)*(-1) for x in input().split()]
hp.heapify(a)
for _ in range(m):
    min = hp.heappop(a)
    hp.heappush(a, (-1)*(-min//2))
print(-sum(a))

Buggy python submission (verdict: Runtime Error):
n, m = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
a.sort()
for _ in range(m):
    a[-1] //= 2
    if a[-1] >= a[-2]: continue
    else:
        a.sort()
print(sum(a))

Fixed submission:
import heapq as hp
n, m = (int(x) for x in input().split())
a = [int(x)*(-1) for x in input().split()]
hp.heapify(a)
for _ in range(m):
    min = hp.heappop(a)
    hp.heappush(a, (-1)*(-min//2))
print(-sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
for _ in range(m):
    idx = a.index(max(a))
    a[idx] //= 2
print(sum(a))

Fixed submission:
import heapq as hp
n, m = (int(x) for x in input().split())
a = [int(x)*(-1) for x in input().split()]
hp.heapify(a)
for _ in range(m):
    min = hp.heappop(a)
    hp.heappush(a, (-1)*(-min//2))
print(-sum(a))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = []
ans = 0
for _ in range(n):
    s.append("".join(sorted(str(input()))))
for i in range(n-1):
    for j in range(i+1, n):
        if s[i] == s[j]: ans +=1
print(ans)

Fixed submission:
n = int(input())
s = []
d = {}
for _ in range(n):
    s.append("".join(sorted(str(input()))))
for si in s:
    if si not in d.keys():
        d[si] = 1
    else: d[si] += 1
ans = 0
val = d.values()
for v in val:
    ans += v*(v-1)/2
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = []
ans = 0
for _ in range(n):
    s.append(sorted(str(input())))
for i in range(n-1):
    for j in range(i+1, n):
        if s[i] == s[j]: ans +=1
print(ans)

Fixed submission:
n = int(input())
s = []
d = {}
for _ in range(n):
    s.append("".join(sorted(str(input()))))
for si in s:
    if si not in d.keys():
        d[si] = 1
    else: d[si] += 1
ans = 0
val = d.values()
for v in val:
    ans += v*(v-1)/2
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = []
for _ in range(n):
    s.append(str(input()))
for i in range(n):
    s[i] = sorted(s[i])
ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        if s[i] == s[j]: ans +=1
print(ans)

Fixed submission:
n = int(input())
s = []
d = {}
for _ in range(n):
    s.append("".join(sorted(str(input()))))
for si in s:
    if si not in d.keys():
        d[si] = 1
    else: d[si] += 1
ans = 0
val = d.values()
for v in val:
    ans += v*(v-1)/2
print(int(ans))
Buggy python submission (verdict: Runtime Error):
import math


def func(a, b, div):
    if (a/div).is_integer(): c_1 = int(a/div)
    else: c_1 = a // div + 1
    c_2 = b // div
    return int(c_2 - c_1 + 1)


a, b, c, d = (int(x) for x in input().split())
print(int((b - a + 1) - func(a, b, c) - func(a, b, d) + func(a, b, c*d//math.gcd(c, d))))

Fixed submission:
import fractions
def lcm(a,b):
  return a*b //fractions.gcd(a, b)

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

b_num = B//C + B//D - B//lcm(C, D)
a_num = (A-1)//C + (A-1)//D - (A-1)//lcm(C, D)
print((B-(A-1))-(b_num-a_num))

Buggy python submission (verdict: Runtime Error):
import math
a, b, c, d = (int(x) for x in input().split())
def func(div):
    if (a/div).is_integer(): c_1 = int(a/div)
    else: c_1 = a // div + 1
    c_2 = b // div
    return int(c_2 - c_1 + 1)
print(int((b - a + 1) - func(c) - func(d) + func(c*d//math.gcd(c, d))))

Fixed submission:
import fractions
def lcm(a,b):
  return a*b //fractions.gcd(a, b)

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

b_num = B//C + B//D - B//lcm(C, D)
a_num = (A-1)//C + (A-1)//D - (A-1)//lcm(C, D)
print((B-(A-1))-(b_num-a_num))
Buggy python submission (verdict: Runtime Error):
w, h, x, y = map(int, input().split())
m = 1 if x == w/2 and y == h/2 else m = 0
print(w*h/2, m)

Fixed submission:
w, h, x, y = (int(i) for i in input().split())
s = (w * h) / 2
met = 1 if (x == w/2 and y == h/2) else 0
print(s, met)
Buggy python submission (verdict: Runtime Error):
n, a, b, c, d = map(int, input().split())
s = [0 if i == "#" else 1 for i in input()]
cnt = 0
for si in range(a, max(c, d)):
    if si != 0:
        cnt = 0
    else:
        cnt += 1
        if cnt == 2:
            print("No")
            exit()
if c < d:
    print("Yes")
    exit()
idx = b - 1
cnt = 0
while idx < d:
    if s[idx] == s[idx+1] == s[idx+2] == 1:
        print("Yes")
        exit()
    else:
        idx += 1
print("No")

Fixed submission:
n, a, b, c, d = map(int, input().split())
s = input()
for i in range(a, max(c, d)):
    if s[i-1:i+1] == "##":
        print("No")
        exit()
if c < d:
    print("Yes")
    exit()
for i in range(b-1, d):
    if s[i-1:i+2] == "...":
        print("Yes")
        exit()
print("No")

Buggy python submission (verdict: Runtime Error):
n, a, b, c, d = map(int, input().split())
s = [0 if i == "#" else 1 for i in input()]
if c < d:
    print("Yes")
    exit()
idx = b - 1
cnt = 0
while idx <= d + 1:
    if s[idx] == 0:
        cnt = 0
    else:
        cnt += 1
        if cnt == 3:
            print("Yes")
            exit()
    idx += 1
print("No")

Fixed submission:
n, a, b, c, d = map(int, input().split())
s = input()
for i in range(a, max(c, d)):
    if s[i-1:i+1] == "##":
        print("No")
        exit()
if c < d:
    print("Yes")
    exit()
for i in range(b-1, d):
    if s[i-1:i+2] == "...":
        print("Yes")
        exit()
print("No")
Buggy python submission (verdict: Runtime Error):
n, m = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
a.sort()
bc = []
for _ in range(m):
    bc.append([int(i) for i in input().split()])
bc = sorted(bc, key=lambda x: x[1], reverse=True)
idx = 0
for i in range(m):
    v = bc[i][1]
    for j in range(idx, idx + bc[i][0]):
        if a[j] < v:
            a[j] = v
        else: break
        if j == idx + bc[i][0] - 1: idx += bc[i][0]
print(sum(a))

Fixed submission:
n, m = map(int, input().split())
a = [int(i) for i in input().split()]
bc = []
for _ in range(m): bc.append([int(i) for i in input().split()])
a.sort()
bc.sort(key=lambda x:x[1])
bc = bc[::-1]
idx = 0
for b, c in bc:
    for bi in range(b):
        if idx + bi == n or a[idx+bi] >= c:
            idx = "e"
            break
        else: a[idx+bi] = c
    if idx == "e": break
    else: idx += b
print(sum(a))

Buggy python submission (verdict: Runtime Error):
n, m = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
a.sort()
bc = []
for _ in range(m):
    bc.append([int(i) for i in input().split()])
bc = sorted(bc, key=lambda x: x[1], reverse=True)
idx = 0
for i in range(m):
    for j in range(idx, idx + bc[i][0]):
        if a[j] < bc[i][1]:
            a[j] = bc[i][1]
    idx += bc[i][0]
print(sum(a))


Fixed submission:
n, m = map(int, input().split())
a = [int(i) for i in input().split()]
bc = []
for _ in range(m): bc.append([int(i) for i in input().split()])
a.sort()
bc.sort(key=lambda x:x[1])
bc = bc[::-1]
idx = 0
for b, c in bc:
    for bi in range(b):
        if idx + bi == n or a[idx+bi] >= c:
            idx = "e"
            break
        else: a[idx+bi] = c
    if idx == "e": break
    else: idx += b
print(sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
a.sort()
bc = []
for _ in range(m):
    bc.append([int(i) for i in input().split()])
bc = sorted(bc, key=lambda x: x[1], reverse=True)
for i in range(m):
    for j in range(bc[i][0]):
        if a[j] < bc[i][1]:
            a[j] = bc[i][1]
    a.sort()
print(sum(a))

Fixed submission:
n, m = map(int, input().split())
a = [int(i) for i in input().split()]
bc = []
for _ in range(m): bc.append([int(i) for i in input().split()])
a.sort()
bc.sort(key=lambda x:x[1])
bc = bc[::-1]
idx = 0
for b, c in bc:
    for bi in range(b):
        if idx + bi == n or a[idx+bi] >= c:
            idx = "e"
            break
        else: a[idx+bi] = c
    if idx == "e": break
    else: idx += b
print(sum(a))
Buggy python submission (verdict: Runtime Error):
N = int(input())

t = [[0] * 10 for _ in range(10)]
for i in range(1, N + 1):
    s = str(i)
    t[int(s[0])][int(s[-1])] += 1

result = 0
for i in range(1, 10):
    for j in range(1, 10):
        result += t[i][j] * t[j][i]
print(result)

Fixed submission:
from itertools import accumulate
n, k = map(int, input().split())
s = [i for i in input()]
zero_one = [0]
if s[0] == "0":
    zero_one.append(0)
s_ = s[0]
cnt = 0
for i in range(n):
    if s_ == s[i]:
        cnt += 1
    else:
        zero_one.append(cnt)
        cnt = 1
        s_ = s[i]
zero_one.append(cnt)
if s[-1] == "0":
    zero_one.append(0)
ans = 0
l = len(zero_one)
zero_one = list(accumulate(zero_one))
for i in range(0, l, 2):
    ans = max(ans, zero_one[min(l-1, i+2*k+1)] - zero_one[i])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
s = [i for i in input()]
zero_one = []
if s[0] == "0":
    zero_one.append(0)
s_ = s[0]
cnt = 0
for i in range(n):
    if s_ == s[i]:
        cnt += 1
    else:
        zero_one.append(cnt)
        cnt = 1
        s_ = s[i]
zero_one.append(cnt)
if s[-1] == "0":
    zero_one.append(0)
ans = 0
l = len(zero_one)
for i in range(0, l, 2):
    ans = max(ans, sum(zero_one[i:i+2*k+1]))
print(ans)

Fixed submission:
from itertools import accumulate
n, k = map(int, input().split())
s = [i for i in input()]
zero_one = [0]
if s[0] == "0":
    zero_one.append(0)
s_ = s[0]
cnt = 0
for i in range(n):
    if s_ == s[i]:
        cnt += 1
    else:
        zero_one.append(cnt)
        cnt = 1
        s_ = s[i]
zero_one.append(cnt)
if s[-1] == "0":
    zero_one.append(0)
ans = 0
l = len(zero_one)
zero_one = list(accumulate(zero_one))
for i in range(0, l, 2):
    ans = max(ans, zero_one[min(l-1, i+2*k+1)] - zero_one[i])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
s = [i for i in input()]
zero_one = []
if s[0] == "0":
    zero_one.append(0)
s_ = s[0]
cnt = 0
for i in range(n):
    if s_ == s[i]:
        cnt += 1
    else:
        zero_one.append(cnt)
        cnt = 1
        s_ = s[i]
zero_one.append(cnt)
if s[-1] == "0":
    zero_one.append(0)
ans = 0
for i in range(0, n, 2):
    ans = max(ans, sum(zero_one[i:min(n, i+2*k+1)]))
print(ans)

Fixed submission:
from itertools import accumulate
n, k = map(int, input().split())
s = [i for i in input()]
zero_one = [0]
if s[0] == "0":
    zero_one.append(0)
s_ = s[0]
cnt = 0
for i in range(n):
    if s_ == s[i]:
        cnt += 1
    else:
        zero_one.append(cnt)
        cnt = 1
        s_ = s[i]
zero_one.append(cnt)
if s[-1] == "0":
    zero_one.append(0)
ans = 0
l = len(zero_one)
zero_one = list(accumulate(zero_one))
for i in range(0, l, 2):
    ans = max(ans, zero_one[min(l-1, i+2*k+1)] - zero_one[i])
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
b = [int(i) for i in input().split()]
ans = []
idx = n
if 1 not in b:
    print(-1)
    exit()
for i in reversed(range(n)):
    if b[i] != 1: continue
    else:
        b_ = b[i:idx]
        idx = i
        ma = max(b_)
        for j, bi in enumerate(b_):
            if bi == j + 1:
                for _ in range(b_.count(bi)):
                    ans.append(bi)
            elif bi < j + 1:
                break
            else:
                print(-1)
                exit()
for i in range(n): print(ans[i])

Fixed submission:
n = int(input())
b = list(map(int, input().split()))
res = []
for _ in range(n):
    idx = 0
    for i in range(len(b)):
        if b[i] == i + 1:
            idx = i + 1
    if idx == 0:
        print(-1)
        exit()
    res.append(idx)
    b.pop(idx-1)
res = res[::-1]
for i in range(n): print(res[i])
Buggy python submission (verdict: Time Limit Exceeded):
N, M = (int(x) for x in input().split())
a, b, b2, p = [], [], [], []
for i in range(N):
    o, t = (int(x) for x in input().split())
    a.append(o)
    b.append(t)
ans = 0
while M > 0:
    idx = a.index(min(a))
    n = b[idx]
    if M - n >= 0:
        ans += a[idx] * n
        M -= n
    else:
        ans += a[idx] * M
        M = 0
    del a[idx]
    del b[idx]
print(ans)



Fixed submission:
n, m = map(int, input().split())
l = []
for _ in range(n): l.append([int(x) for x in input().split()])
l.sort()
s = cnt = 0
for a, b in l:
    if cnt + b < m:
        s += a*b
        cnt += b
    else:
        s += a * (m - cnt)
        break
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = (int(x) for x in input().split())
a, b, b2, p = [], [], [], []
for i in range(N):
    p.append([int(x) for x in input().split()])
    a.append(p[i][0])
    b.append(p[i][1])
ans = 0
while M > 0:
    idx = [i for i, x in enumerate(a) if x == min(a)]
    if len(idx) == 1:
        n = b[idx[0]]
        idx = idx[0]
    else:
        b2.append([i, b[i]] for i in idx)
        n = max(b2[:][1])
        idx = b2.index(b2[:][1] == n)
    if M - n >= 0:
        ans += a[idx] * n
        M -= n
    else:
        ans += a[idx] * M
        M = 0
    del a[idx]
    del b[idx]

print(ans)


Fixed submission:
n, m = map(int, input().split())
l = []
for _ in range(n): l.append([int(x) for x in input().split()])
l.sort()
s = cnt = 0
for a, b in l:
    if cnt + b < m:
        s += a*b
        cnt += b
    else:
        s += a * (m - cnt)
        break
print(s)