Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [input() for _ in range(n)]
t = []
for i in range(n):
    t.append(s[i] + s[i])
t = t + t
ans = 0
for i in range(n):
    ok = True
    for j in range(n):
        for k in range(n):
            if t[i+j][k] != t[i+k][j]: 
                ok = False
                break
        if not ok: break
    if ok: ans += 1
print(ans * n)

Fixed submission:
n = int(input())
s = [input() for _ in range(n)]
t = []
for i in range(n):
    t.append(s[i] + s[i])
t = t + t
ans = 0
for i in range(n):
    ok = True
    for j in range(n):
        for k in range(n):
            if t[i+j][k] != t[i+k][j]: 
                ok = False
                break
        if not ok: break
    if ok: ans += 1
print(ans * n)

Buggy python submission (verdict: Time Limit Exceeded):
import time
import sys

n = int(input())
s = [input() for _ in range(n)]
t = []
for i in range(n):
    t.append(s[i] + s[i])
t = t + t

start = time.time()

ans = 0
for i in range(n):
    for j in range(n):
        ok = True
        for k in range(n):
            for l in range(k, n):
                if t[i+k][j+l] != t[i+l][j+k]: 
                    ok = False
                    break
            if not ok: break
        if ok: ans += 1
        if time.time() - start > 1600:
            print(n * n)
            sys.exit()
print(ans)

Fixed submission:
n = int(input())
s = [input() for _ in range(n)]
t = []
for i in range(n):
    t.append(s[i] + s[i])
t = t + t
ans = 0
for i in range(n):
    ok = True
    for j in range(n):
        for k in range(n):
            if t[i+j][k] != t[i+k][j]: 
                ok = False
                break
        if not ok: break
    if ok: ans += 1
print(ans * n)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
d = defaultdict(int)
for _ in range(int(input())):
    d[input()] += 1
for _ in range(int(input())):
    d[input()] -= 1
print(max(0, d.values()))


Fixed submission:
from collections import defaultdict
d1 = defaultdict(int)
d2 = defaultdict(int)
n = int(input())
for i in range(n):
    d1[input()] += 1
m = int(input())
for i in range(m):
    d2[input()] += 1

ans = 0
for k, v in d1.items():
    ans = max(ans, v - d2[k])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
x=[0]*n;y=[0]*n
for i in range(n):x[i],y[i]=map(int,input().split())

ans=1e20
for i in range(n):
    for j in range(i+1, n):
        for a in range(n):
            for b in range(a+1, n):
                cnt=0
                x1=min(x[i],x[j])
                x2=max(x[i],x[j])
                y1=min(y[a],y[b])
                y2=max(y[a],y[b])
                for c in range(n):
                    if x1<=x[c]<=x2 and y1<=y[c]<=y2: cnt+=1
                if cnt>=k:
                    ans=min(ans,(x2-x1)*(y2-y1))
print(ans)

Fixed submission:
n,k=map(int,input().split())
x=[0]*n;y=[0]*n
for i in range(n):x[i],y[i]=map(int,input().split())

ans=1e20
for i in range(n):
    for j in range(i+1, n):
        for a in range(n):
            for b in range(a+1, n):
                cnt=0
                x1=min(x[i],x[j])
                x2=max(x[i],x[j])
                y1=min(y[a],y[b])
                y2=max(y[a],y[b])
                for c in range(n):
                    if x1<=x[c]<=x2 and y1<=y[c]<=y2: cnt+=1
                if cnt>=k:
                    ans=min(ans,(x2-x1)*(y2-y1))
print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np
n, ma, mb = map(int, input().split())

item = [tuple(map(int, input().split())) for _ in range(n)]

INF = 5000
dp = np.full((n + 1, 444, 444), INF, dtype=np.int)

dp[0][0][0] = 0

for i in range(n):
    for j in range(401):
        for k in range(401):
            a, b, c = item[i]
            dp[i + 1][j + a][k + b] = min(dp[i + 1]
                                          [j + a][k + b], dp[i][j][k] + c)
            dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k])

ans = INF
for i in range(1, 401):
    for j in range(1, 401):  # i : j == ma : mb
        if ma * j == i * mb:
            ans = min(ans, dp[n][i][j])
print(ans if ans != INF else -1)


Fixed submission:
n, ma, mb = map(int, input().split())

item = [tuple(map(int, input().split())) for _ in range(n)]

INF = 5000
dp = [[INF] * 444 for _ in range(444)]


dp[0][0] = 0

for i in range(n):
    next = [[INF] * 444 for _ in range(444)]
    for j in range(401):
        for k in range(401):
            a, b, c = item[i]
            next[j + a][k + b] = min(next
                                     [j + a][k + b], dp[j][k] + c)
            next[j][k] = min(next[j][k], dp[j][k])
    dp = next

ans = INF
for i in range(1, 401):
    for j in range(1, 401):  # i : j == ma : mb
        if ma * j == i * mb:
            ans = min(ans, dp[i][j])
print(ans if ans != INF else -1)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n, ma, mb = map(int, input().split())

item = [tuple(map(int, input().split())) for _ in range(n)]

INF = 5000
dp = np.full((n + 1, 444, 444), INF, dtype=np.int)

dp[0][0][0] = 0

for i in range(n):
    for j in range(401):
        for k in range(401):
            a, b, c = item[i]
            dp[i + 1][j + a][k + b] = min(dp[i + 1]
                                          [j + a][k + b], dp[i][j][k] + c)
            dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k])

ans = INF
for i in range(1, 401):
    for j in range(1, 401):  # i : j == ma : mb
        if ma * j == i * mb:
            ans = min(ans, dp[n][i][j])
print(ans if ans != INF else -1)


Fixed submission:
n, ma, mb = map(int, input().split())

item = [tuple(map(int, input().split())) for _ in range(n)]

INF = 5000
dp = [[INF] * 444 for _ in range(444)]


dp[0][0] = 0

for i in range(n):
    next = [[INF] * 444 for _ in range(444)]
    for j in range(401):
        for k in range(401):
            a, b, c = item[i]
            next[j + a][k + b] = min(next
                                     [j + a][k + b], dp[j][k] + c)
            next[j][k] = min(next[j][k], dp[j][k])
    dp = next

ans = INF
for i in range(1, 401):
    for j in range(1, 401):  # i : j == ma : mb
        if ma * j == i * mb:
            ans = min(ans, dp[i][j])
print(ans if ans != INF else -1)
Buggy python submission (verdict: Runtime Error):
print('ACL' * int(input())
      

Fixed submission:
print('ACL' * int(input()))
Buggy python submission (verdict: Runtime Error):
M = 10**9 + 7
n = int(input())
print((pow(10, n, M) - 2 * pow(9, n, M) + pow(8, n, M) % M)


Fixed submission:
M = 10**9 + 7
n = int(input())
print((pow(10, n, M) - 2 * pow(9, n, M) + 8**n) % M)
Buggy python submission (verdict: Runtime Error):
b,c,a=1,M=1e9+7;main(s){for(scanf("%d",&s);s-->2;c=(a+b)%M)a=b,b=c;printf("%d",c);}

Fixed submission:
M = 10**9 + 7
s = int(input())

f = [1]
for i in range(1, s - 2):
  f.append(f[-1] * i % M)

r = 0
for k in range(s // 3):
  t = s - 2 * k - 3
  r += f[t] * pow(f[k], M - 2, M) * pow(f[t - k], M - 2, M)

print(r % M)

Buggy python submission (verdict: Runtime Error):
b,c,a=1,M=1e9+7;main(s){for(scanf("%d",&s);s-->2;c=(a+b)%M)a=b,b=c;print("%d",c);}

Fixed submission:
M = 10**9 + 7
s = int(input())

f = [1]
for i in range(1, s - 2):
  f.append(f[-1] * i % M)

r = 0
for k in range(s // 3):
  t = s - 2 * k - 3
  r += f[t] * pow(f[k], M - 2, M) * pow(f[t - k], M - 2, M)

print(r % M)
Buggy python submission (verdict: Runtime Error):
from itertools import accumulate
enum = enumerate

R = lambda: map(int, input().split())
*_, k = R()
a = accumulate(R())
b = tuple(accumulate(R()))
print(max(i + j for i, x in enum(a, 1) for j, y in enum(b, 1) if x + y <= k))


Fixed submission:
from itertools import accumulate
from bisect import bisect_right

R = lambda: map(int, input().split())
*_, k = R()
a = accumulate(R())
b = list(accumulate(R()))
r = bisect_right(b, k)
for i, x in enumerate(a, 1):
  if x > k:
    break
  j = bisect_right(b, k - x)
  r = max(r, i + j) 
print(r)
Buggy python submission (verdict: Runtime Error):
R = lambda: map(int, input().split())
R()
a = [0] * 100001
s = 0
for x in R():
  s += x
  a[x] += 1
q, = R()
for _ in range(q):
  b, c = R()
  s += (c - b) * a[b]
  print(s)
  a[c]+=d[b]
  a[b] = 0


Fixed submission:
from collections import Counter

R = lambda: map(int, input().split())
R()
d = Counter(R())
s = sum(d.elements())
q, = R()
for _ in range(q):
  b, c = R()
  s += (c - b) * d[b]
  print(s)
  d[c]+=d[b]
  d[b] = 0
Buggy python submission (verdict: Runtime Error):
from collections import deque

R=lambda: map(int, input().split())

n, m = R()
g = [[] for _ in range(n)]
for _ in range(m):
  u, v = R()
  g[u - 1].append(v - 1)
  g[v - 1].append(u - 1)

r = 'Yes' + [None] * (n - 1)
V = [True] + [False] * (n - 1)
q = deque([0])
while q:
  u = q.popleft()
  for v in g[u]:
    if not V[v]:
      V[v] = True
      r[v] = u + 1
      q.append(v)

print(*(['No'], r)[all(r)], sep='\n')


Fixed submission:
from collections import deque

R=lambda: map(int, input().split())

n, m = R()
g = [[] for _ in range(n)]
for _ in range(m):
  u, v = R()
  g[u - 1].append(v - 1)
  g[v - 1].append(u - 1)

r = [None] * (n - 1)
V = [True] + [False] * (n - 1)
q = deque([0])
while q:
  u = q.popleft()
  for v in g[u]:
    if not V[v]:
      V[v] = True
      r[v - 1] = u + 1
      q.append(v)

print(*(['No'],['Yes'] + r)[all(r)], sep='\n')

Buggy python submission (verdict: Time Limit Exceeded):
R=lambda: map(int, input().split())

n, m = R()
g = [[] for _ in range(n)]
for _ in range(m):
  u, v = R()
  g[u - 1].append(v - 1)
  g[v - 1].append(u - 1)

r = [None] * (n - 1)
V = [True] + [False] * (n - 1)
q = [0]; s = 0
while q[s:]:
  u = q[s]; s += 1
  for v in g[u]:
    if not V[v]:
      V[v] = True
      r[v - 1] = u + 1
      q.append(v)

print(*(['No'],['Yes'] + r)[all(r)], sep='\n')


Fixed submission:
from collections import deque

R=lambda: map(int, input().split())

n, m = R()
g = [[] for _ in range(n)]
for _ in range(m):
  u, v = R()
  g[u - 1].append(v - 1)
  g[v - 1].append(u - 1)

r = [None] * (n - 1)
V = [True] + [False] * (n - 1)
q = deque([0])
while q:
  u = q.popleft()
  for v in g[u]:
    if not V[v]:
      V[v] = True
      r[v - 1] = u + 1
      q.append(v)

print(*(['No'],['Yes'] + r)[all(r)], sep='\n')
Buggy python submission (verdict: Runtime Error):
from collections import Counter

n = int(input())
s = input()
x, y, z = Counter(s).values()
print(x * y * z - sum(s[i] != s[(i + j) // 2] != s[j] != s[i]
                      for i in range(n) for j in range(i + 2, n, 2))) 


Fixed submission:
from collections import Counter

n = int(input())
s = input()
c = Counter({'R': 0,'G': 0, 'B': 0})
c.update(s)
x, y, z = c.values()
print(x * y * z - sum(s[i] != s[(i + j) // 2] != s[j] != s[i]
                      for i in range(n) for j in range(i + 2, n, 2)))
Buggy python submission (verdict: Runtime Error):
from itertools import count, repeat

h = int(input().split()[0])
a0 = repeat('.')
r0 = list(range(w))
for i in range(h):
  a = input()
  r = [i]
  for x, y, z, u in zip(a0, '.' + a, a, r0):
    r.append(min(u + (x + z == '.#'), r[-1] + (y + z == '.#')))
  a0 = a
  r0 = r[1:]
print(r[-1])


Fixed submission:
h, w = map(int, input().split())
a0 = '.' * w
r0 = [200] * w
for i in range(h):
  a = input()
  r = [i * 200]
  for x, y, z, u in zip(a0, '.' + a, a, r0):
    r.append(min(u + (x + z == '.#'), r[-1] + (y + z == '.#')))
  a0 = a
  r0 = r[1:]
print(r[-1])
Buggy python submission (verdict: Runtime Error):
R = lambda: tuple(map(int, input().split()))
A, B, M = R()
a, b = R(), R()
d = (R() for _ in range(M))
print(min([min(a) + min(b)] + [a[x - 1] + b[x - 1] - c for x, y, c in d]))


Fixed submission:
R = lambda: tuple(map(int, input().split()))
A, B, M = R()
a, b = R(), R()
d = (R() for _ in range(M))
print(min([min(a) + min(b)] + [a[x - 1] + b[y - 1] - c for x, y, c in d]))

Buggy python submission (verdict: Runtime Error):
R = lambda: tuple(map(int, input().split()))
A, B, M = R()
a, b = R(), R()
l = (R() for _ in range(M))
print(min(a[x - 1] + b[x - 1] - c for x, y, c in l))


Fixed submission:
R = lambda: tuple(map(int, input().split()))
A, B, M = R()
a, b = R(), R()
d = (R() for _ in range(M))
print(min([min(a) + min(b)] + [a[x - 1] + b[y - 1] - c for x, y, c in d]))
Buggy python submission (verdict: Runtime Error):
M = 10**9 + 7
n, a, b = map(int, input().split())
r = (pow(2, n, M) - 1) % M
f = c = 1
for i in range(b):
  f = f * (i + 1) % M
  c = c * (n - i) % M
  if i + 1 == a:
    r = (r - c * pow(f, M - 2, M)) % M
print((r - c * pow(f, M - 2, M) % M))


Fixed submission:
input()
a = list(map(int, input().split()))
print(min(sum((x - p)**2 for x in a) for p in range(1, 101)))

Buggy python submission (verdict: Runtime Error):
M = 10**9 + 7
n, a, b = map(int, input().split())
r = (pow(2, n, M) - 1) % M
f = c = 1
for i in range(b):
  f = f * (i + 1) % M
  c = c * (n - i) % M
  if i + 1 == a:
    r = (r - c * pow(f, M - 2, M)) % M
print((r - c * pow(f, M - 2, M) % M)


Fixed submission:
input()
a = list(map(int, input().split()))
print(min(sum((x - p)**2 for x in a) for p in range(1, 101)))
Buggy python submission (verdict: Runtime Error):
from itertools import groupby
from itertools import itemgetter

a = groupby(sorted(input() for _ in range(int(input()))))
a = [(len(tuple(g)), s) for s, g in a]
m = max(a, key=itemgetter(0))[0]
for k, s in a:
  if k == m:
    print(s)


Fixed submission:
from collections import Counter
from itertools import groupby
from operator import itemgetter

c = Counter(input() for _ in range(int(input())))
a = sorted((-c[x],x) for x in c)
for _, s in next(groupby(a, itemgetter(0)))[1]:
  print(s)

Buggy python submission (verdict: Runtime Error):
from itertools import groupby
from iterator import itemgetter

a = groupby(sorted(input() for _ in range(int(input()))))
a = [(len(tuple(g)), s) for s, g in a]
m = max(a, key=itemgetter(0))[0]
for k, s in a:
  if k == m:
    print(s)


Fixed submission:
from collections import Counter
from itertools import groupby
from operator import itemgetter

c = Counter(input() for _ in range(int(input())))
a = sorted((-c[x],x) for x in c)
for _, s in next(groupby(a, itemgetter(0)))[1]:
  print(s)

Buggy python submission (verdict: Runtime Error):
from collections import Counter

c = Counter(input() for _ in range(int(input())))
m = max(c.values())
for s in sorted(s for s, k in c.items() if k == m) 
  print(s)


Fixed submission:
from collections import Counter
from itertools import groupby
from operator import itemgetter

c = Counter(input() for _ in range(int(input())))
a = sorted((-c[x],x) for x in c)
for _, s in next(groupby(a, itemgetter(0)))[1]:
  print(s)
Buggy python submission (verdict: Runtime Error):
r = range(1, 10)
n = int(input())
a = [None] + [[0] * 10 for _ in r]
for i in r:
  if i <= n:
    a[i][j] += 1
for i in r:
  for j in r:
    k = 1
    while 10 * k * i + j <= n:
      a[i][j] += min(k, (n - j) // 10 - k * i + 1)
      k *= 10
print(sum(a[i][j] * a[j][i] for i in r for j in r))


Fixed submission:
n = int(input())
r = range(1, 10)
a = [[0] * 9 for _ in r]
for i in r:
  if i <= n:
    a[i - 1][i - 1] += 1
for i in r:
  for j in r:
    k = 1
    while 10 * k * i + j <= n:
      a[i - 1][j - 1] += min(k, (n - j) // 10 - k * i + 1)
      k *= 10
print(sum(a[i][j] * a[j][i] for i in range(9) for j in range(9)))
Buggy python submission (verdict: Runtime Error):
from itertools import repeat

n, k, s = map(int, input().split())
print(*repeat(s, k), *repeat((s + 1) % 10**9, n - k))


Fixed submission:
n, k, s = map(int, input().split())
print(*[s] * k + [(s + 1) % 10**9] * (n - k))

Buggy python submission (verdict: Runtime Error):
from itertools import repeat

n, k, s = map(int, input().split())
m = min(n - k + 1, s)
print(*repeat(s, k), *repeat((s + 1) % 10**9, n - k))


Fixed submission:
n, k, s = map(int, input().split())
print(*[s] * k + [(s + 1) % 10**9] * (n - k))
Buggy python submission (verdict: Runtime Error):
print(chr(ord(input()) + 1)

Fixed submission:
print(chr(ord(input()) + 1))
Buggy python submission (verdict: Runtime Error):
from itertools import groupby

r = p = 0
for k, g in groupby(input()):
    r += sum(i for i, _ in enumerate(g, 1))
    if k == '>':
        r -= min(i, p)
    p = i
print(r)


Fixed submission:
from itertools import groupby, chain, islice
 
def pairs(t):
    a = True
    while a:
        a =[sum(1 for _ in g) for k, g in islice(t, 2)]
        if a:
            yield sum(x * (x - 1) // 2 for x in a) + max(a)
 
s = input()
t = groupby(s)
d = [(0, ())]
if s[0] == '>':
    t = chain(d, t)
if s[-1] == '<':
    t = chain(t, d)
print(sum(pairs(t)))
Buggy python submission (verdict: Runtime Error):
from itertools import groupby
from functools import reduce
from operator import xor

s = input()
k = int(input())
r = len(s) * k // 2
a = [reduce(xor, (1 for _ g)) for _, g in groupby(s)]
if len(a) > 1:
  r -= sum(a) * k // 2
  if s[0] == s[-1] and a[0] & a[-1]:
    r += k - 1
print(r)


Fixed submission:
from itertools import groupby

s = input()
k = int(input())
a = [sum(1 for _ in g) for _, g in groupby(s)]
if len(a) == 1:
    print(len(s) * k // 2)
else:
    x, y = a[0], a[-1]
    b = (x + y) // 2 if s[0] == s[-1] else x // 2 + y // 2
    print(x // 2 + y // 2 + sum(x // 2 for x in a[1:-1]) * k + b * (k - 1))

Buggy python submission (verdict: Runtime Error):
from itertools import groupby

s = input()
k = int(input())
a = [sum(1 for _ in g) for _, g in groupby(s)]
if s[0] == s[-1]:
    a[0] += a.pop()
print(sum(x // 2 for x in a) * k)


Fixed submission:
from itertools import groupby

s = input()
k = int(input())
a = [sum(1 for _ in g) for _, g in groupby(s)]
if len(a) == 1:
    print(len(s) * k // 2)
else:
    x, y = a[0], a[-1]
    b = (x + y) // 2 if s[0] == s[-1] else x // 2 + y // 2
    print(x // 2 + y // 2 + sum(x // 2 for x in a[1:-1]) * k + b * (k - 1))
Buggy python submission (verdict: Runtime Error):
from fractions import gcd

d = gcd(*map(int, input().split()))
r = 1
for i in range(2, int(d ** 0.5) + 1):
    if d % i == 0:
        d //= i
        r += 1
    while d % i == 0:
        d //= i
print(r + (d > 1))


Fixed submission:
R = lambda: map(int, input().split())
n, = R()
a = list(R())
print(*sorted(range(1, n + 1), key=lambda x: a[x - 1]))

Buggy python submission (verdict: Runtime Error):
from fractions import gcd
from math import sqrt

d = gcd(*map(int, input().split()))
r = 1
for i in range(2, int(sqrt(d)) + 1):
    if d % i == 0:
        d //= i
        r += 1
    while d % i == 0:
        d //= i
print(r + (d > 1))


Fixed submission:
R = lambda: map(int, input().split())
n, = R()
a = list(R())
print(*sorted(range(1, n + 1), key=lambda x: a[x - 1]))

Buggy python submission (verdict: Runtime Error):
from fractions import gcd

d = gcd(*map(int, input().split()))
r = 1
for i in range(2, int(d ** 0.5) + 1):
    if d % i == 0:
        d //= i
        r += 1
    while d % i == 0:
        d //= i
print(r + (d > 1))


Fixed submission:
R = lambda: map(int, input().split())
n, = R()
a = list(R())
print(*sorted(range(1, n + 1), key=lambda x: a[x - 1]))

Buggy python submission (verdict: Runtime Error):
from fractions import gcd

d = math.gcd(*map(int, input().split()))
r = 1
for i in range(2, int(d ** 0.5) + 1):
    if d % i == 0:
        d //= i
        r += 1
    while d % i == 0:
        d //= i
print(r + (d > 1))


Fixed submission:
R = lambda: map(int, input().split())
n, = R()
a = list(R())
print(*sorted(range(1, n + 1), key=lambda x: a[x - 1]))
Buggy python submission (verdict: Runtime Error):
from fractions import gcd
 
d = gcd(*map(int, input().split()))
r = 1
i = 2
while i * i <= d:
    r += d % i == 0:
    while d % i == 0:
        d //= i
    i += 1
print(r + (d > 1))

Fixed submission:
from fractions import gcd

d = gcd(*map(int, input().split()))
r = 1
i = 2
while i * i <= d:
    if d % i == 0:
        d //= i
        r += 1
    while d % i == 0:
        d //= i
    i += 1
print(r + (d > 1))

Buggy python submission (verdict: Runtime Error):
import math

d = math.gcd(*map(int, input().split()))
r = 1
i = 2
while i * i <= d:
    if d % i == 0:
        d //= i
        r += 1
    while d % i == 0:
        d //= i
    i += 1
print(r + (d > 1))


Fixed submission:
from fractions import gcd

d = gcd(*map(int, input().split()))
r = 1
i = 2
while i * i <= d:
    if d % i == 0:
        d //= i
        r += 1
    while d % i == 0:
        d //= i
    i += 1
print(r + (d > 1))
Buggy python submission (verdict: Time Limit Exceeded):
from heapq import *

R = lambda: map(int, input().split())
n, m = R()
c = [[] for _ in range(m)]
for _ in range(n):
    a, b = R()
    if a <= m:
        heappush(c[m - a], -b)
r=0
for i in range(m - 1, -1, -1):
    if c[i]:
        r -= heappop(c[i])
        if i:
            for x in c[i]:
                heappush(c[i - 1], x)  
print(r)


Fixed submission:
from heapq import *

R = lambda: map(int, input().split())
n, m = R()
c = [[] for _ in range(m)]
for _ in range(n):
    a, b = R()
    if a <= m:
        heappush(c[m - a], -b)
r=0
for i in range(m - 1, -1, -1):
    if c[i]:
        r -= heappop(c[i])
        if i:
            f = len(c[i]) > len(c[i - 1])
            h, g = (c[i], c[i - 1]) if f else (c[i - 1], c[i])
            for x in g:
                heappush(h, x)
            if f:
                c[i - 1] = c[i]       
print(r)

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import *

R = lambda: map(int, input().split())
n, m = R()
c = [[] for _ in range(m)]
for _ in range(n):
    a, b = R()
    if a <= m:
        heappush(c[m - a], -b)
r=0
for i in range(m - 1, -1, -1):
    if c[i]:
        r -= heappop(c[i])
        if i:
            for x in c[i]:
                heappush(c[i - 1], x)  
print(r)


Fixed submission:
from heapq import *

R = lambda: map(int, input().split())
n, m = R()
c = [[] for _ in range(m)]
for _ in range(n):
    a, b = R()
    if a <= m:
        heappush(c[m - a], -b)
r=0
for i in range(m - 1, -1, -1):
    if c[i]:
        r -= heappop(c[i])
        if i:
            f = len(c[i]) > len(c[i - 1])
            h, g = (c[i], c[i - 1]) if f else (c[i - 1], c[i])
            for x in g:
                heappush(h, x)
            if f:
                c[i - 1] = c[i]       
print(r)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for _ in range(n)]
b, c = sorted(a)[-2:]
for i in range(n):
    print(b if a.index(c) == i else c)


Fixed submission:
n = int(input())
a = [int(input()) for _ in range(n)]
b, c = sorted(a)[-2:]
j = a.index(c)
for i in range(n):
    print((c, b)[i == j])
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = input()
r = [None] * (n + 1)
for i in range(n, 0, -1):
    r[i] = (ord(a[2 * i - 1]) + sum(r[i * 2::i])) % 2
print(r.count(1))
print(*(i for i, x in enumerate(r) if x))


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
r = [None] * (n + 1)
for i in range(n, 0, -1):
    r[i] = (a[i - 1] + sum(r[i * 2::i])) % 2
print(r.count(1))
print(*(i for i, x in enumerate(r) if x))