Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
k=int(input())
l=[[1,2,3,4,5,6,7,8,9]]
for _ in range(10):
  a=[]
  for i in range(len(l[-1])):
    L=l[-1][i]
    if L%10==9:
      a.append(L*10+8)
      a.append(L*10+9)
    elif L%10==0:
      a.append(L*10+0)
      a.append(L*10+1)
    else:
      a.append(L*10+L%10-1)
      a.append(L*10+L%10)
      a.append(L*10+L%10+1)
    l.append(a)
print(sorted(set(list(itertools.chain.from_iterable(l))))[k-1])

Fixed submission:
from collections import deque
k=int(input())
l=deque([1,2,3,4,5,6,7,8,9])
for i in range(k-1):
  d=l.popleft()
  a=d%10
  if a!=0:
    l.append(d*10+a-1)
  l.append(d*10+a)
  if a!=9:
    l.append(d*10+a+1)
print(l.popleft())

Buggy python submission (verdict: Runtime Error):
import itertools
k=int(input())
l=[[1,2,3,4,5,6,7,8,9]]
for _ in range(10):
  a=[]
  for i in range(len(l[_])):
    L=l[_][i]
    if L%10==9:
      a.append(L*10+8)
      a.append(L*10+9)
    elif L%10==0:
      a.append(L*10+0)
      a.append(L*10+1)
    else:
      a.append(L*10+L%10-1)
      a.append(L*10+L%10)
      a.append(L*10+L%10+1)
    l.append(a)
print(sorted(set(list(itertools.chain.from_iterable(l))))[k-1])

Fixed submission:
from collections import deque
k=int(input())
l=deque([1,2,3,4,5,6,7,8,9])
for i in range(k-1):
  d=l.popleft()
  a=d%10
  if a!=0:
    l.append(d*10+a-1)
  l.append(d*10+a)
  if a!=9:
    l.append(d*10+a+1)
print(l.popleft())
Buggy python submission (verdict: Time Limit Exceeded):
n,x,y=map(int,input().split())
l=[]
r_append = l.append
for i in range(n-1):
  for k in range (i+1,n):
    if k<(x+y)//2-1 or i>(x+y)//2:
      r_append(k-i)
    else:
      r_append(min(abs(x-1-i)+abs(y-1-k)+1,k-i))
for i in range(1,n):
  print(l.count(i))

Fixed submission:
from collections import Counter
n,x,y=map(int,input().split())
l=[]
for i in range(n-1):
  for k in range (i+1,n):
      l.append(min(abs(x-1-i)+abs(y-1-k)+1,k-i))
S=Counter(l)
for i in range(1,n):
  print(S[i])

Buggy python submission (verdict: Time Limit Exceeded):
n,x,y=map(int,input().split())
l=[]
r_append = l.append
for i in range(n-1):
  for k in range (i+1,n):
    if k<x-1 or i>y-1:
      r_append(k-i)
    else:
      r_append(min(abs(x-1-i)+abs(y-1-k)+1,k-i))
for i in range(1,n):
  print(l.count(i))

Fixed submission:
from collections import Counter
n,x,y=map(int,input().split())
l=[]
for i in range(n-1):
  for k in range (i+1,n):
      l.append(min(abs(x-1-i)+abs(y-1-k)+1,k-i))
S=Counter(l)
for i in range(1,n):
  print(S[i])

Buggy python submission (verdict: Time Limit Exceeded):
n,x,y=map(int,input().split())
l=[]
r_append = l.append
for i in range(n-1):
  for k in range (i+1,n):
    if k<x-1 or i>y-1:
      r_append(k-i)
    else:
      r_append(min(abs(x-1-i)+abs(y-1-k)+1,k-i))
for i in range(1,n):
  print(l.count(i))

Fixed submission:
from collections import Counter
n,x,y=map(int,input().split())
l=[]
for i in range(n-1):
  for k in range (i+1,n):
      l.append(min(abs(x-1-i)+abs(y-1-k)+1,k-i))
S=Counter(l)
for i in range(1,n):
  print(S[i])

Buggy python submission (verdict: Time Limit Exceeded):
n,x,y=map(int,input().split())
l=[]
for i in range(n-1):
  for k in range (i+1,n):
    if k<x-1 or i>y-1:
      l.append(k-i)
    else:
      l.append(min(abs(x-1-i)+abs(y-1-k)+1,k-i))
for i in range(1,n):
  print(l.count(i))

Fixed submission:
from collections import Counter
n,x,y=map(int,input().split())
l=[]
for i in range(n-1):
  for k in range (i+1,n):
      l.append(min(abs(x-1-i)+abs(y-1-k)+1,k-i))
S=Counter(l)
for i in range(1,n):
  print(S[i])

Buggy python submission (verdict: Time Limit Exceeded):
n,x,y=map(int,input().split())
l=[]
for i in range(n-1):
  for k in range (i+1,n):
    if k<x-1 or i>y-1:
      l.append(k-i)
    else:
      l.append(min(abs(x-1-i)+abs(y-1-k)+1,k-i))
for i in range(1,n):
  print(l.count(i))
      

Fixed submission:
from collections import Counter
n,x,y=map(int,input().split())
l=[]
for i in range(n-1):
  for k in range (i+1,n):
      l.append(min(abs(x-1-i)+abs(y-1-k)+1,k-i))
S=Counter(l)
for i in range(1,n):
  print(S[i])

Buggy python submission (verdict: Time Limit Exceeded):
n,x,y=map(int,input().split())
l=[]
for i in range(n-1):
  for k in range (i+1,n):
      l.append(min(abs(x-1-i)+abs(y-1-k)+1,k-i))
for i in range(1,n):
  print(l.count(i))
      

Fixed submission:
from collections import Counter
n,x,y=map(int,input().split())
l=[]
for i in range(n-1):
  for k in range (i+1,n):
      l.append(min(abs(x-1-i)+abs(y-1-k)+1,k-i))
S=Counter(l)
for i in range(1,n):
  print(S[i])
Buggy python submission (verdict: Runtime Error):
import math
n=int(input())
l=[int(x) for x in input().split()]
for k in range(n):
  L=l.pop(k)
  ans=0
  for i in range(n+1):
    c=l.count(i)
    if c>1:
      ans=ans+math.factorial(c) // (math.factorial(c- 2) * 2)
  print(ans)
  l.insert(k,L)

Fixed submission:
import math
n,m=map(int,input().split())
if n>1:
  N=math.factorial(n) // (math.factorial(n - 2) * 2)
else:
  N=0
if m>1:
  M=math.factorial(m) // (math.factorial(m - 2) * 2)
else:
  M=0
print(N+M)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(1,1+n):
  c=a.count(i)
  ans+=(c*(c-1))//2
for k in range(n):
  c=a.count(a[k])
  print(ans-c+1)

Fixed submission:
N = int(input())
A = [int(x) for x in input().split()]
l = [0]*N
ans = 0
for a in A:
    l[a-1] += 1
for j in l:
    ans += int(j*(j-1)/2)
for k in range(N):
    print(ans - l[A[k]-1] + 1)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(1,1+n):
  c=a.count(i)
  ans+=(c*(c-1))//2
for k in range(n):
  c=a.count(a[k])
  print(ans-c+1)

Fixed submission:
N = int(input())
A = [int(x) for x in input().split()]
l = [0]*N
ans = 0
for a in A:
    l[a-1] += 1
for j in l:
    ans += int(j*(j-1)/2)
for k in range(N):
    print(ans - l[A[k]-1] + 1)

Buggy python submission (verdict: Time Limit Exceeded):
import math
n=int(input())
l=[int(x) for x in input().split()]
for k in range(n):
  L=l.pop(k)
  ans=0
  for i in range(n+1):
    c=l.count(i)
    if c>1:
      ans=ans+math.factorial(c) // (math.factorial(c- 2) * 2)
  print(ans)
  l.insert(k,L)

Fixed submission:
N = int(input())
A = [int(x) for x in input().split()]
l = [0]*N
ans = 0
for a in A:
    l[a-1] += 1
for j in l:
    ans += int(j*(j-1)/2)
for k in range(N):
    print(ans - l[A[k]-1] + 1)

Buggy python submission (verdict: Time Limit Exceeded):
import math
n=int(input())
l=[int(x) for x in input().split()]
for k in range(n):
  L=l.pop(k)
  ans=0
  for i in range(n+1):
    c=l.count(i)
    if c>1:
      ans=ans+math.factorial(c) // (math.factorial(c- 2) * 2)
  print(ans)
  l.insert(k,L)

Fixed submission:
N = int(input())
A = [int(x) for x in input().split()]
l = [0]*N
ans = 0
for a in A:
    l[a-1] += 1
for j in l:
    ans += int(j*(j-1)/2)
for k in range(N):
    print(ans - l[A[k]-1] + 1)

Buggy python submission (verdict: Time Limit Exceeded):
import math
n=int(input())
l=[int(x) for x in input().split()]
for k in range(n):
  L=l.pop(k)
  ans=0
  for i in range(n+1):
    c=l.count(i)
    if c>1:
      ans=ans+math.factorial(c) // (math.factorial(c- 2) * 2)
  print(ans)
  l.insert(k,L)
    
    

Fixed submission:
N = int(input())
A = [int(x) for x in input().split()]
l = [0]*N
ans = 0
for a in A:
    l[a-1] += 1
for j in l:
    ans += int(j*(j-1)/2)
for k in range(N):
    print(ans - l[A[k]-1] + 1)
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
i=1
while True:
  if (int(i*0.08)==a and i(i*0.1)==b):
    print(i)
    exit()
  if i>200:
    print(-1)
    exit()
  i=i+1

Fixed submission:
a,b=map(int,input().split())
for i in range(2000):
  if int(i*0.08)==a and int(i*0.1)==b:
    print(i)
    exit()
print(-1)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
s = [0] * m
c = [0] * m
for i in range(m):
    s[i], c[i] = map(int, input().split())
l=[]
for i in range(m):
  for k in range(i+1,m):
    if s[i]==s[k] and c[i]!=c[k]:
      print(-1)
      exit()
    if s[i]==s[k] and c[i]==c[k]:
      l.append(k)
for i in range(len(l)):
  del s[l[i]]
  del c[l[i]]
ans=0
for i in range(len(s)):
  ans+=c[i]*(10**(n-s[i]))
if ans%(10**n)==0:
  print(ans+10**n)
else:
  print(ans)

Fixed submission:
N, M=map(int,input().split())
num=[list(map(int,input().split())) for i in range(M)]
 
for i in range(1000):
    n=str(i)
    if len(n)!=N:
        continue
    if all([n[s-1]==str(c) for s,c in num]):
        print(n)
        break
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
s=k
if k>n:
  print(i)
  exit()
for i in range(1000000):
  s*=k
  if s>n:
    print(i+2)
    exit()

Fixed submission:
n,k=map(int,input().split())
for i in range(100000000000):
  if k**i>n:print(i);exit()
Buggy python submission (verdict: Runtime Error):
n=int(input())
M=list(map(int,input().split()))
m=sorted(M)
l=[]
for p in range(m[0],m[n-1]):
  L=0
  for i in range(n):
    L+=(m[i]-p)**2
  l.append(L)
print(min(l))

Fixed submission:
n=int(input())
M=list(map(int,input().split()))
m=sorted(M)
l=[]
for p in range(m[0],m[n-1]+1):
  L=0
  for i in range(n):
    L+=(m[i]-p)**2
  l.append(L)
print(min(l))
Buggy python submission (verdict: Runtime Error):
list=[int(input()) for i in range(3)]
print("Yes" if len(set(list))=2 else "No")

Fixed submission:
s=list(set(input().split()))
if len(s)==2:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
list=[int(input()) for i in range(3)]
print(len(set(list)))

Fixed submission:
s=list(set(input().split()))
if len(s)==2:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
s,t=map(input().split())
a,b=map(int,input().split())
u=input()
if s==u:
  print(a-1,b)
else:
  print(a,b-1)

Fixed submission:
s,t=input().split()
a,b=map(int,input().split())
u=input()
if s==u:
  print(a-1,b)
else:
  print(a,b-1)
Buggy python submission (verdict: Runtime Error):
s=input()
print(x*len(s))

Fixed submission:
s=input()
print("x"*len(s))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
from collections import deque
import math
import bisect
import sys
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))


h,n=mp()
magic=[lmp() for i in range(n)]
dp=[float("inf")]*(h+1)
dp[0]=0
for i in range(h):
    for k in range(n):
        ni=min(i+magic[k][0],h)
        dp[ni]=min(dp[ni],dp[i]+magic[k][1])
print(dp[-1])

Fixed submission:
from collections import Counter
from collections import deque
import math
import bisect
import sys
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))


h,n=mp()
magic=[lmp() for i in range(n)]
dp=[float("inf")]*(h+1)
dp[0]=0
for i in range(h):
    for k in range(n):
        ni=min(i+magic[k][0],h)
        dp[ni]=min(dp[ni],dp[i]+magic[k][1])
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
s=input()
l=[0]*1000
for _ in range(n):
    i=s[_]
    for j in range(1000):
        k=str(j).zfill(3)
        if k[0]==i:
            if l[j]==2:
                l[j]=3
        if k[1]==i:
            if l[j]==1:
                l[j]=2
        if k[2]==i:
            if l[j]==0:
                l[j]=1
ans=0
for i in l:
    if i==3:
        ans+=1
print(ans)

Fixed submission:
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
s=input()
l=[0]*1000
for _ in range(n):
    i=s[_]
    for j in range(1000):
        k=str(j).zfill(3)
        if k[0]==i:
            if l[j]==2:
                l[j]=3
        if k[1]==i:
            if l[j]==1:
                l[j]=2
        if k[2]==i:
            if l[j]==0:
                l[j]=1
ans=0
for i in l:
    if i==3:
        ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=list(input())
s.pop(n)
print(s.append(s.pop(n)))

Fixed submission:
N = int(input())
S = [i for i in input()]
alpha=['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
ans=''
for c in S:
    cnt = alpha.index(c)+N
    if cnt > 25:
        cnt=cnt-26
    c = alpha[cnt]
    ans+=c
print(ans)

Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
s.pop(n)
print(s.append(s.pop(n)))

Fixed submission:
N = int(input())
S = [i for i in input()]
alpha=['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
ans=''
for c in S:
    cnt = alpha.index(c)+N
    if cnt > 25:
        cnt=cnt-26
    c = alpha[cnt]
    ans+=c
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
if n%2==1:
  print("No")
  exit()
for i in range((n//2)-1):
  if a[i]!=a[-i-1]:
    print("No")
    exit()
print("Yes")

Fixed submission:
n=int(input())
s=input()
if n%2==1:
  print("No")
  exit()
for i in range(n//2):
  if s[i]!=s[n//2+i]:
    print("No")
    exit()
print("Yes")

Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
if n%2!=0:
  print("No")
  exit()
for i in range(n//2+1):
  if a[i]!=a[-i-1]:
    print("No")
    exit()
print("Yes")

Fixed submission:
n=int(input())
s=input()
if n%2==1:
  print("No")
  exit()
for i in range(n//2):
  if s[i]!=s[n//2+i]:
    print("No")
    exit()
print("Yes")

Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
l=len(s)
s2=s.pop(l//2)
print("Yes" if s==s2 else "No")
  

Fixed submission:
n=int(input())
s=input()
if n%2==1:
  print("No")
  exit()
for i in range(n//2):
  if s[i]!=s[n//2+i]:
    print("No")
    exit()
print("Yes")
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
if a-2b>0:
  print(a-2b)
else:
  print(0)

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

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n=int(input())
l = sorted(list(map(int, input().split())))
ans=0
for i in range(n):
  for k in range(i+1,n):
    for _ in range(k+1,n):
      if -l[i]+l[k]>=l[_]:
        continue
      elif l[i]+l[k]<=l[_]:
        break
      else:
        ans+=1
print(ans)

Fixed submission:
a,b=map(int,input().split())
if a-2*b>0:
  print(a-2*b)
else:
  print(0)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n=int(input())
l = list(map(int, input().split()))
l=sorted(l)
ans=0
for i in range(n):
  for k in range(i+1,n):
    for _ in range(k+1,n):
      if -l[i]+l[k]>=l[_]:
        continue
      elif l[i]+l[k]<=l[_]:
        break
      else:
        ans+=1
print(ans)

Fixed submission:
import bisect
n=int(input())
l=list(map(int,input().split()))
l=sorted(l)
ans=0
for i in range(n-2):
  for k in range(i+1,n-1):
    ans+=bisect.bisect_left(l,l[i]+l[k])-k-1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n=int(input())
l = list(map(int, input().split()))
l=sorted(l)
ans=0
for i in range(n):
  for k in range(i+1,n):
    for _ in range(k+1,n):
      if -l[i]+l[k]>=l[_]:
        continue
      elif l[i]+l[k]<=l[_]:
        break
      else:
        ans+=1
print(ans)

Fixed submission:
import bisect
n=int(input())
l=list(map(int,input().split()))
l=sorted(l)
ans=0
for i in range(n-2):
  for k in range(i+1,n-1):
    ans+=bisect.bisect_left(l,l[i]+l[k])-k-1
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
from collections import Counter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

h,w,a,b=mp()
if h==1 and b==0:
    print("1"*a+"0"*(5-a))
elif w==1 and a==0:
    for i in range(b):
        print("1")
    for i in range(h-b):
        print("0")
elif a*h==b*w:
    for i in range(h//b):
        for k in range(b):
            print("0"*(i*a)+"1"*a+"0"*((h//b-i-1)*a))
else:
    print("No")

Fixed submission:
import sys
from collections import Counter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

h,w,a,b=mp()
for i in range(b):
    print("1"*a+"0"*(w-a))
for i in range(h-b):
    print("0"*a+"1"*(w-a))
Buggy python submission (verdict: Time Limit Exceeded):
n,k,q=map(int,input().split())
a=[int(input()) for i in range(q)]
ans=["No"]*n
for i in range(n):
    if a.count(i+1)>q-k:
        ans[i]="Yes"
for i in range(n):
    print(ans[i])

Fixed submission:
from collections import Counter
n,k,q=map(int,input().split())
a=[int(input()) for i in range(q)]
c=Counter(a)
ans=["No"]*n
for i in range(n):
    if c[i+1]>q-k:
        ans[i]="Yes"
for i in range(n):
    print(ans[i])
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=sorted(list(map(int,input().split())))
for i in range(m):
  a[-1]=a[-1]//2
  a=sorted(a)
print(sum(a))

Fixed submission:
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,m=mp()
a=lmp()
l=[]
heapq.heapify(l)
for i in a:
    heapq.heappush(l,(-1)*i)
for i in range(m):
    j=heapq.heappop(l)
    heapq.heappush(l,-(-j//2))
print(-sum(l))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import Counter
from collections import deque
import heapq
import math
import fractions
import bisect
import itertools
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,q=mp()
tree=[[] for i in range(n+1)]
c=[0]*(n+1)
done=[0]*(n+1)
for i in range(n-1):
    a,b=mp()
    tree[a].append([a,b])
    tree[b].append([b,a])
for i in range(q):
    p,x=mp()
    c[p]+=x
que=deque()
que.append(tree[1])
done[1]=1
while len(que):
    q=que.popleft()
    for v in q:
        if done[v[1]]==0:
            done[v[1]]=1
            c[v[1]]+=c[v[0]]
            que.append(tree[v[1]])
print(*c[1:])

Fixed submission:
import sys
from collections import Counter
from collections import deque
import heapq
import math
import fractions
import bisect
import itertools
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,q=mp()
tree=[[] for i in range(n+1)]
c=[0]*(n+1)
done=[0]*(n+1)
for i in range(n-1):
    a,b=mp()
    tree[a].append([a,b])
    tree[b].append([b,a])
for i in range(q):
    p,x=mp()
    c[p]+=x
que=deque()
que.append(tree[1])
done[1]=1
while len(que):
    q=que.popleft()
    for v in q:
        if done[v[1]]==0:
            done[v[1]]=1
            c[v[1]]+=c[v[0]]
            que.append(tree[v[1]])
print(*c[1:])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import Counter
from collections import deque
import math
import fractions
import bisect
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,m=mp()
l=[lmp() for i in range(n)]
l.append([10**6,10**6])
val=[]
ans=0
l=sorted(l,key=lambda x: x[0],reverse=True)
for i in range(1,m+1):
    while l[-1][0]==i:
        q=l.pop()
        val.append(q[1])
    val.sort()
    if len(val):
        ans+=val.pop()
print(ans)

Fixed submission:
import sys
from collections import Counter
from collections import deque
import heapq
import math
import fractions
import bisect
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,m=mp()
l=[lmp() for i in range(n)]
l.append([10**6,10**6])
val=[]
heapq.heapify(val)
ans=0
c=0
l=sorted(l,key=lambda x: x[0],reverse=True)
for i in range(1,m+1):
    while l[-1][0]==i:
        q=l.pop()
        heapq.heappush(val,(-1)*q[1])
        c+=1
    if c>0:
        ans-=heapq.heappop(val)
        c-=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import Counter
from collections import deque
import math
import fractions
import bisect
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,m=mp()
l=[lmp() for i in range(n)]
l.append([10**6,10**6])
val=[]
ans=0
l=sorted(l,key=lambda x: x[0],reverse=True)
for i in range(1,m+1):
    while l[-1][0]==i:
        q=l.pop()
        val.append(q[1])
    val.sort()
    if len(val)>0:
        ans+=val.pop()
print(ans)

Fixed submission:
import sys
from collections import Counter
from collections import deque
import heapq
import math
import fractions
import bisect
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,m=mp()
l=[lmp() for i in range(n)]
l.append([10**6,10**6])
val=[]
heapq.heapify(val)
ans=0
c=0
l=sorted(l,key=lambda x: x[0],reverse=True)
for i in range(1,m+1):
    while l[-1][0]==i:
        q=l.pop()
        heapq.heappush(val,(-1)*q[1])
        c+=1
    if c>0:
        ans-=heapq.heappop(val)
        c-=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
l,r=map(int,input().split())
if r%2019<l%2019:
  print(0)
  exit()
L=[]
for i in range(l,r+1):
  for k in range(i+1,r+1):
    L.append((i*k)%2019)
print(min(L))

Fixed submission:
import sys
from collections import Counter
from collections import deque
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

l,r=mp()
if l//2019 != r//2019:
    print(0)
    exit()
ans=10000
for i in range(l,r):
    for k in range(i+1,r+1):
        ans=min(ans,(i*k)%2019)
print(ans)
Buggy python submission (verdict: Runtime Error):
from functools import lru_cache
n,m=map(int,input().split())
a=[int(input()) for _ in range(m)]
a=sorted(a)
@lru_cache(maxsize=None) 
def fib(n): 
    if n <= 1:
        return 1
    else:
        return fib(n - 2) + fib(n - 1)
ans=fib(a[0])*fib(n-a[-1])
for i in range(1,m):
  if a[i]-a[i-1]==1:
    print(0)
    exit()
  elif m==1:
    print(ans)
    exit()
  ans=ans*fib(a[i]-a[i-1]-1)
print(ans%1000000007)

Fixed submission:
import sys
from collections import Counter
from collections import deque
import heapq
import math
import fractions
import bisect
import itertools
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

mod=1000000007
n,m=mp()
dp=[0]*(n+2)
dp[0]=1
for i in range(m):
    a=int(input())
    dp[a]=-1
for i in range(n):
    if dp[i]==-1:
        continue
    if dp[i+1]>=0:
        dp[i+1]+=dp[i]
        dp[i+1]=dp[i+1]%mod
    if dp[i+2]>=0:
        dp[i+2]+=dp[i]
        dp[i+2]=dp[i+2]%mod
print(dp[-2]%mod)