Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
W, H, x, y = map(int, input().split())
if (x == W and y == H) or (x == 0 and y == 0) or (x == W and y == 0) or (x == 0 and y == H):
    print(W*H, 0)
else:
    # 横分割の時の最小値を求める
    A = min((H-y)*W, y*W)
 
    # 縦分割の時の最小値を求める
    B = min((W-x)*H, x*H)
 
    # 最後に最大の方を選ぶ
    # このときA=Bなら複数あるということ
    if A == B:
        print(A, 1)
    else:
        print(max(A, B), 0)

Fixed submission:
X, A = map(int, input().split())
if X < A:
    print(0)
else:
    print(10)
Buggy python submission (verdict: Runtime Error):
import collections
import numpy as np

N = int(input())

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

xy = np.array(xy)

diff_xy = []

for i in range(N-1):
    for j in range(i+1, N):
        diff_xy.append(list(xy[j] - xy[i]))

cs = []
for c in diff_xy:
    cs.append(diff_xy.count(c))
    
print(1 + (N - (max(cs) + 1)))

Fixed submission:
import collections
import numpy as np

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

xy = np.array(xy)

dic_xy = {}

for i in range(N):
    for j in range(N):
        if i != j:
            diff_xy = xy[i] - xy[j]
            diff_xy = tuple(diff_xy)
            
            if dic_xy.get(diff_xy) is None:
                dic_xy[diff_xy] = 1
            else:
                dic_xy[diff_xy] += 1

max_diff = 0
for x in dic_xy:
    max_diff = max(max_diff, dic_xy[x])
    
print(N - max_diff)

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

N = int(input())

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

xy = np.array(xy)

diff_xy = []

for i in range(N-1):
    for j in range(i+1, N):
        diff_xy.append(list(xy[j] - xy[i]))

cs = []
for c in diff_xy:
    cs.append(diff_xy.count(c))
    
print(1 + (N - (max(cs) + 1)))

Fixed submission:
import collections
import numpy as np

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

xy = np.array(xy)

dic_xy = {}

for i in range(N):
    for j in range(N):
        if i != j:
            diff_xy = xy[i] - xy[j]
            diff_xy = tuple(diff_xy)
            
            if dic_xy.get(diff_xy) is None:
                dic_xy[diff_xy] = 1
            else:
                dic_xy[diff_xy] += 1

max_diff = 0
for x in dic_xy:
    max_diff = max(max_diff, dic_xy[x])
    
print(N - max_diff)
Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
s1 = input()
ls = []
rs = []
for _ in range(Q):
    l, r = map(int, input().split())
    ls.append(l)
    rs.append(r)

lr = []
for i in range(Q):
    lr.append([ls[i], rs[i], i])
    
lr_sort = sorted(lr, key=lambda x: x[1]-x[0], reverse=True)
for i in range(len(lr_sort)):
    l, r = lr_sort[i][0], lr_sort[i][1]
    if i == 0:
        s2 = s1[l-1:r]
        flag = 0
        for j in range(len(s2)-1):
            if s2[j]=='A' and s2[j+1]=='C':
                flag += 1
        lr_sort[i].append(flag)
    else:
        l_p, r_p = lr_sort[i-1][0], lr_sort[i-1][1]
        
        for j in range(min(l,l_p), max(l,l_p)):
            if s2[j]=='A' and s2[j+1]=='C':
                flag -= 1
        for j in range(min(r,r_p), max(r,r_p)):
            if s2[j]=='A' and s2[j+1]=='C':
                flag -= 1
        lr_sort[i].append(flag)

lr_sort2 = sorted(lr_sort, key=lambda x: x[2])
for ans in lr_sort2:
    print(ans[3])

Fixed submission:
N, Q = map(int, input().split())
s1 = input()
t = [0 for _ in range(N+1)]
for i in range(N):
    t[i+1] = t[i] + (1 if s1[i:i+2] == 'AC' else 0)
for i in range(Q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
s1 = input()
ls = []
rs = []
for _ in range(Q):
    l, r = map(int, input().split())
    ls.append(l)
    rs.append(r)

lr = []
for i in range(Q):
    lr.append([ls[i], rs[i], i])
    
lr_sort = sorted(lr, key=lambda x: x[1]-x[0], reverse=True)
for i in range(len(lr_sort)):
    l, r = lr_sort[i][0], lr_sort[i][1]
    #print(l, r)
    if i == 0:
        s2 = s1[l-1:r]
        flag = 0
        for j in range(len(s2)-1):
            if s2[j]=='A' and s2[j+1]=='C':
                flag += 1
        lr_sort[i].append(flag)
    else:
        l_p, r_p = lr_sort[i-1][0], lr_sort[i-1][1]
        #print(l_p, r_p)
        
        for j in range(min(l,l_p), max(l,l_p)):
            if s2[j]=='A' and s2[j+1]=='C':
                flag -= 1
        for j in range(min(r,r_p), max(r,r_p)):
            if s2[j]=='A' and s2[j+1]=='C':
                flag -= 1
        lr_sort[i].append(flag)
lr_sort2 = sorted(lr_sort, key=lambda x: x[2])
for ans in lr_sort2:
    print(ans[3])

Fixed submission:
N, Q = map(int, input().split())
s1 = input()
t = [0 for _ in range(N+1)]
for i in range(N):
    t[i+1] = t[i] + (1 if s1[i:i+2] == 'AC' else 0)
for i in range(Q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
s1 = input()
lr = [(map(int, input().split())) for _ in range(Q)]

for k in range(Q):
    l, r = lr[k]
    s2 = s1[l-1:r]
    flag = 0
    for i in range(len(s2)-1):
        if s2[i]=='A' and s2[i+1]=='C':
            flag += 1
    print(flag)

Fixed submission:
N, Q = map(int, input().split())
s1 = input()
t = [0 for _ in range(N+1)]
for i in range(N):
    t[i+1] = t[i] + (1 if s1[i:i+2] == 'AC' else 0)
for i in range(Q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])
Buggy python submission (verdict: Runtime Error):
import collections
N = int(input())
l = list(input())
c = collections.Counter(l)
m = 1
for k, v in c.items():
    m *= (v + 1)
print(m - 1)
import collections
N = int(input())
l = list(input())
c = collections.Counter(l)
m = 1
for k, v in c.items():
    m *= (v + 1)
m = m - 1
m = m % (10^9 + 7)
import collections
N = int(input())
l = list(input())
c = collections.Counter(l)
m = 1
for k, v in c.items():
    m *= (v + 1)
print(m - 1)
import collections
N = int(input())
l = list(input())
c = collections.Counter(l)
m = 1
for k, v in c.items():
    m *= (v + 1)
m = m - 1
m = m % (10^9 + 7)
print(m)

Fixed submission:
from sys import stdin
N=int(input())
S=list(input().strip())
ans=1
for i in set(S):
    ans=ans*(S.count(i)+1)
ans-=1
print(ans%(10**9+7))

Buggy python submission (verdict: Runtime Error):
import collections
N = int(input())
l = list(input())
c = collections.Counter(l)
m = 1
for k, v in c.items():
    m *= (v + 1)
print(m - 1)
import collections
N = int(input())
l = list(input())
c = collections.Counter(l)
m = 1
for k, v in c.items():
    m *= (v + 1)
m = m - 1
m = m % (10^9 + 7)


Fixed submission:
from sys import stdin
N=int(input())
S=list(input().strip())
ans=1
for i in set(S):
    ans=ans*(S.count(i)+1)
ans-=1
print(ans%(10**9+7))
Buggy python submission (verdict: Runtime Error):
HW = list(map(int, input().split()))
hw = list(map(int, input().split()))

H = HW[0]
W = HW[1]

h = hw[0]
w = hw[1]

return H * W - (H * h + (W - h) * w)


Fixed submission:
HW = list(map(int, input().split()))
hw = list(map(int, input().split()))
H = HW[0]
W = HW[1]
h = hw[0]
w = hw[1]
r = H * W - (W * h + (H - h) * w)
print(r)

Buggy python submission (verdict: Runtime Error):
N = int(input())
a = [input() for i in range(N)]
print(a)

Fixed submission:
HW = list(map(int, input().split()))
hw = list(map(int, input().split()))
H = HW[0]
W = HW[1]
h = hw[0]
w = hw[1]
r = H * W - (W * h + (H - h) * w)
print(r)
Buggy python submission (verdict: Runtime Error):
m = 0
cnt = 0
for i in range(N):
    
    cnt += c[i][1]
    m += c[i][0] * c[i][1]
     
    if cnt == M:
        print(m)
        break
    elif cnt > M:
        print(m - c[i][0] * (cnt - M))
        break
    else:
        continue

Fixed submission:
N, M = map(int, input().split())
a, b = [0 for _ in range(N)], [0 for _ in range(N)]
for i in range(N):
    a[i], b[i] = (list(map(int, input().split())))
c = []
for i in range(N):
    c.append([a[i],b[i],i])
c = sorted(c, key=lambda x: x[0])
m = 0
cnt = 0
for i in range(N):
    
    cnt += c[i][1]
    m += c[i][0] * c[i][1]
     
    if cnt == M:
        print(m)
        break
    elif cnt > M:
        print(m - c[i][0] * (cnt - M))
        break
    else:
        continue

Buggy python submission (verdict: Time Limit Exceeded):
N, M = list(map(int, input().split()))
a, b = [0 for _ in range(N)], [0 for _ in range(N)]
for i in range(N):
    a[i], b[i] = (list(map(int, input().split())))
for i in range(1, len(a)):
    j = i - 1
    ele1 = a[i]
    ele2 = b[i]
    while a[j] > ele1 and j >= 0:
        a[j+1] = a[j]
        b[j+1] = b[j]
        j -= 1
    a[j+1] = ele1
    b[j+1] = ele2
money=0
for i in range(N):
    money+=a[i]*b[i]
    M-=b[i]
    if M <= 0:
        break
if M == 0:
    print(money)
else:
    print(money + (a[i] * M))

Fixed submission:
N, M = map(int, input().split())
a, b = [0 for _ in range(N)], [0 for _ in range(N)]
for i in range(N):
    a[i], b[i] = (list(map(int, input().split())))
c = []
for i in range(N):
    c.append([a[i],b[i],i])
c = sorted(c, key=lambda x: x[0])
m = 0
cnt = 0
for i in range(N):
    
    cnt += c[i][1]
    m += c[i][0] * c[i][1]
     
    if cnt == M:
        print(m)
        break
    elif cnt > M:
        print(m - c[i][0] * (cnt - M))
        break
    else:
        continue

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

change = True
while change:
    change = False
    for i in range(N-1):
        if a[i] > a[i+1]:
            a[i], a[i+1] = a[i+1], a[i]
            b[i], b[i+1] = b[i+1], b[i]
            change = True

money=0
for i in range(N):
    money+=a[i]*b[i]
    M-=b[i]
    if M <= 0:
        break
if M == 0:
    print(money)
else:
    print(money + (a[i] * M))

Fixed submission:
N, M = map(int, input().split())
a, b = [0 for _ in range(N)], [0 for _ in range(N)]
for i in range(N):
    a[i], b[i] = (list(map(int, input().split())))
c = []
for i in range(N):
    c.append([a[i],b[i],i])
c = sorted(c, key=lambda x: x[0])
m = 0
cnt = 0
for i in range(N):
    
    cnt += c[i][1]
    m += c[i][0] * c[i][1]
     
    if cnt == M:
        print(m)
        break
    elif cnt > M:
        print(m - c[i][0] * (cnt - M))
        break
    else:
        continue
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
hs = [int(input()) for _ in range(N)]
hs_sort = sorted(hs)
diff_min = 1e5
for i in range(N-K+1):
    diff = hs_sort[i+2] - hs_sort[i]
    if diff < diff_min:
        diff_min = diff
    else:
        continue
print(diff_min)

Fixed submission:
N, K = map(int, input().split())
hs = [int(input()) for _ in range(N)]
hs_sort = sorted(hs)
diff_min = 1e10
for i in range(N-K+1):
    diff = hs_sort[i+K-1] - hs_sort[i]
    if diff <= diff_min:
        diff_min = diff
    else:
        continue
print(diff_min)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
p = []
y = []
for i in range(M):
    p1,y1=[int(i) for i in input().split()]
    p.append(p1)
    y.append(y1)
ans = [0 for _ in range(M)]
for idx in range(M):
    ans[idx] = [idx, p[idx], y[idx]]
ans = sorted(ans, key=lambda x: x[1])
ans = sorted(ans, key=lambda x: x[2])
for idx in range(M):
    if idx == 0:
        ans[idx][2] = 1
    else:
        if ans[idx][1] == ans[idx-1][1]:
            ans[idx][2] = ans[idx-1][2] + 1
        else:
            ans[idx][2] = 1
ans = sorted(ans, key=lambda x: x[0])
for idx in range(M):
    print('{:0=6}{:0=6}'.format(ans[idx][1], ans[idx][2]))

Fixed submission:
x, y = map(int, input().split())
print(int(x + y/2))
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
p = []
y = []
for i in range(M):
    p1,y1=[int(i) for i in input().split()]
    p.append(p1)
    y.append(y1)
for idx in range(M):
    ans[idx] = [idx, p[idx], y[idx]]
ans = sorted(ans, key=lambda x: x[1])
ans = sorted(ans, key=lambda x: x[2])
for idx in range(M):
    if idx == 0:
        ans[idx][2] = 1
    else:
        if ans[idx][1] == ans[idx-1][1]:
            ans[idx][2] = ans[idx-1][2] + 1
        else:
            ans[idx][2] = 1
ans = sorted(ans, key=lambda x: x[0])
for idx in range(M):
    print('{:0=6}{:0=6}'.format(ans[idx][1], ans[idx][2]))

Fixed submission:
N, M = map(int, input().split())
anses = [0] * M
pre = [0] * N
 
for idx in range(M):
    p, y = (int(x) for x in input().split())
    anses[idx] = [idx, p, y, 0]

anses = sorted(anses, key=lambda x: x[2])

for ans in anses:
    pre[ans[1]-1] += 1
    ans[3] = pre[ans[1]-1]

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

for ans in anses:
    print('{:0=6}{:0=6}'.format(ans[1], ans[3]))
Buggy python submission (verdict: Runtime Error):
N,A,B=mnap(int,input().split())

C=A*N
if C<B:
  print(B)
elif C>B:
  print(C)

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

C=A*N
if C<=B:
  print(C)
elif C>B:
  print(B)
Buggy python submission (verdict: Runtime Error):
L,R = list(map(int, input().split()))
if R-L >= 2019:
  print(0)
elif:
  M=2019
  for i in range(L,R):
    for j in range(i+1,R+1):
      L=(i * j) % 2019
      if L<M:
        M=L
print(M)

Fixed submission:
L,R = list(map(int, input().split()))
if R - L >= 2019:
  print(0)
else:
  M=2019
  for i in range(L,R):
    for j in range(i+1,R+1):
      K=i * j % 2019
      if K < M:
        M = K
  print(M)

Buggy python submission (verdict: Time Limit Exceeded):
L,R = list(map(int, input().split()))
M=2019
for i in range(L,R):
  for j in range(i+1,R+1):
    L=(i * j) % 2019
    if L<M:
      M=L
print(M)

Fixed submission:
L,R = list(map(int, input().split()))
if R - L >= 2019:
  print(0)
else:
  M=2019
  for i in range(L,R):
    for j in range(i+1,R+1):
      K=i * j % 2019
      if K < M:
        M = K
  print(M)
Buggy python submission (verdict: Runtime Error):
N = int(input())
H = list(map(int, input().split()))
count = 0
counts = []

for i in range(N-1):
    if H[i] >= H[i+1]:
        count += 1
    else:
        counts.append(count)
        count = 0

print(max(counts))

Fixed submission:
N = int(input())
H = list(map(int, input().split()))
count = 0
counts = []

if N <= 1:
    counts.append(0)
else:
    for i in range(N-1):
        if H[i] >= H[i+1]:
            count += 1
        else:
            counts.append(count)
            count = 0
    else:
        counts.append(count)

print(max(counts))

Buggy python submission (verdict: Runtime Error):
N = int(input())
H = list(map(int, input().split()))
counts = []
i = 0

while True:
    count = 0
    if i == N-1:
        break
    for j in range(i+1, N):
        if H[j-1] < H[j]:
            i = j-1
            break
        count += 1
    counts.append(count)
    i += 1

print(max(counts))

Fixed submission:
N = int(input())
H = list(map(int, input().split()))
count = 0
counts = []

if N <= 1:
    counts.append(0)
else:
    for i in range(N-1):
        if H[i] >= H[i+1]:
            count += 1
        else:
            counts.append(count)
            count = 0
    else:
        counts.append(count)

print(max(counts))

Buggy python submission (verdict: Runtime Error):
N = int(input())
H = list(map(int, input().split()))
counts = []

for i in range(N):
    if i == N-1:
        break
    count = 0
    for j in range(i+1, N):
        if H[i] < H[j]:
            break
        count += 1
    counts.append(count)

print(max(counts))

Fixed submission:
N = int(input())
H = list(map(int, input().split()))
count = 0
counts = []

if N <= 1:
    counts.append(0)
else:
    for i in range(N-1):
        if H[i] >= H[i+1]:
            count += 1
        else:
            counts.append(count)
            count = 0
    else:
        counts.append(count)

print(max(counts))

Buggy python submission (verdict: Runtime Error):
N = int(input())
H = list(map(int, input().split()))
counts = []

for i in range(N):
    count = 0
    for j in range(i+1, N):
        if H[i] < H[j]:
            break
        count += 1
    counts.append(count)

print(max(count))

Fixed submission:
N = int(input())
H = list(map(int, input().split()))
count = 0
counts = []

if N <= 1:
    counts.append(0)
else:
    for i in range(N-1):
        if H[i] >= H[i+1]:
            count += 1
        else:
            counts.append(count)
            count = 0
    else:
        counts.append(count)

print(max(counts))
Buggy python submission (verdict: Runtime Error):
import math

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

z = Y//1000 - N

for m in range(z//9 + 1):
    if (z - 9*m)%4 == 0:
        g = (z - 9*m)//4
        result = [m, g, N-m-g]
    else:
        result = [-1, -1, -1]

print(' '.join(map(str, result)))

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

z = Y//1000 - N
flag = False

for m in range(z//9 + 1):
    if (z - 9*m)%4 == 0:
        g = (z - 9*m)//4
        if m + g <= N:
            result = [m, g, N-m-g]
            flag = True
            break
    else:
        pass

if not flag:
    result = [-1, -1, -1]

print(' '.join(map(str, result)))
Buggy python submission (verdict: Runtime Error):
n=int(input())
sum=0
for i in range(0,n):
        x=float(input())
        y=str(input())
        if(y=='JPY'):
                sum=sum+x
        else:
                z=x*380000.0
                sum=sum+z
print(sum)

Fixed submission:
def main():
    N = int(input())
    total = 0
    for i in range(N):
        money,currency = input().split()
        if currency == "JPY":
            total += float(money)
        else:
            total += float(money)*380000
    print(total)
main()
Buggy python submission (verdict: Runtime Error):
n = int(input())
p = list(range(2, n+1))
p.append(1)
sum = 0
for i in range(n-1):
    sum += (i+1) % p[i]
print(sum)

Fixed submission:
n = int(input())
print(n*(n-1)//2)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(float, input().split()))

a.reverse()

answer = 0.0
for i in range(0, len(a)-1):
  a[i+1] = (a[i] + a[i+1]) / 2

print(a[len(a)-1])

Fixed submission:
a = int(input())
s = input()

if a >= 3200:
  print(s)
else:
  print("red")
Buggy python submission (verdict: Runtime Error):
n, l = map(int, input().split())

str = []
for i in range(n):
  str.append(input())

str.sort()

print(''.join(str))

Fixed submission:
s = input().split()

a = int(s[0])
b = int(s[1])
c = int(s[2])

count_5 = 0
if a == 5:
  count_5 += 1
if b == 5:
  count_5 += 1
if c == 5:
  count_5 += 1
  
count_7 = 0
if a == 7:
  count_7 += 1
if b == 7:
  count_7 += 1
if c == 7:
  count_7 += 1
  
if count_5 == 2 and count_7 == 1:
  print("YES")
else:
  print("NO")

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

str = []
for i in range(n):
  str.append(input())

str.sort()

print("".join(str))

Fixed submission:
s = input().split()

a = int(s[0])
b = int(s[1])
c = int(s[2])

count_5 = 0
if a == 5:
  count_5 += 1
if b == 5:
  count_5 += 1
if c == 5:
  count_5 += 1
  
count_7 = 0
if a == 7:
  count_7 += 1
if b == 7:
  count_7 += 1
if c == 7:
  count_7 += 1
  
if count_5 == 2 and count_7 == 1:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Runtime Error):
a = input()

if a < 1200:
    print("ABC")
elif(a < 2800):
    print("ARC")
else:
    print("AGC")


Fixed submission:
a = int(input())

if a < 1200:
    print("ABC")
elif a < 2800:
    print("ARC")
else:
    print("AGC")

Buggy python submission (verdict: Runtime Error):
a = input()

if a < 1200:
    print("ABC")
elif(a < 2800)
    print("ARC")
else
    print("AGC")


Fixed submission:
a = int(input())

if a < 1200:
    print("ABC")
elif a < 2800:
    print("ARC")
else:
    print("AGC")
Buggy python submission (verdict: Runtime Error):
# B - Power Socket

a = int(input())
b = int(input())
div = b // (a - 1)
mod = b % (a - 1)

print(1 if a == b else (div + 1 if mod > 1 else div))

Fixed submission:
# B - Power Socket

a, b = list(map(int, input().split()))
tgt = b - a

if tgt == 0:
    print(1)
else:
    div = tgt // (a - 1)
    mod = tgt % (a - 1)
    print(div + 2 if mod > 0 else div + 1)
Buggy python submission (verdict: Runtime Error):
# D - Summer Vacation

_input = list(map(int, input().split()))
n = _input[0]
m = _input[1]
jobs = dict()
for i in range(n):
    __input = list(map(int, input().split()))
    a = __input[0]
    b = __input[1]
    item = jobs[b] if b in jobs else list()
    item.append(a)
    item.sort(reverse=True)
    jobs[b] = item

sorted(jobs.items(), key=lambda j: -j[0])
reward = 0
while m > 0:
    for b, aList in jobs:
        if len(aList) > 0 and m >= aList[0]:
            reward += b
            aList.pop(0)
            jobs[b] = aList
            break
    m -= 1

print(reward)

Fixed submission:
# D - Summer Vacation ★
from collections import defaultdict
from heapq import heappush, heappop

_input = list(map(int, input().split()))
n = _input[0]
m = _input[1]
jobs = defaultdict(list)

# かかる日数ごとに報酬をまとめる
for i in range(n):
    a, b = list(map(int, input().split()))
    if a <= m:
        jobs[a].append(b)

# M-1日目、M-2日目…と後ろから順に得られる報酬が多い仕事を割り振っていく
# ※日数制限があったほうが埋めやすいので
reward = 0
heapsort = []
for daysLeft in range(1, m + 1):
    if daysLeft in jobs:
        for b in jobs[daysLeft]:
            heappush(heapsort, -b)
    if len(heapsort) > 0:
        reward += -heappop(heapsort)
print(reward)

Buggy python submission (verdict: Time Limit Exceeded):
# D - Summer Vacation

_input = list(map(int, input().split()))
n = _input[0]
m = _input[1]
jobs = dict()
for i in range(n):
    __input = list(map(int, input().split()))
    a = __input[0]
    b = __input[1]
    item = jobs[b] if b in jobs else list()
    item.append(a)
    item.sort(reverse=True)
    jobs[b] = item

reward = 0
while m > 0:
    for b, aList in sorted(jobs.items(), key=lambda j: -j[0]):
        if len(aList) > 0 and m >= aList[0]:
            reward += b
            aList.pop(0)
            jobs[b] = aList
            break
    m -= 1

print(reward)

Fixed submission:
# D - Summer Vacation ★
from collections import defaultdict
from heapq import heappush, heappop

_input = list(map(int, input().split()))
n = _input[0]
m = _input[1]
jobs = defaultdict(list)

# かかる日数ごとに報酬をまとめる
for i in range(n):
    a, b = list(map(int, input().split()))
    if a <= m:
        jobs[a].append(b)

# M-1日目、M-2日目…と後ろから順に得られる報酬が多い仕事を割り振っていく
# ※日数制限があったほうが埋めやすいので
reward = 0
heapsort = []
for daysLeft in range(1, m + 1):
    if daysLeft in jobs:
        for b in jobs[daysLeft]:
            heappush(heapsort, -b)
    if len(heapsort) > 0:
        reward += -heappop(heapsort)
print(reward)