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

Fixed submission:
# -*- coding: utf-8 -*-
# 整数の入力
#a = int(input())
# スペース区切りの整数の入力
#b, c = map(int, input().split())
# 文字列の入力
#s = input()
# 出力
#print("{} {}".format(a+b+c, s))

import numpy as np

nrow = input()
k = int(input())

l = len(nrow)

dp = np.zeros((l, 2, 4), int)
topmax = int(nrow[0])
dp[0, 0, 1] = 1  # =topmax
dp[0, 1, 0] = 1  # =0
dp[0, 1, 1] = topmax-1  # <topmax

for i in range(1, l):
  topmax = int(nrow[i])

  dp[i, 1, 0] = dp[i-1, 1, 0]  # =0
  for j in range(1,4):
    dp[i, 1, j] = dp[i-1, 1, j] + dp[i-1, 1, j-1] * 9  # =0,any

  if topmax == 0:
    for j in range(1, 4):
      dp[i, 0, j] = dp[i-1, 0, j]  #=0
  else:
    dp[i, 0, 2] = dp[i-1, 0, 1]  # =topmax,
    dp[i, 0, 3] = dp[i-1, 0, 2]  # =topmax,
    dp[i, 1, 1] += dp[i-1, 0, 1] # =0,<topmax
    dp[i, 1, 2] += dp[i-1, 0, 2]+dp[i-1, 0, 1] * (topmax-1)  # =0,<topmax
    dp[i, 1, 3] += dp[i-1, 0, 3]+dp[i-1, 0, 2] * (topmax-1)  # =0,<topmax

print(dp[l-1,0,k]+dp[l-1,1,k])

Buggy submission (verdict: Runtime Error):
import math

def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def count1(nrow, k):
  keta = len(nrow)
  topmax = int(nrow[0])

  if keta == 1:
    return topmax
  ans = topmax
  ans += (keta-1)*9
  return ans

def count2(nrow, k):
  keta = len(nrow)
  topmax = int(nrow[0])

  ans = count1(nrow[1:], k)  # top==topmax
  ans += (topmax-1)*(keta-1)*9  # top!=topmax
  if keta > 2:
    ans += comb(keta-1, 2)*81
  return ans

def count3(nrow, k):
  keta = len(nrow)
  topmax = int(nrow[0])

  ans = count2(nrow[1:],k) #top==topmax
  ans += (topmax-1)*comb(keta-1,2) * 81#top!=topmax
  if keta > 3:
    ans += comb(keta-1 , 3) * 729
  return ans

nrow=input()
k = int(input())

if k==1:
  print(count1(nrow,k))
elif k == 2:
  print(count2(nrow,k))
elif k == 3:
  print(count3(nrow,k))
Problem p02659 (python)

Fixed submission:
# coding: utf-8
# Your code here!
from decimal import Decimal
a, b = input().split()
a = Decimal(str(a))
b = Decimal(str(b))
c = str(a * b)
index = c.find('.')
print(c[:index])

Buggy submission (verdict: Runtime Error):
import decimal
a, b = map(int, input().split())
a = Decimal(str(a))
b = Decimal(str(b))
c = str(a * b)
index = c.find('.')
print(c[:index])

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
number = str(a * b)
index = number.find('.')
number = number[:index]
print(number)
Problem p02676 (python)

Fixed submission:
K = int(input())
S = input()
strings = ''
if K >= len(S):
  print(S)
else:
  strings = str(S[:K]) + '...'
  print(strings)

Buggy submission (verdict: Runtime Error):
K = input()
S = input()
strings = ''
if len(K) >= len(S):
  print(S)
else:
  strings = str(S[:K + 1]) + '...'
  print(strings)

Buggy submission (verdict: Runtime Error):
K = input()
S = input()
strings = ''
if len(K) >= len(S):
  print(S)
else:
  strings = str(S[:K]) + '...'
  print(strings)

Buggy submission (verdict: Runtime Error):
K = input()
S = input()
if len(K) >= len(S):
  print(S)
else:
  strings = str(S[:K]) + '...'
  print(strings)

Buggy submission (verdict: Runtime Error):
K = input()
S = input()
if len(K) >= len(S):
  print(S)
else:
  strings = S[:K + 1] + '...'
  print(strings)

Buggy submission (verdict: Runtime Error):
K = input()
S = input()
if len(K) > len(S):
  print(S)
else:
  strings = S[:K + 1]
  print(strings)
Problem p02627 (python)

Fixed submission:
N = input()
if(N.lower() == N):
  print("a")
else:
  print("A")

Buggy submission (verdict: Runtime Error):
N = input()
if(N.lower() = N):
  print("a")
else:
  print("A")

Buggy submission (verdict: Runtime Error):
N = input()
if(N.lower() = N):
  print("a")
else:
  print("A")
Problem p02712 (python)

Fixed submission:
n = int(input())
sum = 0

for i in range(1,n+1,1):
  if(i%3 == 0 or i%5 == 0):
    continue
  sum += i
  
print(sum)

Buggy submission (verdict: Runtime Error):
n = input()
sum = 0

for i in range(1,n+1,1):
  if(i%3 == 0 or i%5 == 0):
    continue
  sum += i
  
print(sum)
Problem p02836 (python)

Fixed submission:
s = input()
n = len(s)
res = 0
for i in range(n//2):
    if s[i] != s[-(i+1)]:
        res += 1
print(res)

Buggy submission (verdict: Runtime Error):
Jupyter Notebook
0temp-Copy3
(autosaved)
Current Kernel Logo
Python 3 
File
Edit
View
Insert
Cell
Kernel
Navigate
Widgets
Help

7
ABC147
from ipywidgets import Textarea
import io
​
if 'open' in globals():
    del open
if 'input' in globals():
    del input
​
original_open = open
​
class custom_open():
    def __init__(self):
        self.text = ''
​
    def __call__(self, file, *args, **kwargs):
        if file == 0:
            return io.StringIO(self.text)
        return original_open(file, *args, **kwargs)
​
    def updater(self, change):
        self.text = change["new"]
​
class custom_input():
    def __init__(self):
        self.__sio = io.StringIO('')
        self.shell = get_ipython()
        if self.shell.events.callbacks['pre_run_cell'] != []:
            self.shell.events.callbacks['pre_run_cell'] = []
        self.shell.events.register('pre_run_cell', self.pre_run_cell)
​
    def __call__(self):
        return self.__sio.readline().strip()
​
    def pre_run_cell(self, info):
        text = self.shell.user_ns.get('text_area', None).value
        self.__sio = io.StringIO(text)
​
open = custom_open()
input = custom_input()
​
text_area = Textarea()
text_area.observe(open.updater, names='value')
display(text_area)
vvvvvv
### B - Palindrome-philia
s = input()
​
n = len(s)
if n % 2 == 1:
    front = s[:(n//2 - 1)]
    rev = front[::-1]
    end = s[(n//2 - 1):]
else:
    front = s[:(n//2)]
    rev = front[::-1]
    end = s[(n//2):]
​
res = 0
for i in range(n//2 - 1):
    if rev[i] != end[i]:
        res += 1
print(res)
0
rev
'cder'
end
'oder'
Problem p02916 (python)

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

sum=0
for i in range(n):
    sum=sum+b[i]
    if i>0 and a[i-1] == a[i]-1:
        sum=sum+c[a[i]-2]
print(sum)

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

sum=0
for i in range(n):
  sum=sum+b[a[i]]
  if i>0 | a[i-1] == a[i]+1:
    sum=sum+c[a[i-1]]
print(sum)

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

sum=0
for i in range(n):
  sum=sum+b[a[i]]
  if i>0 | a[i-1] == a[i]+1:
    sum=sum+c[a[i-1]]
Problem p02935 (python)

Fixed submission:
n=int(input())
v=list(map(int, input().split()))
v.sort()
sum=v[0]
for i in range(1,len(v)):
  sum=(sum+v[i])/2
print(sum)

Buggy submission (verdict: Runtime Error):
n=int(input())
v=list(map(int, input().split())).sort()
sum=v[0]
for i in range(1,len(v)):
  sum=(sum+v[i])/2
print(sum)
Problem p02951 (python)

Fixed submission:
a,b,c=map(int,input().split())
if (a-b)>=c:
  print(0)
else:
  print(c-a+b)

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
if (a-b)>=c:
  print(0)
  else:
    print(c-a+b)
Problem p03242 (python)

Fixed submission:
s=input()
t=[]
for i in range(3):
  if s[i] =='9':
    t.append('1')
  else:
    t.append('9')
st="".join(t)
print(st)

Buggy submission (verdict: Runtime Error):
s=input()
for i in range(3):
  if s[i] =='9':
    s[i]='1'
  else:
    s[i]='9'
print(s)
Problem p03307 (python)

Fixed submission:
n=int(input())
if(n%2==0):
  print(n)
else:
  print(n*2)

Buggy submission (verdict: Runtime Error):
n=int(input())
for i in 10**9:
  if n%2==0 and n%i==0:
    print(i)
    exit()
Problem p03803 (python)

Fixed submission:
a,b=map(int,input().split())
if a==b:
  print('Draw')
elif a==1 or (a>b and b!=1):
  print('Alice')
else:
  print('Bob')

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
if a==b:
  print('Draw')
elif a==1 or (a>b and B!=1):
  print('Alice')
else:
  print('Bob')
Problem p02689 (python)

Fixed submission:
n,m = map(int,input().split())
h_list = list(map(int,input().split()))
roads = []
for i in range(m):
    a,b = map(int,input().split())
    roads.append([a,b])
#print(roads)
terrace = [1] * n
for road in roads:
    if h_list[road[0]-1] > h_list[road[1]-1]:
        terrace[road[1]-1] = 0
    elif h_list[road[0]-1] == h_list[road[1]-1]:
        terrace[road[0]-1] = 0
        terrace[road[1]-1] = 0
    elif h_list[road[0]-1] < h_list[road[1]-1]:
        terrace[road[0]-1] = 0
print(terrace.count(1))

Buggy submission (verdict: Runtime Error):
# n,m = map(int,input().split())
h_list = list(map(int,input().split()))
roads = []
for i in range(m):
    a,b = map(int,input().split())
    roads.append([a,b])
#print(roads)
terrace = [1] * n
for road in roads:
    if h_list[road[0]-1] > h_list[road[1]-1]:
        terrace[road[1]-1] = 0
    elif h_list[road[0]-1] == h_list[road[1]-1]:
        terrace[road[0]-1] = 0
        terrace[road[1]-1] = 0
    elif h_list[road[0]-1] < h_list[road[1]-1]:
        terrace[road[0]-1] = 0
print(terrace.count(1))
Problem p02759 (python)

Fixed submission:
page = int(input())

if page%2 == 0 :
  print(int(page/2))
elif page%2 == 1 :
  print(page//2 + 1)

Buggy submission (verdict: Runtime Error):
page = input()
if page%2 = 0 :
  print(page/2)
elif page%2 = 1 :
  print(page/2 + 1)
Problem p03041 (python)

Fixed submission:
n,k = map(int,input().split())
s = input()
ans = ''
for i in range(n):
    if i == k-1:
        ans = ans + s[i].lower()
    else:
        ans = ans + s[i]
print(ans)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
s = input()
ans = ''
for i in len(s):
  if i == k:
    ans = ans + s[i].lower()
  ans = ans + s[i]
print(ans)
Problem p02701 (python)

Fixed submission:
n=int(input())
s=[input() for _ in range(n)]
t=list(set(s))
print(len(t))

Buggy submission (verdict: Runtime Error):
n=int(input())
s=[list(input()) for _ in range(n)]
t=list(set(s))
print(len(t))

Buggy submission (verdict: Runtime Error):
n=int(input())
s=[list(map(str,input().split())) for _ in range(n)]
t=list(set(s))
print(len(t))
Problem p02754 (python)

Fixed submission:
N,A,B=map(int,input().split())
ans=(N//(A+B))*A
rem=N%(A+B)
ans=ans+min(rem,A)
print(ans)

Buggy submission (verdict: Runtime Error):
N,A,B=map(int,input().split)
ans=N//(A+B)*A
rem=N%(A+B)
ans=ans+min(rem,A)
print(ans)
Problem p02759 (python)

Fixed submission:
N=int(input())
import math
ans=math.ceil(N/2)
print(ans)

Buggy submission (verdict: Runtime Error):
N=input()
1<=N<=100
ans=(N+1)//2
print(ans)

Buggy submission (verdict: Runtime Error):
N=input()
ans=(N+1)//2
print(ans)
Problem p02777 (python)

Fixed submission:
S,T=map(str,input().split())
A,B=map(int,input().split())
U=str(input())
if U==S:
  print(A-1,B)
else:
  print(A,B-1)

Buggy submission (verdict: Runtime Error):
S,T=map(int,input().split())
A,B=map(int,input().split())
U=input()
if U=S:
  print("{} {}".format(A-1,B))
if U=T:
  print("{} {}".format(A,B-1))
Problem p02831 (python)

Fixed submission:
import fractions
a,b=map(int,input().split())
g=fractions.gcd(a,b)
print(a*b//g)

Buggy submission (verdict: Runtime Error):
import math
a,b=map(int,input().split())
g=math.gcd(a,b)
print(a*b//g)

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
import math
ans=a*b//math.gcd(a,b)
print(ans)

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
import math
print(math.gcd(a,b))
Problem p03011 (python)

Fixed submission:
P,Q,R=map(int,input().split())
print(min(P+Q,Q+R,R+P))

Buggy submission (verdict: Runtime Error):
P,Q,R=map(int,input().split())
print(min(A+B,B+C,C+A))
Problem p03041 (python)

Fixed submission:
N,K=map(int,input().split())
S=list(input())
S[K-1]=S[K-1].lower()
print(''.join(S))

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
S=str(input())
print(S.replace(S[K-1],S[K-1].lower())
Problem p03207 (python)

Fixed submission:
n=int(input())
p=[int(input()) for _ in range(n)]
p.sort()
s=0
for i in range(n-1):
  s+=p[i]
ans=s+(p[n-1]//2)
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
p=[input() for _ in range(n)]
p.sort()
s=0
for i in range(n-1):
  s+=p[i]
ans=s+(p[n-1]//2)
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
p=list(map(int,input().split()))
half=max(p)
sum=0
i=0
for i in range(N):
  sum+=p[i]
  i+=1
all=sum-half
print(half//2+all)
Problem p03272 (python)

Fixed submission:
N,i=map(int,input().split())
print(int(N)-int(i)+1)

Buggy submission (verdict: Runtime Error):
N,i=map(int,iput().split())
print(N-i+1)
Problem p03315 (python)

Fixed submission:
S=str(input())
count=0
i=0
for i in range(4):
  if S[i]=='+':
    count+=1
  else:
    count-=1
  i+=1
print(count)

Buggy submission (verdict: Runtime Error):
S=str(input())
count==0
for i in range(4):
  if S[i]=='+':
    count+=1
  else:
    count-=1
  i+=1
print(count)
Problem p02773 (python)

Fixed submission:
from collections import Counter
n=int(input())
s=[]
ansl=[]
for i in range(n):
    s.append(input())
counter = Counter(s)
max=counter.most_common(1)[0][1]
for w in counter.most_common():
    if w[1]==max:
        ansl.append(w[0])
ansl.sort()
for i in range(len(ansl)):
    print(ansl[i])

Buggy submission (verdict: Runtime Error):
n=int(input())
s=[]
ansl=[]
for i in range(n):
    s.append(input())
counter = Counter(s)
max=counter.most_common(1)[0][1]
for w in counter.most_common():
    if w[1]==max:
        ansl.append(w[0])
ansl.sort()
for i in range(len(ansl)):
    print(ansl[i])
Problem p02831 (python)

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

Buggy submission (verdict: Runtime Error):
import math
a,b=map(int,input().split())
print(a*b//math.gcd(a, b))
Problem p02623 (python)

Fixed submission:
n, m, k = map(int, input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

for i in range(1,n):
    A[i] += A[i-1]
for i in range(1,m):
    B[i] += B[i-1]
A.insert(0,0)
B.insert(0,0)

j = m
ans = 0
for i in range(n+1):
    if A[i] > k:
        break
    
    while B[j] > k-A[i]:
        j -= 1
    ans = max(ans, i+j)

print(ans)

Buggy submission (verdict: Runtime Error):
n, m, k = map(int, input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

for i in range(1,n):
    A[i] += A[i-1]
for i in range(1,m):
    B[i] += B[i-1]
A.insert(0,0)
B.insert(0,0)

j = m
ans = 0
for i in range(m):
    if A[i] > k:
        break
    
    while B[j] > k-A[i]:
        j -= 1
    ans = max(ans, i+j)

print(ans)
Problem p02679 (python)

Fixed submission:
from math import gcd

mod = 10**9 +7
N = int(input())
dic = {}

zero = 0
for _ in range(N):
    a,b = map(int, input().split())
    if  a ==0 and b == 0:
        zero += 1
        continue
    elif a == 0:
        key = (0,1)
    elif b == 0:
        key = (1,0)
    else:
        if a<0:
            a=-a 
            b=-b
        g = gcd(a,abs(b))
        key = (a//g,b//g)
    
    if key not in dic:
        dic[key]=0

    dic[key] +=1

ans = 1
for k1, v1 in dic.items():
    if v1 ==0:
        continue

    if k1[1] >0:
        k2 = (k1[1],-k1[0])
    else:
        k2 = (-k1[1],k1[0])

    if k2 not in dic:
        ans *= 2**v1
        ans %= mod
    else:
        ans *= ((2**v1-1) %mod) + ((2**dic[k2]-1) %mod) +1
        ans %= mod
        dic[k2]=0

ans = (ans + zero -1 )%mod
print(ans)

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

mod = 10**9 +7
N = int(input())
dic = {}

zero = 0
for _ in range(N):
    a,b = map(int, input().split())
    if  a ==0 and b == 0:
        zero += 1
        continue
    elif a == 0:
        key = (0,1)
    elif b == 0:
        key = (1,0)
    else:
        if a<0:
            a=-a 
            b=-b
        g = gcd(a,abs(b))
        key = (a//g,b//g)
    
    if key not in dic:
        dic[key]=0

    dic[key] +=1

ans = 1
for k1, v1 in dic.items():
    if v1 ==0:
        continue

    if k1[1] >0:
        k2 = (k1[1],-k1[0])
    else:
        k2 = (-k1[1],k1[0])

    if k2 not in dic:
        ans *= 2**v1
        ans %= mod
    else:
        ans *= ((2**v1-1)) %mod) + ((2**dic[k2]-1)) %mod) +1
        ans %= mod
        dic[k2]=0

ans = (ans + zero -1 )%mod
print(ans)
Problem p02707 (python)

Fixed submission:
n,*l=map(int,open(0).read().split());a=[0]*n
for i in l:a[i-1]+=1
print(*a)

Buggy submission (verdict: Runtime Error):
n,a=open(0);for i in range(int(n)):print(a.count(str(i+1)))
Problem p02712 (python)

Fixed submission:
n = int(input())
count = 0;
 
for i in range(n):
  if (i + 1) % 3 != 0 and (i + 1) % 5 != 0:
    count+=(i+1)
   
print(count)

Buggy submission (verdict: Runtime Error):
n = int(input())
count = 0;

for i in range(n):
  if i % 3 != 0 && i % 5 != 0:
    count+=i
   
print(i)
Problem p02792 (python)

Fixed submission:
N = int(input())

c = [[0 for _ in range(9)] for _ in range(9)]
for i in range(1, 10):
  for j in range(1, 10):
    cnt = 0
    for n in range(1, N + 1):
      if n // (10 ** (len(str(n)) - 1)) == i and n % 10 == j:
        cnt += 1
    c[i - 1][j - 1] = cnt

ans = 0
for i in range(9):
  for j in range(9):
    ans += c[i][j] * c[j][i]
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())

def check(a, b, i):
  if (a + 1) * 10 ** i + b - 10 <= N:
    return 10 ** (i - 1)
  else:
    ret = 0
    for j in range(10 ** (i - 1)):
      if a * 10 ** i + j * 10 + a <= N:
        ret += 1
      else:
        return ret
ans = 0
for a in range(1, 10):
  for b in range(a, 10):
    if a == b:
      n = 0
      if a * 10 + b <= N:
        n += 2
      elif a <= N:
        n += 1
      for i in range(2, 6):
        n += check(a, b, i)
      ans += n ** 2
    else:
      n, m = 0, 0
      if a * 10 + b <= N:
        n += 1
      if b * 10 + a <= N:
        m += 1
      for i in range(2, 6):
        n += check(a, b, i)
        m += check(b, a, i)
      ans += n * m * 2
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())

def check(a, b, i):
  if (a + 1) * 10 ** i + b - 10 <= N:
    return 10 ** (i - 1)
  else:
    ret = 0
    for j in range(10 ** (i - 1)):
      if a * 10 ** i + j * 10 + a <= N:
        ret += 1
      else:
        return ret
ans = 0
for a in range(1, 10):
  for b in range(1, 10):
    if a == b:
      n = 0
      if a * 10 + b <= N:
        n += 2
      elif a <= N:
        ans += 1
      for i in range(2, 6):
        n += check(a, b, i)
      ans += n ** 2
    else:
      n, m = 0, 0
      if a * 10 + b <= N:
        n += 1
      if b * 10 + a <= N:
        m += 1
      for i in range(2, 6):
        n += check(a, b, i)
        m += check(b, a, i)
      ans += n * m
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())

def check(a, b, i):
  if (a + 1) * 10 ** i + b - 10 <= N:
    return 10 ** (i - 1)
  else:
    ret = 0
    for j in range(10 ** (i - 1)):
      if a * 10 ** i + j * 10 + a <= N:
        ret += 1
      else:
        return ret
ans = 0
for a in range(1, 10):
  for b in range(a, 10):
    if a == b:
      n = 0
      if a * 10 + b <= N:
        n += 2
      elif a <= N:
        ans += 1
      for i in range(2, 6):
        n += check(a, b, i)
      ans += n ** 2
    else:
      n, m = 0, 0
      if a * 10 + b <= N:
        n += 1
      if b * 10 + a <= N:
        m += 1
      for i in range(2, 6):
        n += check(a, b, i)
        m += check(b, a, i)
      ans += n * m * 2
print(ans)
Problem p02912 (python)

Fixed submission:
import heapq

def minus_int(s):
  return -1 * int(s)

N, M = map(int, input().split())
A = list(map(minus_int, input().split()))
heapq.heapify(A)
for _ in range(M):
  tmp = int(heapq.heappop(A) / 2)
  heapq.heappush(A, tmp)

print(sum(A) * (-1))

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

A.sort()
tmp = A.pop(-1)
index = 0
for _ in range(M):
  tmp //= 2
  if tmp < A[-1]:
    A.append(tmp)
    tmp = A.pop(-2)
    A.sort()
A.append(tmp)

print(sum(A))
Problem p02948 (python)

Fixed submission:
from heapq import heappush, heappop

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

for i in range(N):
  ab = list(map(int, input().split()))
  #Ai > M の仕事はいらない
  if ab[0] <= M:
    jobs[ab[0] - 1].append(ab[1])

#最終日はAi=1の仕事のみ選べる。その前の日はAi<=2, ...
#終わりから考えればよさそう
hq = []
ans = 0
for i in range(M):
  for b in jobs[i]:
    heappush(hq, -1 * b)
  if len(hq) > 0:
    m = -1 * heappop(hq)
    ans += m

print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

AB.sort(reverse = True, key = lambda x:x[1])
ans = 0
for i in range(1, M + 1):
  for j in range(len(AB)):
    if AB[j][0] <= i:
      ans += AB.pop(j)[1]
      break
    if AB[j][0] > M:
      AB.pop(j)

print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

for i in range(len(AB)):
  if AB[i][0] > M:
    AB.pop(i)

AB.sort(reverse = True, key = lambda x:x[1])
ans = 0
for i in range(1, M + 1):
  for j in range(len(AB)):
    if AB[j][0] <= i:
      ans += AB.pop(j)[1]
      break

print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

for i in range(N):
  if AB[i][0] > M:
    AB.pop(i)

AB.sort(reverse = True, key = lambda x:x[1])
ans = 0
for i in range(1, M + 1):
  for j in range(len(AB)):
    if AB[j][0] <= i:
      ans += AB.pop(j)[1]
      break

print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

AB.sort()
B = [[] for _ in range(M + 2)]
i = 1
j = 0
while i <= M:
  while j < N or AB[j][0] <= i:
    B[i].append(AB[j][1])
    j += 1
  B[i] = B[i - 1].copy()
  i += 1

ans = 0
for i in range(1, M + 1):
  if len(B[i]) > 0:
    m = max(B[i])
    ans += m
    for j in range(i, M + 1):
      if len(B[j]) > 0:
        B[j].remove(m)

print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

AB.sort()
B = [[] for _ in range(100005)]
tmp = 0
for ab in AB:
  if ab[0] != tmp:
    B[ab[0]] = B[tmp].copy()
  B[ab[0]].append(ab[1])
  tmp = ab[0]

for i in range(1, M + 1):
  if len(B[i]) == 0:
    B[i] = B[i - 1].copy()

ans = 0
for i in range(1, M + 1):
  if len(B[i]) > 0:
    m = max(B[i])
    ans += m
    for j in range(i, M + 1):
      if len(B[j]) > 0:
        B[j].remove(m)

print(ans)