Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03061 (python)

Fixed submission:
from fractions import gcd


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

# l[i] := [0, i]の数のGCDメモ
l = [None for _ in range(N)]
l[0] = A[0]
for i in range(1, N):
    l[i] = gcd(l[i - 1], A[i])

# r[i] := [i, N - 1]の数のGCDメモ
r = [None for _ in range(N)]
r[N - 1] = A[N - 1]
for i in reversed(range(N - 1)):
    r[i] = gcd(r[i + 1], A[i])

ans = 0
for i in range(N):
    if i == 0:
        ans = max(ans, r[1])
    elif i == N - 1:
        ans = max(ans, l[N - 2])
    else:
        ans = max(ans, gcd(l[i - 1], r[i + 1]))
print(ans)

Buggy submission (verdict: Runtime Error):
import math

def solve(N, A):
    max_gcd = 0
    for i in range(N):
        lst = A[0:i]
        lst.extend(A[i + 1: N])
        gcd = lst[0]
        for j in range(1, len(lst)):
            gcd = math.gcd(gcd, lst[j])
        if gcd > max_gcd:
            max_gcd = gcd
    return max_gcd


N = int(input())
A = list(map(int, input().split()))
print(solve(N, A))
Problem p03087 (python)

Fixed submission:
def solve(N, Q, S, L_R):
    memo = [None] * N
    cumsum = 0
    for i in range(len(S) - 1):
        memo[i] = cumsum
        if S[i] == "A" and S[i + 1] == "C":
            cumsum += 1
    memo[N - 1] = cumsum
    for l, r in L_R:
        print(memo[r - 1] - memo[l - 1])


N, Q = map(int, input().split())
S = input()
L_R = [tuple(map(int, input().split())) for _ in range(Q)]
solve(N, Q, S, L_R)

Buggy submission (verdict: Runtime Error):
def solve(N, Q, S, L_R):
    answers = [None] * Q
    ac_index = [0] * len(S)
    for i in range(len(S)):
        s = S[i]
        if s == "A":
            a_flag = True
            continue
        elif s == "C":
            if a_flag:
                ac_index[i - 1] = 1
            a_flag = False
        else:
            a_flag = False
    q = 0
    for l, r in L_R:
        arr = ac_index[l - 1:r]
        ans = sum(arr)
        if arr[-1] == 1:
            ans -= 1
        answers[q] = ans
        q += 1
    return answers

def count_ac(pstr):
    count = 0
    a_flag = False
    for i in range(len(pstr)):
        s = pstr[i]
        if s == "A":
            a_flag = True
            continue
        elif s == "C":
            if a_flag:
                count += 1
            a_flag = False
        else:
            a_flag = False
    return count

N, Q = map(int, input().split())
S = input()
L_R = [tuple(map(int, input().split())) for _ in range(Q)]
for ans in solve(N, Q, S, L_R):
    print(ans)
Problem p03089 (python)

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

ans = list()
for k in reversed(range(N)):
    hit = False
    for l in reversed(range(1, k + 2)):
        if B[l - 1] == l:
            B = B[:l - 1] + B[l:]
            hit = True
            ans.append(l)
            break
    if not hit:
        print(-1)
        exit(0)

for e in reversed(ans):
    print(e)

Buggy submission (verdict: Runtime Error):
def solve(N, b):
    for i in range(N):
        if b[i] > i + 1:
            return -1
    ans = [None for _ in range(N)]
    for i in reversed(range(N)):
        min_j = b[i]
        max_j = N + b[i] - i - 1
        for j in reversed(range(min_j - 1, max_j)):
            if not ans[j]:
                ans[j] = b[i]
                break
    return ans


N = int(input())
b = list(map(int, input().split()))

for i in solve(N, b):
    print(i)
Problem p03128 (python)

Fixed submission:
from math import isinf

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)

m = [None, 2, 5, 5, 4, 5, 6, 3, 7, 6]

# 最大何桁作れるか

# dp[i] := ちょうど i 本のマッチ棒を使って、条件を満たす整数を作るときの最大桁数
# dp[i + 1] = max(dp[i - m[j]] + 1) for all j in A

dp = [float('-inf') for _ in range(N + 1)]
dp[0] = 0

for i in range(1, N + 1):
    for num in A:
        if i - m[num] >= 0:
            dp[i] = max(dp[i], dp[i - m[num]] + 1)

matches = N
ans = ''
for _ in range(dp[N]):
    for a in A:
        if matches - m[a] < 0:
            continue
        if dp[matches - m[a]] == dp[matches] - 1:
            matches -= m[a]
            ans += str(a)
            break

print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)

m = [None, 2, 5, 5, 4, 5, 6, 3, 7, 6]

# 最大何桁作れるか

# dp[i] := ちょうど i 本のマッチ棒を使って、条件を満たす整数を作るときの最大桁数
# dp[i + 1] = max(dp[i - m[j]] + 1) for all j in A

dp = [float('-inf') for _ in range(N + 1)]
dp[0] = 0

for i in range(1, N + 1):
    for num in A:
        if i - m[num] >= 0:
            dp[i] = max(dp[i], dp[i - m[num]] + 1)

matches = N
ans = ''
for _ in range(dp[N]):
    for a in A:
        if dp[matches - m[a]] == dp[matches] - 1:
            matches -= m[a]
            ans += str(a)
            break

print(ans)
Problem p03294 (python)

Fixed submission:
from fractions import gcd


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


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

cumlcm = A[0]
for a in A[1:]:
    cumlcm = lcm(cumlcm, a)
m = cumlcm - 1
f = sum(map(lambda a: m % a, A))
print(f)

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


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


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

cumlcm = A[0]
for a in A[1:]:
    cumlcm = lcm(cumlcm, a)
m = cumlcm - 1
f = sum(map(lambda a: m % a if a != 0 else m, A))
print(f)

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


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


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

cumlcm = A[0]
for a in A[1:]:
    cumlcm = lcm(cumlcm, a)
m = cumlcm - 1
f = sum(map(lambda a: m % a, A))
print(f)
Problem p03450 (python)

Fixed submission:
import sys
sys.setrecursionlimit(300000)

N, M = map(int, input().split())
nl = [[] for _ in range(N + 1)]
for _ in range(M):
    L, R, D = map(int, input().split())
    nl[L].append((R, D))
    nl[R].append((L, -D))

seen = [None for _ in range(N + 1)]


def dfs(v, d):
    seen[v] = d
    for next_v, D in nl[v]:
        next_d = d + D
        if seen[next_v] is None:
            dfs(next_v, next_d)
        else:
            if seen[next_v] != next_d:
                print('No')
                exit(0)


for v in range(1, N + 1):  # すべての連結成分に対してDFS
    if seen[v] is None:
        dfs(v, 0)

print('Yes')

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
nl = [[] for _ in range(N + 1)]
for _ in range(M):
    L, R, D = map(int, input().split())
    nl[L].append((R, D))
    nl[R].append((L, -D))

seen = [None for _ in range(N + 1)]


def dfs(v, d):
    seen[v] = d
    for next_v, D in nl[v]:
        next_d = d + D
        if seen[next_v] is None:
            dfs(next_v, next_d)
        else:
            if seen[next_v] != next_d:
                print('No')
                exit(0)


for v in range(1, N + 1):  # すべての連結成分に対してDFS
    if seen[v] is None:
        dfs(v, 0)

print('Yes')
Problem p03488 (python)

Fixed submission:
from collections import defaultdict

s = input()
x, y = map(int, input().split())

arr = list(map(len, s.split('T')))
EW = [arr[ew] for ew in range(0, len(arr), 2)]
NS = [arr[ns] for ns in range(1, len(arr), 2)]

# dp[i][j] := i回目までの移動で座標jにいることができるか
dp = [defaultdict(bool) for i in range(len(EW))]
dp[0][EW[0]] = True
for i in range(1, len(EW)):
    for prev in dp[i - 1].keys():
        dp[i][prev + EW[i]] = True
        dp[i][prev - EW[i]] = True
if not dp[-1][x]:
    print('No')
    exit(0)

if len(NS) > 0:
    dp = [defaultdict(bool) for i in range(len(NS))]
    dp[0][NS[0]] = True
    dp[0][-NS[0]] = True
    for i in range(1, len(NS)):
        for prev in dp[i - 1].keys():
            dp[i][prev + NS[i]] = True
            dp[i][prev - NS[i]] = True
    if not dp[-1][y]:
        print('No')
        exit(0)

print('Yes')

Buggy submission (verdict: Runtime Error):
from collections import defaultdict

s = input()
x, y = map(int, input().split())

arr = list(map(len, s.split('T')))
EW = [arr[ew] for ew in range(0, len(arr), 2)]
NS = [arr[ns] for ns in range(1, len(arr), 2)]

# dp[i][j] := i回目までの移動で座標jにいることができるか
dp = [defaultdict(bool) for i in range(len(EW))]
dp[0][EW[0]] = True
for i in range(1, len(EW)):
    for prev in dp[i - 1].keys():
        dp[i][prev + EW[i]] = True
        dp[i][prev - EW[i]] = True
if not dp[-1][x]:
    print('No')
    exit(0)

dp = [defaultdict(bool) for i in range(len(NS))]
dp[0][NS[0]] = True
dp[0][-NS[0]] = True
for i in range(1, len(NS)):
    for prev in dp[i - 1].keys():
        dp[i][prev + NS[i]] = True
        dp[i][prev - NS[i]] = True
if not dp[-1][y]:
    print('No')
    exit(0)

print('Yes')
Problem p03695 (python)

Fixed submission:
import numpy as np

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

colors = np.array([0 for _ in range(9)])
for a in A:
    if 1 <= a <= 399: colors[0] += 1
    elif 400 <= a <= 799: colors[1] += 1
    elif 800 <= a <= 1199: colors[2] += 1
    elif 1200 <= a <= 1599: colors[3] += 1
    elif 1600 <= a <= 1999: colors[4] += 1
    elif 2000 <= a <= 2399: colors[5] += 1
    elif 2400 <= a <= 2799: colors[6] += 1
    elif 2800 <= a <= 3199: colors[7] += 1
    else: colors[8] += 1

if colors[8] == 0:
    ans = len(colors[colors > 0])
    print(ans, ans)
else:
    legend = colors[8]
    colors = colors[:8]
    v = len(colors[colors > 0])
    print(max(1, v), v + legend)

Buggy submission (verdict: Runtime Error):
import numpy as np

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

colors = np.array([0 for _ in range(9)])
for a in A:
    if 1 <= a <= 399: colors[0] += 1
    elif 400 <= a <= 799: colors[1] += 1
    elif 800 <= a <= 1199: colors[2] += 1
    elif 1200 <= a <= 1599: colors[3] += 1
    elif 1600 <= a <= 1999: colors[4] += 1
    elif 2000 <= a <= 2399: colors[5] += 1
    elif 2400 <= a <= 2799: colors[6] += 1
    elif 2800 <= a <= 3199: colors[7] += 1
    else: colors[8] += 1

if colors[8] == 0:
    ans = len(colors[colors > 0])
    print(ans, ans)
else:
    legend = colors[8]
    colors = colors[:8]
    v = len(colors[colors > 0])
    print(max(1, v), v + min(legend, 8 - v))
Problem p04013 (python)

Fixed submission:
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7

N, A = MI()
X = LMI()

# dp[i][j][s] := i番目までのカードからj枚を選んで合計がsになる組み合わせの数
dp = [[[0] * 2502 for _ in range(N + 2)] for _ in range(N + 1)]
for i in range(N):
    dp[i][0][0] = 1
dp[0][1][X[0]] = 1
for i in range(1, N):
    for j in range(1, i + 2):
        for s in range(A * N + 1):
            if s - X[i] < 0:
                dp[i][j][s] = dp[i - 1][j][s]
            else:
                dp[i][j][s] = dp[i - 1][j][s] + dp[i - 1][j - 1][s - X[i]]

ans = 0
for i in range(1, N + 1):
    ans += dp[N - 1][i][A * i]
print(ans)

Buggy submission (verdict: Runtime Error):
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7

N, A = MI()
X = LMI()

# dp[i][j][s] := i番目までのカードからj枚を選んで合計がsになる組み合わせの数
dp = [[[0] * (A * N + 1) for _ in range(N + 1)] for _ in range(N)]
for i in range(N):
    dp[i][0][0] = 1
dp[0][1][X[0]] = 1
for i in range(1, N):
    for j in range(1, i + 2):
        for s in range(A * N + 1):
            if s - X[i] < 0:
                dp[i][j][s] = dp[i - 1][j][s]
            else:
                dp[i][j][s] = dp[i - 1][j][s] + dp[i - 1][j - 1][s - X[i]]

ans = 0
for i in range(1, N + 1):
    ans += dp[N - 1][i][A * i]
print(ans)

Buggy submission (verdict: Runtime Error):
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7

N, A = MI()
X = LMI()
mx = max(X)

# dp[i][j][s] := i番目までのカードからj枚を選んで合計がsになる組み合わせの数
dp = [[[0] * (N * mx + 1) for _ in range(N + 1)] for _ in range(N)]
for i in range(N):
    dp[i][0][0] = 1
dp[0][1][X[0]] = 1
for i in range(N):
    for j in range(1, i + 2):
        for s in range(N * mx + 1):
            dp[i][j][s] = dp[i - 1][j][s] + dp[i - 1][j - 1][s - X[i]]

ans = 0
for i in range(1, N + 1):
    ans += dp[N - 1][i][A * i]
print(ans)
Problem p03147 (python)

Fixed submission:
n = int(input())
h = list(map(int, input().split()))
 
ans = h[0]
for i in range(1, n):
  d = h[i] - h[i-1]
  if d > 0:
    ans += d
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
h = map(int, input().split())

ans = 0
for i in range(1, n):
  d = h[i] - h[i-1]
  if d > 0:
    ans += d
print(ans)
Problem p03469 (python)

Fixed submission:
n = input().split('/')
n[0] = str(int(n[0]) + 1)

print('/'.join(n))

Buggy submission (verdict: Runtime Error):
n, y = map(int, input().split())

a = 0
b = 0
c = n
ans = c * 1000

while ans < y:
    if y - ans >= 9000:
        tmp = (y - ans) // 9000
        a += tmp
        c -= tmp
    elif y - ans >= 4000:
        tmp = (y - ans) // 4000
        b += tmp
        c -= tmp
    ans = a * 10000 + b * 5000 + c * 1000

if ans != y:
    a = b = c = -1

print(a, b, c)
Problem p03471 (python)

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

a, b, c = (-1, -1, -1)
for i in range(n + 1):
  for j in range(n + 1 - i):
    k = n - (i + j)
    if 10000 * i + 5000 * j + 1000 * k == y:
      a, b, c = (i, j, k)
      break
print(a, b, c)

Buggy submission (verdict: Runtime Error):
n, y = map(int, input().split())

a = y // 10000
b = (y - a * 10000) // 5000
c = (y - a * 10000 - b * 5000) // 1000
n = a + b + c

while ans != y:
    if y - ans >= 9000:
        tmp = (y - ans) // 9000
        a += tmp
        c -= tmp
    elif y - ans >= 4000:
        tmp = (y - ans) // 4000
        b += tmp
        c -= tmp
    ans = a * 10000 + b * 5000 + c * 1000

if ans != y:
    a = b = c = -1

print(a, b, c)
Problem p03485 (python)

Fixed submission:
# -*- coding: utf-8 -*-
 
import math
 
l = list(map(int, input().split()))
print(math.ceil((l[0] + l[1])/2))

Buggy submission (verdict: Runtime Error):
-*- coding: utf-8 -*-
 
import math
 
l = rawinput().split()
print(math.ceil(l[0] + l[1])

Buggy submission (verdict: Runtime Error):
-*- coding: utf-8 -*-
 
import math
 
l = raw_input().split()
print(math.ceil(l[0] + l[1])

Buggy submission (verdict: Runtime Error):
-*- coding: utf-8 -*-

import math

l = rawinput().split()
print(math.ceil(l[0] + l[1])
Problem p03611 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))

count = {}
for ai in a:
  count[ai] = count.get(ai, 0) + 1

ans = 0
for key in count.keys():
  ans = max(ans, count.get(key - 1, 0) + count.get(key) + count.get(key + 1, 0))
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

count = {}
for ai in a:
  count[ai] = count.get(ai, 0) + 1

ans = 0
for key in count.keys():
  ans = max(ans, count.get(key - 1) + count.get(key) + count.get(key + 1))
print(ans)
Problem p02582 (python)

Fixed submission:
s = input().strip()
res, tmp = 0, 0

for c in s:
    if c == 'R':
        tmp += 1
        res = max(res, tmp)
    else:
        tmp = 0

print(res)

Buggy submission (verdict: Runtime Error):
res, tmp = 0, 0
for c in s:
    if c == 'R':
        tmp += 1
        res = max(res, tmp)
    else:
        tmp = 0

print(res)
Problem p02582 (python)

Fixed submission:
S = input()

if "RRR" in S:
  print(3)
elif "RR" in S:
  print(2)
elif "R" in S:
  print(1)
else:
  print(0)

Buggy submission (verdict: Runtime Error):
S = input()

if "RRR" in S:
  print(3)
else "RR" in S:
  print(2)
else "R" in S:
  print(1)
else:
  print(0)
Problem p02606 (python)

Fixed submission:
L,R,d = map(int,input().split())

cnt=0
for i in range(L,R+1):
    if i%d==0:
        cnt+=1
print(cnt)

Buggy submission (verdict: Runtime Error):
n = int(input())
cnt  = [0 for i in range(10001)]

for x in range(1,105):
    for y in range(1, 105):
        for z in range(1, 105):
                ans = x**2 + y**2 + z**2 + x*y + y*z + z*x 
                if ans <= 10000:    
                    cnt[ans] +=1
for i in range(1, N+1):  
    print(cnt[i])
Problem p02608 (python)

Fixed submission:
n = int(input())
ans = [0 for _ in range(10050)]
for i in range(1,105):
    for j in range(1,105):
        for k in range(1,105):
            v = i*i+j*j+k*k+i*j+j*k+k*i;
            if v<10050:
                ans[v]+=1
for i in range(n):
    print(ans[i+1])

Buggy submission (verdict: Runtime Error):
n = int(input())
cnt  = [0 for i in range(10001)]

for x in range(1,101):
    for y in range(1, 105):
        for z in range(1, 105):
            ans = x**2 + y**2 + z**2 + x*y + y*z + z*x 
            if ans <= 10000:    
                cnt[ans] +=1
for i in range(1, N+1):  
    print(cnt[i])

Buggy submission (verdict: Runtime Error):
n = int(input())
cnt  = [0 for i in range(10001)]

for x in range(1,101):
    for y in range(1, 105):
        for z in range(1, 105):
            ans = x**2 + y**2 + z**2 + x*y + y*z + z*x 
            if ans <= 10000:    
                cnt[ans] +=1
for i in range(1, N+1):  
    print(cnt[i])

Buggy submission (verdict: Runtime Error):
n = int(input())
cnt  = [0 for i in range(10001)]

for x in range(1,105):
    for y in range(1, 105):
        for z in range(1, 105):
                ans = x**2 + y**2 + z**2 + x*y + y*z + z*x 
                if ans <= 10000:    
                    cnt[ans] +=1
for i in range(1, N+1):  
    print(cnt[i])

Buggy submission (verdict: Runtime Error):
n = int(input())
cnt  = [0 for i in range(10001)]

for x in range(1,105):
    for y in range(1, 105):
        for z in range(1, 105):
                ans = x**2 + y**2 + z**2 + x*y + y*z + z*x 
                if ans <= 10000:    
                    cnt[ans] +=1
for i in range(1, N+1):  
    print(cnt[i])
Problem p02628 (python)

Fixed submission:
N, K = map(int, input().split())
p = list(map(int, input().split()))
print(sum(sorted(p)[:K]))

Buggy submission (verdict: Runtime Error):
import itertools
prod = functools.partial(functools.reduce, operator.mul)
n,k=map(int,input().split())
price=list(map(int,input().split()))

n_list=[]
for com in itertools.combinations(price,k):
    s=sum(com)
    n_list.append(s)
print(min(n_list))
Problem p02639 (python)

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

if var[0]==0:
    print(1)
elif var[1]==0:
    print(2)
elif var[2]==0:
    print(3)
elif var[3]==0:
    print(4)
elif var[4]==0:
    print(5)

Buggy submission (verdict: Runtime Error):
X,Y=map(int,input().split())

if 2*X<Y<4*X and (Y-2*X)%2==0 and (4*X-Y)%2==0:
    print("Yes")
elif (4*X-Y)/2==1 and (Y-2*X)/2==0:
    print("Yes")
elif (4*X-Y)/2==0 and (Y-2*X)/2==1:
    print("Yes")
else:
    print("No")
Problem p02657 (python)

Fixed submission:
a, b = map(int,input().split())

print(a*b)

Buggy submission (verdict: Runtime Error):
import functools
import operator
n = int(input())
number = map(int,input().split())
X = functools.partial(functools.reduce, operator.mul)
s=X(number)
if s>=pow(10,18):
    print(-1)
else:
    print(s)
Problem p03494 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
cnt = 0

while True:
   if [i for i in a if i % 2 == 1]:
       break
   a = [i/2 for i in a]
   cnt += 1

print(cnt)

Buggy submission (verdict: Runtime Error):
n=input()
n_list=list(map(int,input().split()))

counter=0
while all(i%2==0 for i in n_list):
     n_list=[i/2 for i in n_list]

    #n_list=[i/2 for i in n_list]
    counter=+1
print(counter)
Problem p02584 (python)

Fixed submission:
x,k,d = input().split()
x = int(x)
k = int(k)
d = int(d)
ans = 0
if abs(x) >= abs(k*d):
    ans =  abs(x) - abs(k*d)
else:
    kaisuu = int(abs(x)/d)
    k_2 = k - kaisuu
    if k_2%2 == 0:
        ans = abs(x) - d*kaisuu 
    else:
        ans = abs((abs(x) - d*kaisuu) - abs(d))
print(int(ans))

Buggy submission (verdict: Runtime Error):
x,k,d = input().split()
ans = 0
if abs(x) > abs(k*d):
    ans =  abs(x) - abs(k*d)
else:
    kaisuu = abs(x)/d 
    k_2 = k - kaisuu
    if k_2/2 == 2:
        ans = abs(x) - d*kaisuu 
    else:
        ans = (abs(x) - d*kaisuu) - d
print(ans)
Problem p02606 (python)

Fixed submission:
l,r,d = map(int,input().split())
a = (l-1)//d
b = r//d
print(b-a)

Buggy submission (verdict: Runtime Error):
from heapq import *

def solve(p:list):
    s = 0
    n = len(p)
    data = [[] for _ in range(n+1)]
    for i,j in p:
        data[min(i,n)].append(j)
    H = []
    heapify(H)
    for i in range(n,0,-1):
        for j in data[i]:
            heappush(H,-j)
        if H:
            s -= heappop(H)
    return s
    
t = int(input())
for _ in range(t):
    n = int(input())
    ans = 0
    pl = []
    pr = []
    for _ in range(n):
        k,l,r = map(int,input().split())
        m = min(l,r)
        ans += m
        l,r = l-m,r-m
        if l:
            pl.append((k,l))
        else:
            pr.append((n-k,r))
    print(ans+solve(pl)+solve(pr))
Problem p02618 (python)

Fixed submission:
import random
for i in range(365):
    print(random.randint(1,26))

Buggy submission (verdict: Runtime Error):
d = int(input())
c = list(map(int,input().split()))
data = [0]*(26)
ans = 0
for i in range(1,d+1):
    s = list(map(int,input().split()))
    L = []
    for j in range(26):
        out,ind = -float("inf"),-1
        sub = s[j]
        for k in range(26):
            if j == k:
                continue
            sub -= c[k]*(i-data[k])
        L.append(sub)
    out = L.index(max(L))+1
    print(out)
    data[out] = i
Problem p02640 (python)

Fixed submission:
x,y = map(int,input().split())
if y % 2 != 0:
    print("No")
    exit()
a = y//2-x
b = 2*x-y//2
if a >= 0 and b >= 0:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
from itertools import accumulate
from collections import Counter
n = int(input())
T = []
for _ in range(n):
    T.append(int(input()))
T.sort()
print(sum(accumulate(T)))
dic = Counter(T)
ans = 1
mod = 10**9+7
for i in dic.values():
    for j in range(1,i+1):
        ans *= j
        ans %= mod
print(ans)
Problem p02642 (python)

Fixed submission:
n = int(input())
search = list(map(int,input().split()))
search.sort()
double = set([])
for i in range(n-1):
    if search[i+1] == search[i]:
        double.add(search[i])
dp = [1]*(search[-1]+1)
for i in search:
    if not dp[i]:
        continue
    if i in double:
        dp[i] = 0
    k = 2*i
    while k <= search[-1]:
        dp[k] = 0
        k += i
print(sum((dp[i] for i in search)))

Buggy submission (verdict: Runtime Error):
n = int(input())
search = list(map(int,input().split()))
search.sort()
dp = [1]*(search[-1]+1)
if search[0] == 1:
    if search[1] != 1:
        print(1)
    else:
        print(0)
else:
    for i in search:
        k = 2*i
        while k <= search[-1]:
            if dp[k]:
                dp[k] = 0
                k += i
            else:
                break
    ans = 0
    flag = False
    j = -1
    for i in search:
        if flag:
            if i != j:
                flag = False
                ans -= dp[j]
        else:
            if i == j:
                flag = True
            else:
                ans += dp[i]
                j = i
    
print(ans-dp[search[-1]] if flag else ans)