Harryxun/stf_run huggingface dataset:
import numpy as np
N, Q = [int(x) for x in input().split()]
STX = np.zeros((N, 3))
for i in range(N):
    STX[i, 0], STX[i, 1], STX[i, 2] = [int(x) for x in input().split()]
D = [int(input()) for _ in range(Q)]
STX = STX[np.argsort(STX[:, 2])]

for d in D:
    STX_copy = np.copy(STX)
    STX_copy[:, :2] = STX_copy[:, :2] - d
    try:
        print(int(STX_copy[np.where((STX_copy[:, 0] - 0.5 <= STX_copy[:, 2]) & (STX_copy[:, 1] - 0.5 >= STX_copy[:, 2]))][0, 2]))
    except:
        print(-1)


### FIXED CODE ###

A, P = map(int, input().split())
print((3 * A + P) // 2)
N=int(input());print("Three" if len(set(map(input().split())))==3 else "Four")

### FIXED CODE ###

N=int(input());print("Three" if len(set(input().split()))==3 else "Four")
if n % k == 0:
    print('0')
else:
    print('1')

### FIXED CODE ###

n, k = map(int, input().split())

if n % k == 0:
    print('0')
else:
    print('1')
I=lambda:map(int,input().split())
N,M=I()
r=range(N)
m={i:0 for i in r}
for _ in[0]*M:a,b=I();m[a]+=+1;m[b]+=1
for i in r:print(m[i])

### FIXED CODE ###

I=lambda:map(int,input().split())
N,M=I()
r=range(N)
m={i:0 for i in r}
for _ in[0]*M:
  a,b=I()
  m[a-1]+=1
  m[b-1]+=1
for i in r:print(m[i])
A,B,K = map(int, input().split())
var = list(range(A, B + 1))
ans = var[0:K]
ans += var[-K:]
ans = set(ans)
for i in ans:
    print(i)


### FIXED CODE ###

A,B,K = map(int, input().split())
lcnt = 0
rcnt = 0
ans = []
for i in range(A, min(A + K, B)):
    ans.append(i)

for i in range(max(B - K + 1, A), B + 1):
    ans.append(i)

set_ans = list(set(ans))
set_ans.sort()
for i in set_ans:
    print(i)
# 整数の入力
N = int(input())
A = [int(a) for a in input().split()]
Q = int(input())
process = []
proc_append = process.append
hash = [0]*100000
for i in range(Q):
    proc_append(tuple(input().split()))
    process[i] = tuple(map(int,process[i]))

goukei = sum(A)

for i in A:
	hash[i] += 1

for b,c in process:
	if hash[b] != 0:
		goukei += (c-b)*hash[b]
		hash[c] += hash[b]
		hash[b] = 0
	print(goukei)

### FIXED CODE ###

# 整数の入力
N = int(input())
A = [int(a) for a in input().split()]
Q = int(input())
process = []
proc_append = process.append
hash = [0]*100001
for i in range(Q):
    proc_append(tuple(input().split()))
    process[i] = tuple(map(int,process[i]))

goukei = sum(A)

for i in A:
	hash[i] += 1

for b,c in process:
	if hash[b] != 0:
		goukei += (c-b)*hash[b]
		hash[c] += hash[b]
		hash[b] = 0
	print(goukei)
# -*- coding: utf-8 -*-
"""
Created on Fri Aug  9 00:23:59 2019

@author: miz18
"""

import sys
input = sys.stdin.readline

def main(): 
    N,Q = list(map(int,input().split()))
     
    road = []
    r_append = road.append
    x_list = []
    x_append = x_list.append
    for i in range(N):
        s,t,x = list(map(int,input().split()))
        r_append(("s",s-x,x,0))
        r_append(("t",t-x,x,0))
        x_append.append(x)
     
    for i in range(Q):
        d = int(input())
        r_append(("m",d,i,1))
     
    road.sort(lambda x:x[3])
    road.sort(lambda x:x[1])
     
    x_list = list(set(x_list))
    x_list.sort()
     
    x2i_dict = {}
    for i,x in enumerate(x_list):
        x2i_dict[x]=i
     
     
    class BIT:
                
        def __init__(self, L):
            self.N = len(L)
            self.bit = [0]*self.N
            for i,l in enumerate(L):
                self.add(i,l)
     
        def add(self, a, w):
            x = a + 1
            for i in range(1000):
                self.bit[x-1] += w
                x += x & -x
                if x > self.N:
                    break
     
        def sum(self, a):
            x = a+1
            ret = 0
            for i in range(1000):
                ret += self.bit[x-1]
                x -= x & -x
                if x <= 0:
                    break        
            return ret
     
    def bisectR(l,r,bit):
        while r-l>1:
            if bit.sum((l+r)//2)>0:
                r = (l+r)//2
            else:
                l = (l+r)//2
        return r
     
    
     
    bit = BIT([0]*len(x_list))
    b_add = bit.add
    
    ans = [0]*Q
    for r in road:
        if r[0]=="s":
            b_add(x2i_dict[r[2]],1)
        elif r[0]=="t":
            b_add(x2i_dict[r[2]],-1)
        else:
            if bit.sum(len(x_list)-1)==0:
                ans[r[2]]=-1
            elif bit.sum(0)>0:
                ans[r[2]]=x_list[0]
            else:
                i = bisectR(0,len(x_list)-1,bit)
                ans[r[2]] = x_list[i]
     
    for a in ans:
        print(a)
        
if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys

sys.setrecursionlimit(500000)
def input():
    return sys.stdin.readline()[:-1]

def main():
    N,Q = list(map(int,input().split()))

    road = []
    x_list = []

    for i in range(N):
        s,t,x = list(map(int,input().split()))
        road.append([0,s-x,x])
        road.append([1,t-x,x])

    for i in range(Q):
        road.append([2,int(input()),i])

    from collections import defaultdict

    counter = defaultdict(int)
    counter[10**27] = 1
    ans = [0]*Q

    road.sort(key=lambda x:x[0])
    road.sort(key=lambda x:x[1])

    q = [10**27]

    from heapq import heappop,heappush

    for id,_,x in road:
        if id==0:
            heappush(q,x)
            counter[x]+=1
        elif id==1:
            counter[x]-=1
        else:
            while counter[q[0]]==0:
                heappop(q)
            #print(q)
            if q[0]<10**27:
                ans[x] = q[0]
            else:
                ans[x] = -1
    print("\n".join(map(str,ans)))

if __name__ == '__main__':
    main()
a = int(input())
l = list(map(int, input().split()))
x = l.sorted()
for i in range(a):
  if x[i] ==l[i]:
    b +=1
if b ==2:
  print('YES')
else:
  print('NO')

### FIXED CODE ###

a = int(input())
l = list(map(int, input().split()))
x = sorted(l)
b =0
for i in range(a):
  if x[i] !=l[i]:
    b +=1
if b ==2 or b ==0:
  print('YES')
else:
  print('NO')
N = int(input())
ab = [tuple(map(int,input().split())) for _ in range(N - 1)]
M = int(input())
uv = [tuple(map(int,input().split())) for _ in range(M)]
route = [[] for _ in range(N)]

for i, (a, b) in enumerate(ab):
    a -= 1
    b -= 1
    route[a].append((b, i))
    route[b].append((a, i))

path = [0] * M
for i, (u, v) in enumerate(uv):
    u -= 1
    v -= 1
    stack = [u]
    visited = [0] * N
    visited[u] = 1
    dire = [[] for _ in range(N)]
    while True:
        s = stack.pop()
        for g, j in route[s]:
            if visited[g]:
                continue   
            stack.append(g)
            dire[g].append((s, j))
            visited[g] = 1
        if visited[v]:
            break
    s = v
    while True:
        g, num = dire[s][0]
        path[i] |= (1 << num)
        if g == u:
            break
        s = g

data = [0] * (1 << M)
ans = 2 ** (N - 1)
for i in range(1, a << M):
    k = len(bin(i)) - 3
    data[i] = data[i - (2 ** k)] | path[k]
    power = bin(data[i]).count("1")
    judge = bin(i).count("1")
    ans += (-2 ** (N - 1 - power) if judge % 2 else 2 ** (N - 1 - power))
print(ans)

### FIXED CODE ###

N = int(input())
ab = [tuple(map(int,input().split())) for _ in range(N - 1)]
M = int(input())
uv = [tuple(map(int,input().split())) for _ in range(M)]
route = [[] for _ in range(N)]

for i, (a, b) in enumerate(ab):
    a -= 1
    b -= 1
    route[a].append((b, i))
    route[b].append((a, i))

path = [0] * M
for i, (u, v) in enumerate(uv):
    u -= 1
    v -= 1
    stack = [u]
    visited = [0] * N
    visited[u] = 1
    dire = [[] for _ in range(N)]
    while True:
        s = stack.pop()
        for g, j in route[s]:
            if visited[g]:
                continue   
            stack.append(g)
            dire[g].append((s, j))
            visited[g] = 1
        if visited[v]:
            break
    s = v
    while True:
        g, num = dire[s][0]
        path[i] |= (1 << num)
        if g == u:
            break
        s = g

data = [0] * (1 << M)
ans = 2 ** (N - 1)
for i in range(1, 1 << M):
    k = len(bin(i)) - 3
    data[i] = data[i - (2 ** k)] | path[k]
    power = bin(data[i]).count("1")
    judge = bin(i).count("1")
    ans += (-2 ** (N - 1 - power) if judge % 2 else 2 ** (N - 1 - power))
print(ans)
n = int(input())
arr = list(map(int, input().split()))

a = [arr[i] for i in range(0,n,2)]
b = [arr[y] for y in range(1,n,2)]

import collections
acnt = collections.Counter(a)
bcnt = collections.Counter(b)

lsacnt = sorted(acnt.items(), key=lambda x: x[1])
lsbcnt = sorted(bcnt.items(), key=lambda y: y[1])

def val(abcnt, ablscnt):
	if len(list(abcnt)) < 2:
		return ablscnt[1][1]
	else:
		return 0

if lsacnt[0][0] != lsbcnt[0][0]:
	ans = n - lsacnt[0][1] - lsbcnt[0][1]
elif lsacnt[0][0] == lsbcnt[0][0]:
	if lsacnt[0][1] >= lsbcnt[0][1]:
		ans = n - lsacnt[0][0] - val(bcnt,lsbcnt)
	else:
		ans = n - val(acnt,lsbcnt) - lsbcnt[0][0]

print(ans)
	

	

### FIXED CODE ###

n = int(input())
arr = list(map(int, input().split()))

a = [arr[i] for i in range(0,n,2)]
b = [arr[y] for y in range(1,n,2)]

import collections
acnt = collections.Counter(a)
bcnt = collections.Counter(b)

lsacnt = sorted(acnt.items(), key=lambda x: x[1],reverse=True)
lsbcnt = sorted(bcnt.items(), key=lambda j: j[1],reverse=True)

def val(abcnt, ablscnt):
	if len(list(abcnt)) < 2:
		return 0
	else:
		return ablscnt[1][1]

if lsacnt[0][0] != lsbcnt[0][0]:
	ans = n - lsacnt[0][1] - lsbcnt[0][1]
elif lsacnt[0][0] == lsbcnt[0][0]:
	if lsacnt[0][1] > lsbcnt[0][1]:
		ans = n - lsacnt[0][1] - val(bcnt,lsbcnt)
	elif lsacnt[0][1] < lsbcnt[0][1]:
		ans = n - val(acnt,lsacnt) - lsbcnt[0][1]
	elif lsacnt[0][1] == lsbcnt[0][1]:
		ans = n - lsacnt[0][1] - max(val(acnt,lsacnt),val(bcnt,lsbcnt))

print(ans)
from itertools import zip_longest

def twoAnagrams(s, t):
    s_str = ''.join(sorted(s))
    t_str = ''.join(sorted(t, reverse=True))

    if t_str.startswith(s_str):
        if len(s_str) < len(t_str):
            return True
        # this implies s and t is the same string
        else:
            return False

    for s_chr,t_chr in zip_longest(s_str, t_str):
        if s_chr is None:
            return True
        elif t_chr is None or t_chr < s_chr:
            return False
        else s_chr < t_chr:
            return True


s = list(input())
t = list(input())

print('Yes' if twoAnagrams(s,t) else 'No')


### FIXED CODE ###

from itertools import zip_longest

def twoAnagrams(s, t):
    s_str = ''.join(sorted(s))
    t_str = ''.join(sorted(t, reverse=True))

    if t_str.startswith(s_str):
        if len(s_str) < len(t_str):
            return True
        # this implies s and t is the same string
        else:
            return False

    for s_chr,t_chr in zip_longest(s_str, t_str):
        if s_chr is None:
            return True
        elif t_chr is None or t_chr < s_chr:
            return False
        elif s_chr < t_chr:
            return True


s = list(input())
t = list(input())

print('Yes' if twoAnagrams(s,t) else 'No')
def F(n):
    if n < 3:
        return 0
    elif n < 6:
        return 1
    else:
        return F(n - 2) + F(n - 3) + F(n - 4)
    
    
s = int(input())
print(F(s) % (10 ** 9 + 7))


### FIXED CODE ###

S = int(input())
DP = [0] * (S + 1)
Mod = 10 ** 9 + 7

if S >= 3:
    DP[0] = 1
    DP[1] = 0
    DP[2] = 0
    for TS in range(3,S+1):
        DP[TS] = DP[TS-1] + DP[TS-3]
    print(DP[S] % Mod)
else:
    print(0)
N,M=map(int,input().split())
store=[]
for _ in range(N):
  store.append([map(int,input().split())])
store.sort(key=lambda x: x[0])
res=0
for i in range(len(store)):
  price=store[i][0]
  num=store[i][1]
  if M>num:
    res+=price*num
    M-=num
  else:
    res+=price*M
    break
print(res)


### FIXED CODE ###

N, M = map(int, input().split())
shop = []
for i in range(N):
    a, b = map(int, input().split())
    shop.append([a, b])
shop.sort(key=lambda x: x[0])

amount = 0
quantity = 0
for s in shop:
    if quantity + s[1] < M:
        amount += s[0] * s[1]
        quantity += s[1]
    else:
        amount += (M - quantity) * s[0]
        quantity = M
        break

print(amount)
a,b,c=list(map(int,input().split()))
if b-a==c-b:print(YES)
else:print(NO)

### FIXED CODE ###

a,b,c=list(map(int,input().split()))
if b-a==c-b:print('YES')
else:print('NO')
r = float(input())
print '%f %f' % (2*math.pi*r, math.pi*r^2)

### FIXED CODE ###

import math
r = float(input())
print '%f %f' % (math.pi*r*r, 2*math.pi*r)
a=input()

b=a%10
c=a%100
d=a%1000
e=a%10000


if a%10==0:
print(5)
elif (a-b)%100==0
print(4)
elif (a-c)%1000==0
print(3)
elif (a-d)%10000==0
print(2)
else
print(1)

### FIXED CODE ###

import math
from collections import deque
from collections import defaultdict
import itertools as it
 
#自作関数群
def readInt():
 return int(input())
def readInts():
 return list(map(int, input().split()))
def readChar():
 return input()
def readChars():
 return input().split()
def factorization(n):
 res = []
 if n%2==0:
  res.append(2)
 for i in range(3,math.floor(n//2)+1,2):
  if n%i==0:
   c = 0
   for j in res:
    if i%j==0:
     c=1
   if c==0:
    res.append(i)
 return res
def fact2(n):
 p = factorization(n)
 res = []
 for i in p:
  c=0
  z=n
  while 1:
   if z%i==0:
    c+=1
    z/=i
   else:
    break
  res.append([i,c])
 return res
def fact(n):#階乗
 ans = 1
 m=n
 for _i in range(n-1):
  ans*=m
  m-=1
 return ans
def comb(n,r):#コンビネーション
 if n<r:
  return 0
 l = min(r,n-r)
 m=n
 u=1
 for _i in range(l):
  u*=m
  m-=1
 return u//fact(l)
def combmod(n,r,mod):
 return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
 r=copyQueue(q)
 ans=[0]*r.qsize()
 for i in range(r.qsize()-1,-1,-1):
  ans[i] = r.get()
 print(ans)
class UnionFind():
 def __init__(self, n):
  self.n = n
  self.parents = [-1]*n
 
 def find(self, x): # root
  if self.parents[x]<0:
   return x
  else:
   self.parents[x] = self.find(self.parents[x])
   return self.parents[x]
 
 def union(self,x,y):
  x = self.find(x)
  y = self.find(y)
 
  if x==y:
   return
 
  if self.parents[x]>self.parents[y]:
   x,y = y,x
 
  self.parents[x]+=self.parents[y]
  self.parents[y]=x
 
 def size(self,x):
  return -1*self.parents[self.find(x)]
 
 def same(self,x,y):
  return self.find(x)==self.find(y)
 
 def members(self,x): # much time
  root = self.find(x)
  return [i for i in range(self.n) if self.find(i)==root]
 
 def roots(self):
  return [i for i,x in enumerate(self.parents) if x<0]
 
 def group_count(self):
  return len(self.roots())
 
 def all_group_members(self):
  return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
 x = 1
 zero = "0"*n
 ans = []
 ans.append([0]*n)
 for i in range(2**n-1):
  ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
  x+=1
 return ans;
def arrsSum(a1,a2):
 for i in range(len(a1)):
  a1[i]+=a2[i]
 return a1
def maxValue(a,b,v):
 v2 = v
 for i in range(v2,-1,-1):
  for j in range(v2//a+1): #j:aの個数
   k = i-a*j
   if k%b==0:
    return i
 return -1
def copyQueue(q):
 nq = queue.Queue()
 n = q.qsize()
 for i in range(n):
  x = q.get()
  q.put(x)
  nq.put(x)
 return nq
def get_sieve_of_eratosthenes(n):
 #data = [2]
 data = [0,0,0]
 for i in range(3,n+1,2):
  data.append(i)
  data.append(0)
 for i in range(len(data)):
  interval = data[i]
  if interval!=0:
   for j in range(i+interval,n-1,interval):
    data[j] = 0
 #ans = [x for x in data if x!=0]
 ans = data[:]
 return ans
 
x = readInts()
 
for i in range(1,6):
 if x[i-1]!=i:
  print(i)
class Combination:
    """
  O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
  n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
  使用例：
  comb = Combination(1000000)
  print(comb(5, 3))  # 10
  """

    def __init__(self, n_max, mod=10 ** 9 + 7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]

        facinv = [1]
        for i in range(1, n + 1):
            fac.append(fac[i - 1] * i % self.mod)
            facinv.append(facinv[i - 1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n + 1)
        modinv[1] = 1
        for i in range(2, n + 1):
            modinv[i] = self.mod - self.mod // i * \
                modinv[self.mod % i] % self.mod
        return modinv


MOD = 10**9 + 7

r1, c1, r2, c2 = map(int, input().split())
c = Combination(100000)
ans = 0
for r in range(r1, r2 + 1):
    temp = c(c2 + r + 1, r + 1) - c(c1 + r + 1 - 1, r + 1)
    temp %= MOD
    ans += temp
    ans %= MOD
print(ans)


### FIXED CODE ###

class Combination:
    """
  O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
  n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
  使用例：
  comb = Combination(1000000)
  print(comb(5, 3))  # 10
  """

    def __init__(self, n_max, mod=10 ** 9 + 7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]

        facinv = [1]
        for i in range(1, n + 1):
            fac.append(fac[i - 1] * i % self.mod)
            facinv.append(facinv[i - 1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n + 1)
        modinv[1] = 1
        for i in range(2, n + 1):
            modinv[i] = self.mod - self.mod // i * \
                modinv[self.mod % i] % self.mod
        return modinv


MOD = 10**9 + 7

r1, c1, r2, c2 = map(int, input().split())
c = Combination(2000006)
ans = 0
for r in range(r1, r2 + 1):
    temp = c(c2 + r + 1, r + 1) - c(c1 + r + 1 - 1, r + 1)
    temp %= MOD
    ans += temp
    ans %= MOD
print(ans)
import sys
INF = (sys.maxint)/3

def SmallestWindow(S, a_list):
	i = 0
	j = 0
	tmpS = 0
	res = INF
	while 1 :
		while tmpS < S and i <len(a_list):
			i +=1
			tmpS += a_list[i]
		if (tmpS <S):
			break
		res = min (res, i-j)
		j += 1
		tmpS -=a_list[j]
	if res == INF:
		res = 0
	return res
		

def main():
	N, S = map(int, raw_input().split())
	a_list = map(int, raw_input().split())
	print SmallestWindow(S, a_list)

if __name__ == '__main__':
	main()

### FIXED CODE ###

import sys
INF = (sys.maxint)/3

def SmallestWindow(S, a_list):
	i = 0
	j = 0
	tmpS = 0
	res = INF
	while 1 :
		while tmpS < S and i <len(a_list):
			tmpS += a_list[i]
			i = i+1
		if (tmpS <S):
			break
		res = min (res, i-j)
		tmpS -=a_list[j]
		j += 1
	if res == INF:
		res = 0
	return res
		

def main():
	N, S = map(int, raw_input().split())
	a_list = map(int, raw_input().split())
	print SmallestWindow(S, a_list)

if __name__ == '__main__':
	main()
#include<bits/stdc++.h>
 
#define sorted(vector) sort(vector.begin(),vector.end())
#define vmin(vector) *min_element(vector.begin(),vector.end())
#define vmax(vector) *max_element(vector.begin(),vector.end())
#define vsum(vector) accumulate(vector.begin(),vector.end(),0)
#define append(a) push_back(a)
#define int(a) stoi(a)
#define str(a) to_string(a)
#define bisect_left(vector,a) lower_bound(vector.begin(),vector.end(),a)
#define bisect_right(vector,a) upper_bound(vector.begin(),vector.end(),a)

using namespace std;
long floatinf=-10000000;



int main(void){
    map<long,vector<long>> defaultdict;
    long n,m,p;
    long tmp1,tmp2,tmp3;
    cin>>n,m,p;
    
    for(int i=0  ;i<m  ;i++){
        cin>>tmp1>>tmp2>>tmp3;
        defaultdict[tmp1]={tmp2,tmp3};
    }
    vector<long> BELLMANFORD(long point, long d, long p);{
        vector<long long> cost=vector<long long>(n+1,-floatinf);
    }
    for(int i=0  ;i<n-1  ;i++){
        for(int j=0  ;j<n-1  ;j++){
            
        }
    }

### FIXED CODE ###

#import numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) # dijkstra# floyd_warshall
#from scipy.sparse import csr_matrix
 
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)
#input=sys.stdin.readline  #危険！基本オフにしろ！
 
def main():
    a,b=map(int,input().split())
    d=defaultdict(list)
    for i in range(a):
        c,e=map(int,input().split())
        d[c].append(-e)
    for k,v in d.items():
        v=sorted(v)
    ans=[]
    anss=0
    for i in range(1,b+1):
        if i in d.keys():
            for j in d[i]:
                heappush(ans,j)
        if ans:
            anss+=heappop(ans)
    print(-anss)
    
if __name__ == '__main__':
    main()
from collections import deque

n,a=map(int,input().split())
cards=list(map(int,input().split()))


noz=[x-a for x in cards].count(0)
pl=[x-a for x in cards if x-a>0]
nl=[a-x for x in cards if x-a<0]
sl=[pl,nl][len(nl)<=len(pl)]
ll=[pl,nl][len(pl)<len(nl)]

sl.sort()
ll.sort()

sumfunc = lambda n, l: sum([l[x]*((n>>x)&1) for x in range(len(l))])

sumsl=[sumfunc(i,sl) for i in range(1,2**len(sl))]
sumll=[sumfunc(i,ll) for i in range(1,2**len(ll))]

# count=0
# p=sum([not sumsl[-1]<sumfunc(2**i,ll) for i in range(1,len(ll)+1)])
# q=sum([sumsl[0]>=sumfunc(2**i-1,ll) for i in range(1,len(ll)+1)])
# count=[sumfunc(j,ll) in sumsl for j in range(2**q-1,2**p)].count(True)
count=0
count=sum([x==y for x in sumsl for y in sumlll])

print((count+1)*(2**noz)-1)


### FIXED CODE ###

import sys

n,a=map(int, input().split())
cards=list(map(int, input().split()))

integers=[x-a for x in cards]
cards.append(a)
f=max(cards)*n


dp=[[0 for i in range(n+1)] for j in range(2*f+1) ]

for y in range(n+1):
    for x in range(2*f+1):
        if y==0 and x==f:
            dp[x][y]=1
        elif y>0 and (x-integers[y-1]<0 or x-integers[y-1]>2*f):
            dp[x][y]=dp[x][y-1]
        elif y>0 and x-integers[y-1]>=0 and x-integers[y-1]<=2*f:
            dp[x][y]=dp[x-integers[y-1]][y-1]+dp[x][y-1]
        else:
            dp[x][y]=0
print(dp[f][n]-1)
n, k = map(int, input().split())

roads = list(map(int, input().split()))

city = 1
route = []
cnt = [0] * n
route.append(0)


while True:
    city = roads[city-1] 
    cnt[city-1] += 1
    if cnt[city-1] == 2:
        st = route.index(city)
        length = len(route) - st
        break
    route.append(city)

if k <= len(route):
    print(route[k])

elif length >= 1:
    amari = (k+1-st) % length
    if amari  == 0:
        print(route[-1])
    else:
        print(route[amari+st-1])

else:
    print(1)

### FIXED CODE ###

n, k = map(int, input().split())

roads = list(map(int, input().split()))

city = 1
route = []
cnt = [0] * n
cnt[0] += 1
route.append(1)


while True:
    city = roads[city-1] 
    cnt[city-1] += 1
    if cnt[city-1] == 2:
        st = route.index(city)
        length = len(route) - st
        break
    route.append(city)


if k < len(route):
    print(route[k])

else:
    amari = (k+1-st) % length
    if amari  == 0:
        print(route[-1])
    else:
        print(route[amari+st-1])
N,M = map(int,input().split())
A = list(map(int,input().split()))
L = []
for i in range(M) :
    b,c = map(int,input().split())
    L.append(b,c)

L = sorted(L,key=x: x[1], reverse=True)
for i in range(len(L)) :
    b,c = L[i]
    b = min(b,10**9-len(A))
    A.extend([c]*b)
ans = sum(sorted(A,reverse=True)[:N])

print(ans)

### FIXED CODE ###

N,M = map(int,input().split())
A = list(map(int,input().split()))
L = [list(map(int,input().split())) for i in range(M)]

P = sorted(([[1,A[i]] for i in range(N)] + L),key=lambda x: x[1],reverse=True)

ans = 0
rest = N

for cost,value in P :
    K = min(cost, rest)
    K = max(0,K)
    ans += K * value
    rest -= cost

print(ans)