Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
h, n = [int(i) for i in input().split()]
a, b = [0]*n, [0]*n

eff = 0
eff_index = 0
for i in range(n):
    a[i], b[i] = [int(_) for _ in input().split()]
    if eff < a[i]/b[i]:
        eff = a[i]/b[i]
        eff_index = i

max_kaisuu = - (-h//a[eff_index])

ans = float('inf')
H = max_kaisuu * b[eff_index]
dp = [[0] * (H+1) for _ in range(n+1)]
# dp[i][j] i番目までの魔法で消費魔力がjを超えないように選んだときのダメージの最大値
for i in range(n):
    for j in range(H+1):
        if j < b[i]:# i番目の魔法消費b[i]がjを超えているので，入れる可能性がない

            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j], dp[i+1][j-b[i]]+a[i])# 入れ場合と入れない場合を比較

        if dp[i+1][j] >= h:
            ans = min(ans, j)
            H = j
            continue
print(ans)


Fixed submission:
h, n = [int(i) for i in input().split()]
a, b = [0]*n, [0]*n

eff = 0
eff_index = 0
for i in range(n):
    a[i], b[i] = [int(_) for _ in input().split()]

max_a = max(a)

ans = float('inf')
H = h + max_a
dp = [float('inf')] * (H+1)
# dp[i] iのダメージを与える最小消費魔力
dp[0] = 0
for i in range(H+1):
    for j in range(n):
        if i >= a[j]:
            dp[i] = min(dp[i], dp[i-a[j]]+b[j])

    if i >= h:
        ans = min(ans, dp[i])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
h, n = [int(i) for i in input().split()]
a, b = [0]*n, [0]*n

eff = 0
eff_index = 0
for i in range(n):
    a[i], b[i] = [int(_) for _ in input().split()]
    if eff < a[i]/b[i]:
        eff = a[i]/b[i]
        eff_index = i

max_kaisuu = - (-h//a[eff_index])

ans = float('inf')
H = max_kaisuu * b[eff_index]
dp = [[0] * (H+1) for _ in range(n+1)]
# dp[i][j] i番目までの魔法で消費魔力がjを超えないように選んだときのダメージの最大値
for i in range(n):
    for j in range(H+1):
        if j < b[i]:# i番目の魔法消費b[i]がjを超えているので，入れる可能性がない

            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j], dp[i+1][j-b[i]]+a[i])# 入れ場合と入れない場合を比較

        if dp[i+1][j] >= h:
            ans = min(ans, j)
            continue
print(ans)


Fixed submission:
h, n = [int(i) for i in input().split()]
a, b = [0]*n, [0]*n

eff = 0
eff_index = 0
for i in range(n):
    a[i], b[i] = [int(_) for _ in input().split()]

max_a = max(a)

ans = float('inf')
H = h + max_a
dp = [float('inf')] * (H+1)
# dp[i] iのダメージを与える最小消費魔力
dp[0] = 0
for i in range(H+1):
    for j in range(n):
        if i >= a[j]:
            dp[i] = min(dp[i], dp[i-a[j]]+b[j])

    if i >= h:
        ans = min(ans, dp[i])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

ans = 0

table = [[0]*10 for _ in range(10)]

for i in range(1,10):
    for j in range(1, 10):
        number = 1
        while number <= n:
            n_str = str(number)
            if int(n_str[0]) == i and int(n_str[-1]) == j:
                table[i][j] += 1
            number += 1

for i in range(1,10):
    for j in range(1, 10):
        ans += table[j][i] * table[i][j]
print(ans)






Fixed submission:
n = int(input())

ans = 0

table = [[0]*10 for _ in range(10)]

for number in range(1, n+1):
    i = int(str(number)[0])
    j = int(str(number)[-1])
    table[i][j] += 1

for i in range(1,10):
    for j in range(1, 10):
        ans += table[j][i] * table[i][j]
print(ans)
Buggy python submission (verdict: Runtime Error):
n,m,v,p = map(int, input().split())
a = list( map(int, input().split()))

a.sort(reverse=True)
# a = np.array(a)

def isok(i):

    if i <= (p-1):
        return True

    points = a.copy()

    points[i] += m

    adding_point = m*v-m*p

    if points[i] < points[p-1]:
        return False

    j = n-1
    while adding_point > 0:

        if j <= p-2:
            return False

        if i == j:
            j -= 1
            continue
        adding_point -= min(m, points[i]- points[j])

        j -= 1

    return True

if isok(n-1):
    print(n)
    exit()

ok = p-1
ng = n-1

while ng - ok > 1:
    mid = (ok+ng)//2

    if isok(mid):
        ok = mid
    else:
        ng = mid
print(ok+1)



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

a.sort(reverse=True)

def isok(i):

    if i <= (p-1):
        return True

    points = a.copy()

    points[i] += m

    adding_point = m*v-m*p

    if points[i] < points[p-1]:
        return False

    j = n-1
    while adding_point > 0:

        if j <= p-2:
            return False

        if i == j:
            j -= 1
            continue
        adding_point -= min(m, points[i]- points[j])

        j -= 1

    return True

if isok(n-1):
    print(n)
    exit()

ok = p-1
ng = n-1

while ng - ok > 1:
    mid = (ok+ng)//2

    if isok(mid):
        ok = mid
    else:
        ng = mid
print(ok+1)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n,m,v,p = map(int, input().split())
a = list( map(int, input().split()))

a.sort(reverse=True)
a = np.array(a)

def isok(i):

    if i <= (p-1):
        return True

    points = a.copy()

    points[i] += m
    points[:(p-1)] += m

    adding_point = m*v-m*p

    if points[i] < points[p-1]:
        return False

    j = n-1
    # okflag = True
    while adding_point > 0:

        if j <= p-2:
            return False

        if i == j:
            j -= 1
            continue
        adding_point -= min(m, points[i]- points[j])

        j -= 1

    return True

if isok(n-1):
    print(n)
    exit()

ok = p-1
ng = n-1

while ng - ok > 1:
    mid = (ok+ng)//2

    if isok(mid):
        ok = mid
    else:
        ng = mid
print(ok+1)


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

a.sort(reverse=True)

def isok(i):

    if i <= (p-1):
        return True

    points = a.copy()

    points[i] += m

    adding_point = m*v-m*p

    if points[i] < points[p-1]:
        return False

    j = n-1
    while adding_point > 0:

        if j <= p-2:
            return False

        if i == j:
            j -= 1
            continue
        adding_point -= min(m, points[i]- points[j])

        j -= 1

    return True

if isok(n-1):
    print(n)
    exit()

ok = p-1
ng = n-1

while ng - ok > 1:
    mid = (ok+ng)//2

    if isok(mid):
        ok = mid
    else:
        ng = mid
print(ok+1)
Buggy python submission (verdict: Runtime Error):
import math

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

print( (a * b) // math.gcd(a, b))

Fixed submission:
import fractions

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

print( (a * b) // fractions.gcd(a, b))
Buggy python submission (verdict: Runtime Error):
import numpy as np

n = int(input())

if n % 2 != 0:
    print(0)
    exit()

logtenN = int(np.log10(n))


ans = 0
for i in range(1,logtenN+1):
    add10 = n//(10**i)
    ans += add10
    logfiveAddTen = int(np.log10(add10)/np.log10(5))
    for j in range(1,logfiveAddTen):
        add5 = (add10//(5**j))//2
        ans += add5

print(ans)


Fixed submission:
n = int(input())
ans = 0
if n % 2 != 0:
    print(0)
    exit()
denominator = 10
while n >= denominator:
    ans += n//denominator
    denominator *= 5

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n = int(input())
table = np.array([[-1]*n for _ in range(n)]) # 証言がないやつはとりあえず-1入れとくか

for i_speaker in range(n):
    ai = int(input())
    for _ in range(ai):
        xij, yij= map(int, input().split())
        table[i_speaker][xij-1] = yij

ans = 0
for i in range(2**n):
    isConflict = False

    for j_speaker in range(n): # それぞれの桁について0か1かを判断したいので
        if (i >> j_speaker) & 1 == 0: # j桁目が1かどうかをジャッジ
            continue

        for k_target in range(n):
            if table[j_speaker][k_target] != -1 and table[j_speaker][k_target] != ((i >> k_target) & 1) :
                isConflict = True
                break

        if isConflict:
            break
    if isConflict == False:
        ans = max(ans, bin(i).count("1"))


print(ans)


Fixed submission:
n = int(input())
testimony_table = [[] for _ in range(n)]

for i_witness in range(n):
    ai = int(input())
    for _ in range(ai):
        xij, yij= map(int, input().split())
        testimony_table[i_witness].append((xij-1,yij))

ans = 0
for i in range(2**n):
    isConflict = False

    for j_witness in range(n): # それぞれの桁について0か1かを判断したいので
        if (i >> j_witness) & 1 == 0: # j桁目が1かどうかをジャッジ
            continue


        for x_suspect, y_testimony in testimony_table[j_witness]:
            if ((i >> x_suspect) & 1) != y_testimony:
                isConflict = True
                break

        if isConflict:
            break
    if isConflict == False:
        ans = max(ans, bin(i).count("1"))

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list( map(int, input().split()))
p = 10**9+7

len_max = len(list(format(max(a), 'b')))

bin_list = [0]*len_max

for a_ in a:
    for i in range(1,len_max+1):
        if a_ & (1<<(i-1)):
            bin_list[-i] += 1

ans = 0
for i in range(1,len_max+1):
    num_1 = bin_list[-i]%p
    ans += 2**(i-1)%p * num_1 * (n-num_1)%p

print(ans%p)

Fixed submission:
n = int(input())
a = list( map(int, input().split()))
p = 10**9+7

len_max = len(list(format(max(a), 'b')))

bin_list = [0]*len_max

for a_ in a:
    for i in range(1,len_max+1):
        if a_ & (1<<(i-1)):
            bin_list[-i] += 1

ans = 0
for i in range(1,len_max+1):
    num_1 = bin_list[-i]%p
    ans += 2**(i-1)%p * num_1 * (n-num_1)%p

print(ans%p)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list( map(int, input().split()))
p = 10**9+7

len_max = len(list(format(max(a), 'b')))

bin_list = [0]*len_max

def python_list_add(in1, in2):
    return [a + b for a, b in zip(in1, in2)]

for a_ in a:
    a_bin = list(map(int ,list(format(a_,'b').zfill(len_max))))
    bin_list = python_list_add(bin_list, a_bin)


ans = 0
for i in range(1,len_max+1):
    num_1 = bin_list[-i]%p
    ans += 2**(i-1)%p * num_1 * (n-num_1)%p

print(ans%p)


Fixed submission:
n = int(input())
a = list( map(int, input().split()))
p = 10**9+7

len_max = len(list(format(max(a), 'b')))

bin_list = [0]*len_max

for a_ in a:
    for i in range(1,len_max+1):
        if a_ & (1<<(i-1)):
            bin_list[-i] += 1

ans = 0
for i in range(1,len_max+1):
    num_1 = bin_list[-i]%p
    ans += 2**(i-1)%p * num_1 * (n-num_1)%p

print(ans%p)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n = int(input())
a = list( map(int, input().split()))
p = 10**9+7

len_max = len(list(format(max(a), 'b')))

bin_list = np.array([0]*len_max)

for a_ in a:
    a_bin = np.array( list(map(int ,list(format(a_,'b').zfill(len_max)))))
    bin_list += a_bin


ans = 0
for i in range(1,len_max+1):
    num_1 = bin_list[-i]%p
    ans += 2**(i-1)%p * num_1 * (n-num_1)%p

print(ans%p)

Fixed submission:
n = int(input())
a = list( map(int, input().split()))
p = 10**9+7

len_max = len(list(format(max(a), 'b')))

bin_list = [0]*len_max

for a_ in a:
    for i in range(1,len_max+1):
        if a_ & (1<<(i-1)):
            bin_list[-i] += 1

ans = 0
for i in range(1,len_max+1):
    num_1 = bin_list[-i]%p
    ans += 2**(i-1)%p * num_1 * (n-num_1)%p

print(ans%p)
Buggy python submission (verdict: Runtime Error):
x = int(input())

shimo2 = int(str(x)[-2:])
ue = int(str(x)[:-2])

nums = [0]*6

for i in [5,4,3,2,1]:
    nums[i] = shimo2//i
    shimo2 -= nums[i]*i

if ue >= sum(nums):
    print(1)
else:
    print(0)

Fixed submission:
x = int(input())

if x < 100:
    print(0)
    exit()

shimo2 = int(str(x)[-2:])
ue = int(str(x)[:-2])

nums = [0]*6

for i in [5,4,3,2,1]:
    nums[i] = shimo2//i
    shimo2 -= nums[i]*i


if ue >= sum(nums):
    print(1)
else:
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):
import math
MOD = 10**9 + 7 #　素数
x, y = map(int, input().split())

if (x+y)%3 != 0:
    print(0)
    exit()

if x == 0 or y == 0:
    print(0)
    exit()

X = max(x,y)
Y = min(x,y)

all_move = (X+Y)//3
diff = (X-Y)
Y_move = (all_move - diff)//2

def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

def inv_mod(a,mod):
    x = extgcd(a,mod)[0]
    return (mod+x%mod)%mod

def cmb_mod_p(n, r, mod): # nCr mod p
    if n<0 or r<0 or n<r:
        return 0

    res = 1
    for i in range(1,n+1):
        res = res*i%mod
    for i in range(1,r+1):
        res = res*inv_mod(i,mod)%mod
    for i in range(1,n-r+1):
        res = res*inv_mod(i,mod)%mod

    return res

print(cmb_mod_p(all_move, Y_move,MOD))



Fixed submission:
import math
mod = 10**9 + 7
x, y = map(int, input().split())

if (x+y)%3 != 0:
    print(0)
    exit()

if x == 0 or y == 0:
    print(0)
    exit()

X = max(x,y)
Y = min(x,y)

all_move = (X+Y)//3
diff = (X-Y)
y_move = (all_move - diff)//2


def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

n = int(all_move)
r = int(y_move)
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, n + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


print(cmb(n,r,mod))
Buggy python submission (verdict: Time Limit Exceeded):
n, t = [int(i) for i in input().split()]
dishes = []
for _ in range(n):
    a, b = map(int, input().split())
    dishes.append((a, b))

dishes = sorted(dishes, key=lambda x: x[0])

dp = [[0] * t for _ in range(n+1)]

ans = 0

for i in range(n):
    for j in range(t):
        if j < dishes[i][0] :
            dp[i+1][j] = dp[i][j]
        else:
            if dp[i][j] > dp[i][j-dishes[i][0]]+dishes[i][1]:
                dp[i+1][j] = dp[i][j]
            else:
                dp[i+1][j] = dp[i][j-dishes[i][0]]+dishes[i][1]
    ans_i = dp[i][t-1] + max( dishes[i:], key=lambda x: x[1])[1]
    ans = max(ans, ans_i)

print(ans)

Fixed submission:
n, t = [int(i) for i in input().split()]
dishes = []
for _ in range(n):
    a, b = map(int, input().split())
    dishes.append((a, b))

dishes = sorted(dishes, key=lambda x: x[0])

dp = [[0] * t for _ in range(n+1)]

ans = 0

for i in range(n):
    for j in range(t):
        if j < dishes[i][0] :
            dp[i+1][j] = dp[i][j]
        else:
            if dp[i][j] > dp[i][j-dishes[i][0]]+dishes[i][1]:
                dp[i+1][j] = dp[i][j]
            else:
                dp[i+1][j] = dp[i][j-dishes[i][0]]+dishes[i][1]
    ans_i = dp[i][t-1] + max( dishes[i:], key=lambda x: x[1])[1]
    ans = max(ans, ans_i)

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
import numpy as np
from collections import defaultdict

def main():
        
    n = int(input())
    a = np.array(list(map(int, input().split())))
    b = np.array(list(map(int, input().split())))

    a_sort = np.sort(a)
    b_sort = np.sort(b)

    # 1. 回数関係なくそもそも不可能なやつ → no
    # 2-a. サイクルは1つだとしても，完璧じゃない組み合わせが1つ以上許容されるやつ → yes
    # 2-b. サイクルが2以上にわけられるやつ → yes

    # 1
    if (a_sort > b_sort).any():
        print('No')
        exit()

    # 2-a
    if (a_sort[1:] <= b_sort[:-1]).any():
        print('Yes')
        exit()

    # 2-b （startをとりあえず1とかにする）
    d = defaultdict(int)
    for i in range(n):
        d[a[i]] = b[i]

    from_ = 1
    count = 0
    while True:
        count += 1
        from_ = d[from_]
        if from_ == 1:
            break

    if count != n:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Fixed submission:
n = int(input())

if n % 2 == 0:
    print(n//2 -1)
else:
    print(n//2)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
A = list( map(int, input().split()))
F = list( map(int, input().split())) 
A = sorted(A)
F = sorted(F, reverse = True)

def isok(ans):
    k_ = 0
    for a,f in zip(A,F):
        if a > ans//f:
            k_ += a - ans//f
            if k_ > k:
                return False
    return True

ok = max(A)*max(F)
ng = 0

while ok - ng >= 1:
    m = (ok+ng)//2
    if ok - ng == 1:
        if isok(ng):
            ok = ng
            break
        break
    if isok(m):
        ok = m
    else:
        ng = m
print(ok)



Fixed submission:
n, k = map(int, input().split())
A = list( map(int, input().split()))
F = list( map(int, input().split())) 
A = sorted(A)
F = sorted(F, reverse = True)

def isok(ans):
    k_ = 0
    for a,f in zip(A,F):
        if a > ans//f:
            k_ += a - ans//f
            if k_ > k:
                return False
    return True

ok = max(A)*max(F)
ng = 0

while ok - ng >= 1:
    m = (ok+ng)//2
    if ok - ng == 1:
        if isok(ng):
            ok = ng
            break
        break
    if isok(m):
        ok = m
    else:
        ng = m
print(ok)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n, k = map(int, input().split())
A = list( map(int, input().split()))
F = list( map(int, input().split())) 
A = sorted(A)
F = sorted(F, reverse = True)
A = np.array(A)
F = np.array(F)

af = A*F


while k > 0:
    maxIndex = [i for i, x in enumerate(af) if x == max(af)]
    if k >= len(maxIndex):
        af[maxIndex] -= F[maxIndex]
        k -= len(maxIndex)

    else:
        break

print(np.max(af))

Fixed submission:
n, k = map(int, input().split())
A = list( map(int, input().split()))
F = list( map(int, input().split())) 
A = sorted(A)
F = sorted(F, reverse = True)

def isok(ans):
    k_ = 0
    for a,f in zip(A,F):
        if a > ans//f:
            k_ += a - ans//f
            if k_ > k:
                return False
    return True

ok = max(A)*max(F)
ng = 0

while ok - ng >= 1:
    m = (ok+ng)//2
    if ok - ng == 1:
        if isok(ng):
            ok = ng
            break
        break
    if isok(m):
        ok = m
    else:
        ng = m
print(ok)
Buggy python submission (verdict: Runtime Error):
n, m, l = map(int, input().split())
abc = [tuple(map(int,input().split())) for i in range(m)]
q = int(input())
st = [tuple(map(int,input().split())) for i in range(q)]

lmod = 10^len(str(l))

def warshall_floyd(dp):
    #d[i][j]: iからjへの最短距離 + lmod * 補給回数
    for k in range(n):
        for i in range(n):
            for j in range(n):
                dp[i][j] = min(dp[i][j],dp[i][k] + dp[k][j])
                if dp[i][j]%lmod >= l:
                    dp[i][j] = dp[i][j] - l + lmod 

    return dp


dp = [[float('inf') for i in range(n)] for i in range(n)] 
for a,b,c in abc:
    a = a - 1
    b = b - 1
    if c > l:
        c = float('inf')     
    
    dp[a][b] = c
    dp[b][a] = c
for i in range(n):
    dp[i][i] = 0

dp_ = warshall_floyd(dp)



for s,t in st:
    s = s-1
    t = t-1
    if dp_[s][t] == float('inf'):
        print(-1)
    else:
        print(dp_[s][t]//lmod)


Fixed submission:
import sys
input = sys.stdin.readline

n, m, l = map(int, input().split())

def warshall_floyd(dp):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                dp[i][j] = min(dp[i][j] , dp[i][k] + dp[k][j])
    return dp

dp = [[float('inf')]*n for _ in range(n)]

for _ in range(m):
    a, b, c = map(int,input().split())
    dp[a-1][b-1] = dp[b-1][a-1] = c

for i in range(n):
    dp[i][i] = 0

dp = warshall_floyd(dp)

dp2 = [[float('inf')]*n for _ in range(n)]

for i in range(n):
    for j in range(n):
        if dp[i][j] <= l:
            dp2[i][j] = 1
    dp2[i][i] = 0
dp2 = warshall_floyd(dp2)

q = int(input())

ans = [0]*q
for i in range(q):
    s, t = map(int,input().split())
    tmp = dp2[s-1][t-1]
    ans[i] = -1 if tmp == float('inf') else tmp - 1

print(*ans, sep='\n')
Buggy python submission (verdict: Runtime Error):
import math
a,b=map(int, input().split())
n = math.gcd(a,b)


def divisor(n):
    ass = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            ass.append(i)
            ass.append(n//i)
    return ass

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


divs = divisor(n)
ans = 0

for d in divs:
    ans += is_prime(d)


print(ans+1)

Fixed submission:
import fractions
a,b=map(int, input().split())
n = fractions.gcd(a,b)


def divisor(n):
    ass = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            ass.append(i)
            ass.append(n//i)
    return ass

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


divs = divisor(n)
ans = 0

for d in divs:
    ans += is_prime(d)


print(ans+1)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(sorted(input()) for i in range(n)) 

ans = 0
for i in range(n):
    for j in range(i+1,n):
        if s[i] == s[j]:
            ans += 1

print(ans)

Fixed submission:
from collections import Counter
n = int(input())
S = list(input() for i in range(n)) 

ctr = Counter()
ans = 0
for s in S:
    s =  ''.join(sorted(list(s)))
    if s in ctr:
        ans += ctr[s]
    ctr[s] += 1 

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = list(map(int, input().split()))
a = [0]* n
b = [0]* n
for i in range(n):
    a[i], b[i] = list(map(int, input().split()))

ans = 0

for j in range(1,m+1):
    # aがj以下で最大のbをもつもの
    bmax = 0
    bmaxind = n
    for i in range(n):
        if a[i] <= j and b[i] > bmax:
            bmax = b[i]
            bmaxind = i
    ans += bmax
    if bmaxind < n:
        a[bmaxind] = float('inf')
    
print(ans)


Fixed submission:
import heapq

# max heap
class Heapq:
    def __init__(self, arr, desc=False):
        if desc:
            arr = [-a for a in arr]
        self.sign = -1 if desc else 1
        self.hq = arr
        heapq.heapify(self.hq)
 
    def pop(self):
        return heapq.heappop(self.hq) * self.sign
 
    def push(self, a):
        heapq.heappush(self.hq, a * self.sign)
 
    def top(self):
        return self.hq[0] * self.sign
 
    def size(self):
        return len(self.hq)

from collections import defaultdict
d = defaultdict(list)

n, m = map(int, input().split())
ab = [tuple(map(int,input().split())) for i in range(n)]
for a,b in ab:
    d[a].append(b)

q = Heapq([], True)
 
ans = 0
for i in range(1,m+1):
    for b in d[i]:
        q.push(b)
    if q.size():
        ans += q.pop()
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = list(map(int, input().split()))
a = [0]* n
b = [0]* n
for i in range(n):
    a[i], b[i] = list(map(int, input().split()))

ans = 0

for j in range(1,m+1):
    # aがj以下で最大のbをもつもの
    bmax = 0
    bmaxind = n
    for i in range(n):
        if a[i] <= j and b[i] > bmax:
            bmax = b[i]
            bmaxind = i
    ans += bmax
    if bmaxind < n:
        a[bmaxind] = float('inf')
    
print(ans)

Fixed submission:
import heapq

# max heap
class Heapq:
    def __init__(self, arr, desc=False):
        if desc:
            arr = [-a for a in arr]
        self.sign = -1 if desc else 1
        self.hq = arr
        heapq.heapify(self.hq)
 
    def pop(self):
        return heapq.heappop(self.hq) * self.sign
 
    def push(self, a):
        heapq.heappush(self.hq, a * self.sign)
 
    def top(self):
        return self.hq[0] * self.sign
 
    def size(self):
        return len(self.hq)

from collections import defaultdict
d = defaultdict(list)

n, m = map(int, input().split())
ab = [tuple(map(int,input().split())) for i in range(n)]
for a,b in ab:
    d[a].append(b)

q = Heapq([], True)
 
ans = 0
for i in range(1,m+1):
    for b in d[i]:
        q.push(b)
    if q.size():
        ans += q.pop()
print(ans)