Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import numpy as np
from heapq import *

X, Y, Z, K = map(int, input().split())
A = np.array(list(map(int, input().split())))
B = np.array(list(map(int, input().split())))
C = np.array(list(map(int, input().split())))

L = []
heapify(L)
for a in A:
    for b in B:
        for c in C:
            heappush(L, -(a+b+c))
for i in range(K):
    n = heappop(L)
    print(-n)

        


### FIXED CODE ###

import numpy as np
from heapq import *

X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

h = []
heappush(h, (-A[0]-B[0]-C[0], 0, 0, 0))
used = set()
result = []

for _ in range(K):
    sum, i, j, k = heappop(h)
    result.append(-sum)
    if i < X-1 and (i+1, j, k) not in used:
        heappush(h, (-A[i+1]-B[j]-C[k], i+1, j, k))
        used.add((i+1, j, k))
    if j < Y-1 and (i, j+1, k) not in used:
        heappush(h, (-A[i]-B[j+1]-C[k], i, j+1, k))
        used.add((i, j+1, k))
    if k < Z-1 and (i, j, k+1) not in used:
        heappush(h, (-A[i]-B[j]-C[k+1], i, j, k+1))
        used.add((i, j, k+1))

for v in result:
    print(v)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(1000000000)
from itertools import count
from functools import lru_cache
from collections import defaultdict
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok
#


def main():
    T1,T2 = mis()
    A1,A2 = mis()
    B1,B2 = mis()
    d1 = T1*A1 - T1*B1
    d2 = T2*A2 - T2*B2
    if d1 + d2 == 0:
        print('infinity')
    elif d1 < 0 > d2 or d1 > 0 < d2:
        print(0)
    else:
        ans = -1
        pos = 0
        if d1 < 0:
            d1 *= -1
            d2 *= -1
        while True:
            pos += d1
            if pos == 0:
                ans += 1
                break
            elif pos < 0:
                break
            else:
                ans += 1
            pos += d2
            ans += 1
        print(ans)




main()


### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000000)
from itertools import count
from functools import lru_cache
from collections import defaultdict
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok
#


def main():
    T1,T2 = mis()
    A1,A2 = mis()
    B1,B2 = mis()
    d1 = T1*A1 - T1*B1
    d2 = T2*A2 - T2*B2
    if d1 + d2 == 0:
        print('infinity')
    elif d1 < 0 > d2 or d1 > 0 < d2:
        print(0)
    else:
        if d1 < 0:
            d1 *= -1
            d2 *= -1
        if d1 + d2 > 0:
            print(0)
        elif d1 % (d1+d2) == 0:
            print(d1 // abs(d1+d2) * 2)
        else:
            print(d1 // abs(d1+d2) * 2 + 1)




main()
### BUGGY CODE ###

N, M = list(map(int, input().split()))
A = list(map(lambda x: int(x), input().split(' ')))

for _ in range(M):
    diff = 0
    idx = 0
    for i in range(N):
        if (A[i] - A[i]//2) > diff:
            diff = A[i] - A[i]//2
            idx = i
    A[idx] = A[idx] // 2
    
print('{}'.format(sum(A)))

### FIXED CODE ###

import heapq
 
N, M = list(map(int, input().split()))
A = input().split(" ")
neg_A = [-int(a) for a in A]
 
heapq.heapify(neg_A)
 
for t in range(M):
    heapq.heappush(neg_A, -(-heapq.heappop(neg_A)//2))
print(-sum(neg_A))
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
#A = [int(x) for x in input().split()]
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
A = [-float('inf')] + A + [float('inf')]
B.sort()
C.sort()
C = [-float('inf')] + C + [float('inf')]

total = 0

for i in range(N):
    low = 0
    high = N + 1
    while low + 1 < high:
        mid1 = (low + high) // 2
        if A[mid1] < B[i]:
            low = mid1
        if A[mid1] >= B[i]:
            high = mid1
    mid1 = low
    low = 0
    high = N + 1
    while low + 1 < high:
        mid2 = (low + high) // 2
        if C[mid2] <= B[i]:
            low = mid2
        if C[mid2] > B[i]:
            high = mid2
    mid2 = high
    total = total + mid1 * (N + 1 - mid2)

print(total)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
#A = [int(x) for x in input().split()]
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
A = [-float('inf')] + A + [float('inf')]
B.sort()
C.sort()
C = [-float('inf')] + C + [float('inf')]

total = 0

for i in range(N):
    low = 0
    high = N + 1
    while high - low > 1:
        mid1 = (low + high) // 2
        if A[mid1] < B[i]:
            low = mid1
        else:
            high = mid1
    mid1 = low
    low = 0
    high = N + 1
    while high - low > 1:
        mid2 = (low + high) // 2
        if C[mid2] <= B[i]:
            low = mid2
        else:
            high = mid2
    mid2 = high
    total += mid1 * (N + 1 - mid2)

print(total)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**9)
n, m, k = map(int, input().split())
color = [i for i in range(m)]
ans = 0
def dfs(i, daburi, num):
    global ans
    if i == n-1:
        if daburi == k:
            ans += num % 998244353
            return 
        elif daburi < k:
            ans += num % 998244353
            return
    if daburi > k:
        return
    dfs(i+1, daburi, num*(m-1))
    dfs(i+1, daburi+1, num)
dfs(0, 0, m)
print(ans% 998244353)

### FIXED CODE ###

import math
n, m, k = map(int, input().split())

p = 998244353

def comb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n-r)
    return fact[n] * factinv[r] * factinv[n-r] % p

fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]

for i in range(2, n+1):
    fact.append(fact[-1]*i%p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1]*inv[i])%p)
ans = 0

for i in range(k+1):
    row = comb(n-1, i, p)
    column = m * pow(m-1, n-i-1, p)
    ans += row * column
    
print(ans % p)
### BUGGY CODE ###

#!/usr/bin/env python3

import sys

debug = False

def solve(ds, n, x, m):
    ds = [d % m for d in ds]

    nr_loop = (n - 1) // len(ds)
    lastloop_remaining = (n - 1) % len(ds)
    a_n = x
    cnt_zero = 0
    for i in range(0, len(ds)):
        dmod = ds[i] % m
        a_n += (dmod) * nr_loop
        if dmod == 0:
            cnt_zero += nr_loop
        if i < lastloop_remaining:
            a_n += dmod
            if dmod == 0:
                cnt_zero += 1
    cnt_decrease = a_n // m - x // m
    return n - 1 - cnt_decrease - cnt_zero


def read_int_list(sep = " "):
    return [int(s) for s in sys.stdin.readline().split(sep)]


def dprint(*args, **kwargs):
    if debug:
        print(*args, **kwargs)
    return


def main():
    k, q = read_int_list()
    d = read_int_list()
    for _ in range(0, q):
        n, x, m = read_int_list()
        print(str(solve(d, n, x, m)))
    

if __name__ == "__main__":
    main()

### FIXED CODE ###

#!/usr/bin/env python3

import sys

debug = False

def solve(ds, n, x, m):
    ds = [d % m for d in ds]

    nr_loop = (n - 1) // len(ds)
    lastloop_remaining = (n - 1) % len(ds)
    a_n = x
    cnt_zero = 0
    for i in range(0, len(ds)):
        dmod = ds[i] % m
        a_n += (dmod) * nr_loop
        if dmod == 0:
            cnt_zero += nr_loop
        if i < lastloop_remaining:
            a_n += dmod
            if dmod == 0:
                cnt_zero += 1
    cnt_decrease = a_n // m - x // m
    return n - 1 - cnt_decrease - cnt_zero


def read_int_list(sep = " "):
    return [int(s) for s in sys.stdin.readline().split(sep)]


def dprint(*args, **kwargs):
    if debug:
        print(*args, **kwargs)
    return


def main():
    k, q = read_int_list()
    d = read_int_list()
    for _ in range(0, q):
        n, x, m = read_int_list()
        print(str(solve(d, n, x, m)))
    

if __name__ == "__main__":
    main()
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
capacity = [1 for k in range(N+1)]
cut = 0
for k in range(N+1):
    #print(capacity)
    if A[k] >= capacity[k] and k!= N:
        print(-1)
        break
    if A[k] > capacity[k] and k == N:
        print(-1)
        break
    if k < N:
        capacity[k+1] = 2*(capacity[k] - A[k])
    if k == N:
        ans = [0 for k in range(N+1)]
        ans[0] =1
        for m in range(N+1):
            ans[m] = min(capacity[m], sum(A[m:N+1]))
        print(sum(ans))





### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
capacity = [1 for k in range(N+1)]
cut = 0
for k in range(N+1):
    #print(capacity)
    if A[k] >= capacity[k] and k!= N:
        print(-1)
        break
    if A[k] > capacity[k] and k == N:
        print(-1)
        break
    if k < N:
        capacity[k+1] = 2*(capacity[k] - A[k])
    if k == N:
        ans = [0 for k in range(N+1)]
        ans[0] =1
        sumA = 0
        for m in range(1, N+2):
            sumA += A[-m]
            ans[-m] = min(capacity[-m], sumA)
        print(sum(ans))
### BUGGY CODE ###

# coding: utf-8
# Your code here!

x,y,z,k = map(int,input().split())

A = sorted(map(int,input().split()))[::-1]
B = sorted(map(int,input().split()))[::-1]
C = sorted(map(int,input().split()))[::-1]

AB = sorted([a+b for a in A for b in B])[::-1]

ans = sorted([ab + c for ab in AB for c in C])[::-1]

for i in ans[:k]:
    print(i)



### FIXED CODE ###

# coding: utf-8
# Your code here!

x,y,z,k = map(int,input().split())

A = sorted(map(int,input().split()))[::-1]
B = sorted(map(int,input().split()))[::-1]
C = sorted(map(int,input().split()))[::-1]

AB = sorted([a+b for a in A for b in B])[::-1]

ans = sorted([ab + c for ab in AB[:k] for c in C])[::-1]

for i in ans[:k]:
    print(i)
### BUGGY CODE ###

A, B, M = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

xyc_list = []
for i in range(M):
    xyc_list.append(list(map(int, input().split())))

total_min = min(a_list) + min(b_list)
for x,y,c in xyc_list:
    if a_list[x-1] in a_list and b_list[y-1] in b_list:
        total = a_list[x-1] + b_list[y-1] - c
        if total_min > total:
            total_min = total

print(total_min)


### FIXED CODE ###

A, B, M = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

xyc_list = []
for i in range(M):
    xyc_list.append(list(map(int, input().split())))

total_min = min(a_list) + min(b_list)
for x,y,c in xyc_list:
    total = a_list[x-1] + b_list[y-1] - c
    if total_min > total:
        total_min = total

print(total_min)
### BUGGY CODE ###

hwd = list(map(int, input().split()))
a = []
for i in range(hwd[0]):
    a.append(list(map(int, input().split())))
q = int(input())
lr = []
for i in range(q):
    lr.append(list(map(int, input().split())))

xy = [None] * hwd[0] * hwd[1]
for i in range(hwd[0]):
    for j in range(hwd[1]):
        xy[a[i][j] - 1] = [i, j]
for i in range(q):
    power = 0
    pre_number = lr[i][0]
    next_number = lr[i][0] + hwd[2]
    while pre_number != lr[i][1]:
        power = power + abs(xy[pre_number - 1][0] - xy[next_number - 1][0]) + abs(xy[pre_number - 1][1] - xy[next_number - 1][1])
        pre_number = next_number
        next_number = next_number + hwd[2]
    print(power)

### FIXED CODE ###

hwd = list(map(int, input().split()))
a = []
for i in range(hwd[0]):
    a.append(list(map(int, input().split())))
q = int(input())
lr = []
for i in range(q):
    lr.append(list(map(int, input().split())))

xy = [None] * hwd[0] * hwd[1]
for i in range(hwd[0]):
    for j in range(hwd[1]):
        xy[a[i][j] - 1] = [i, j]
        
power_accumulation = []
for i in range(hwd[2]):
    power = [0]
    number = 0
    place = i
    while place < hwd[0] * hwd[1] - hwd[2]:
        power.append(power[number] + abs(xy[place + hwd[2]][0] - xy[place][0]) + abs(xy[place + hwd[2]][1] - xy[place][1]))
        number = number + 1
        place = place + hwd[2]
    power_accumulation.append(power)

for i in range(q):
    test_power = power_accumulation[(lr[i][1] - 1) % hwd[2]][(lr[i][1] - 1) // hwd[2]] - power_accumulation[(lr[i][0]- 1) % hwd[2]][(lr[i][0] - 1) // hwd[2]]
    print(test_power)
### BUGGY CODE ###

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

product = 1
for i in lst:
  product *= i #これが(i + 1)番目

if(product > 1000000000000000000):
  print(-1)
else:
  print(product)

### FIXED CODE ###

N = int(input())
lst = list(map(int, input().split()))
if (0 in lst):
  print(0)
else:
  product = 1
  for i in lst: 
    product *= i

    if(product > 1000000000000000000):
      print(-1)
      break
  else:
    print(product)
### BUGGY CODE ###

from collections import deque

H, W = map(int, input().split())
Ch, Cw = map(lambda x: x - 1, map(int, input().split()))
Dh, Dw = map(lambda x: x - 1, map(int, input().split()))
S = []
already = []
yet = 1000000
for i in range(H):
    S.append(input())
    already.append([yet] * W)
queue = deque()
queue.append((Cw, Ch, 0))
already[Ch][Cw] = 0
answer = -1
while len(queue) > 0:
    #print(queue)
    #print(already)
    x, y, cost = queue.popleft()
    #print(x, y, cost)
    if x == Dw and y == Dh:
        answer = cost
        break
    for i in range(-2, 3):
        for j in range(-2, 3):
            new_x, new_y = (x + i, y + j)
            # 場外
            if new_x < 0 or new_y < 0 or W <= new_x or H <= new_y:
                continue
            # 動かない
            if new_x == x and new_y == y:
                continue
            # 壁
            if S[new_y][new_x] == '#':
                continue
            # 探索済み
            if already[new_y][new_x] <= cost:
                continue
            if (i == 0 and j == -1) \
            or (i == 0 and j == 1) \
            or (i == 1 and j == 0) \
            or (i == -1 and j == 0):
                queue.appendleft((new_x, new_y, cost))
                already[new_y][new_x] = cost
            else:
                queue.append((new_x, new_y, cost+1))
                already[new_y][new_x] = cost+1
print(answer)

### FIXED CODE ###

from collections import deque

H, W = map(int, input().split())
Ch, Cw = map(lambda x: x - 1, map(int, input().split()))
Dh, Dw = map(lambda x: x - 1, map(int, input().split()))
S = []
already = []
yet = 1000000
for i in range(H):
    S.append(input())
    already.append([yet] * W)
queue = deque()
queue.append((Cw, Ch, 0))
already[Ch][Cw] = 0
answer = -1
while len(queue) > 0:
    #print(queue)
    #print(already)
    x, y, cost = queue.popleft()
    #print(x, y, cost)
    if x == Dw and y == Dh:
        answer = cost
        break
    for i in range(-2, 3):
        for j in range(-2, 3):
            new_x, new_y = (x + i, y + j)
            # 場外
            if new_x < 0 or new_y < 0 or W <= new_x or H <= new_y:
                continue
            # 動かない
            if new_x == x and new_y == y:
                continue
            # 壁
            if S[new_y][new_x] == '#':
                continue
            # 探索済み
            if already[new_y][new_x] <= cost:
                continue
            if (i == 0 and j == -1) \
            or (i == 0 and j == 1) \
            or (i == 1 and j == 0) \
            or (i == -1 and j == 0):
                queue.appendleft((new_x, new_y, cost))
                already[new_y][new_x] = cost
            else:
                queue.append((new_x, new_y, cost+1))
                already[new_y][new_x] = cost+1
print(answer)
### BUGGY CODE ###

n = int(input())
X = list(map(int, input().split()))
for i in range(n):
    if i !=0 and i != n-1:
        l = X[:i] + X[i+1:]
    elif i == 0:
        l = X[1:]
    else:
        l = X[:n-1]
    l.sort()
    print(l[n // 2 - 1])


### FIXED CODE ###

n = int(input())
X = list(map(int, input().split()))
X_mid = sorted(X)[n//2 - 1: n//2 + 1]

for i in X:
    print(X_mid[i <= X_mid[0]])  # Falseなら1、Trueなら0
### BUGGY CODE ###

N, M = map(int, input().split())
H = list(map(int, input().split()))

a = [[0 for _ in range(N)] for _ in range(N)]

for i in range(M):
    A, B = map(int, input().split())
    a[A-1][B-1] = 1
    a[B-1][A-1] = 1

ans = 0


for i in range(N):
    flag = 0
    if 1 not in a[i]:
        ans += 1
    else:
        for j in range(N):
            if a[i][j] == 1:
                if H[j] >= H[i]:
                    flag = 1
                    break

        if flag == 0:
            ans += 1

print(ans)




### FIXED CODE ###

N, M = map(int, input().split())
H = list(map(int, input().split()))

a = [set() for _ in range(N)]

for i in range(M):
    A, B = map(int, input().split())
    a[A-1].add(B)
    a[B-1].add(A)

ans = 0

for i in range(N):
    flag = 0
    if a[i] == set():
        ans += 1
    else:
        for j in a[i]:
            if H[j-1] >= H[i]:
                flag = 1
                break

        if flag == 0:
            ans += 1

print(ans)
### BUGGY CODE ###

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

logn = (10**10).bit_length()
doubling = []
sumd = []
for _ in range(logn):
  tmpd = [-1] * m
  doubling.append(tmpd)
  tmps = [0] * m
  sumd.append(tmps)

for i in range(m):
  doubling[0][i] = i * i % m
  sumd[0][i] = i

for i in range(1,logn):
  for j in range(m):
    doubling[i][j] = doubling[i-1][doubling[i-1][j]]
    sumd[i][j] = sumd[i-1][j] + sumd[i-1][doubling[i-1][j]]

now = x
pos = 0
result = 0
while n:
  if n & 1:
    result += sumd[pos][now]
    now = doubling[pos][now]
  n = n >> 1
  pos += 1

print(result)


### FIXED CODE ###

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

logn = (10**10).bit_length()
doubling = []
sumd = []
for _ in range(logn):
  tmpd = [-1] * m
  doubling.append(tmpd)
  tmps = [0] * m
  sumd.append(tmps)

for i in range(m):
  doubling[0][i] = i * i % m
  sumd[0][i] = i

for i in range(1,logn):
  for j in range(m):
    doubling[i][j] = doubling[i-1][doubling[i-1][j]]
    sumd[i][j] = sumd[i-1][j] + sumd[i-1][doubling[i-1][j]]

now = x
pos = 0
result = 0
while n:
  if n & 1:
    result += sumd[pos][now]
    now = doubling[pos][now]
  n = n >> 1
  pos += 1

print(result)
### BUGGY CODE ###

s = input()
f = 0
for i in range(len(s)-1):
	if f == 0:
		for j in range(i+2,len(s)+1):
			t = s[i:j]
			if f == 0:
				for k in range(j-i):
					if t.count(t[k]) > len(t)/2:
						print(i+1,j)
						f = 1
						break
else:
	if f == 0:
		print("-1 -1")


### FIXED CODE ###

s = input()
for i in range(len(s)-2):
	if s[i] == s[i+1]:
		print(i+1, i+2)
		break
	elif s[i] == s[i+2]:
		print(i+1, i+3)
		break
else:
	if s[-2] == s[-1]:
		print(len(s)-1, len(s))
	else:
		print(-1, -1)
### BUGGY CODE ###

from collections import Counter

def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

n, m, r = read_line(int, int, int)

rs = [int(r) for r in input().split()]

cities = Counter()

routes = {}
costs = {}
for _ in range(m):
    a, b, c = read_line(int, int, int)

    cities[a] = 1
    cities[b] = 1

    if a in routes:
        routes[a][b] = c
    else:
        routes[a] = { b : c }

    if b in routes:
        routes[b][a] = c
    else:
        routes[b] = { a : c }

for a in cities.keys():
    for b in cities.keys():
        if a not in costs:
            costs[a] = {}
        if b not in costs[a]:
            if a in routes and b in routes[a]:
                costs[a][b] = routes[a][b]
            else:
                costs[a][b] = 100000 + 1

keys = list(cities.keys())

for k in keys:
    for a in keys:
        for b in keys:
            c = costs[a][k] + costs[k][b]
            if costs[a][b] > c:
                costs[a][b] = c

def cost(selected):
    c = 0
    for i in range(len(selected) - 1):
        a = selected[i]
        b = selected[i + 1]
        c += costs[a][b]
    return c

smallest = cost(rs)

def passing_all_cities(selected):
    for r in rs:
        if r not in selected:
            return False
    return True

def f(selected, rest):
    global smallest
    if passing_all_cities(selected):
        c = cost(selected)
        if smallest > c:
            smallest = c
    else:
        for i in range(len(rest)):
            r = rest[i]
            rest_copy = rest[:]
            del rest_copy[i]
            if cost(selected + [r]) < smallest:
                f(selected + [r], rest_copy)

f([], keys)
print(smallest)


### FIXED CODE ###

from itertools import permutations

def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

n, m, r = read_line(int, int, int)

rs = [int(r) for r in input().split()]

costs = {}
for i in range(n + 1):
    costs[i] = {}
    for j in range(n + 1):
        costs[i][j] = float('inf')

for _ in range(m):
    a, b, c = read_line(int, int, int)

    costs[a][b] = costs[b][a] = c

for k in range(n + 1):
    for i in range(n + 1):
        for j in range(n + 1):
            c = costs[i][k] + costs[k][j]
            if costs[i][j] > c:
                costs[i][j] = c

def cost(selected):
    c = 0
    for i in range(len(selected) - 1):
        a = selected[i]
        b = selected[i + 1]
        c += costs[a][b]
    return c

smallest = float('inf')

for p in permutations(rs):
    c = cost(p)
    if smallest > c:
        smallest = c

print(smallest)
### BUGGY CODE ###

n,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(set(a))
l = []
c = 0
for i in range(len(b)):
    l.append(a.count(b[i]))
    l = sorted(l)
if len(l) - k < 0:
    print(0)
else:
    print(sum(l[:len(l)-k]))

### FIXED CODE ###

import collections
n,k = map(int,input().split())
a = list(map(int,input().split()))
c = collections.Counter(a).values()
counter = sorted(list(c))
print(sum(counter[:len(counter)-k]))
### BUGGY CODE ###

import math
import copy
import sys
import fractions
import numpy as np
from functools import reduce
import statistics
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

n, m = map(int, input().split())
data = getSomeInputListInt(n)

ans = 0
for i in range(1, m+1):
    tmp = 0
    tmpidx = -1
    for j in range(len(data)-1, -1, -1):
        if data[j][0] <= i:
           if tmp < data[j][1]:
               tmp = data[j][1]
               tmpidx = j
    if tmpidx != -1:
        ans += tmp
        del data[tmpidx]

print(ans)

### FIXED CODE ###

import math
import copy
import sys
import fractions
import numpy as np
from functools import reduce
import statistics
import heapq

input = sys.stdin.readline
sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

n, m = map(int, input().split())
data = getSomeInputListInt(n)

data_list = [[0] for _ in range(m)]

for i in range(n):
    if data[i][0]-1 < m:
        data_list[data[i][0]-1].append(-data[i][1])

heap_list = []
heapq.heapify(heap_list)
# heapq.heapify(data_list)

ans = 0
for j in range(m):
    for i in range(len(data_list[j])):
        heapq.heappush(heap_list, data_list[j][i])
    a = heapq.heappop(heap_list)
    ans += a

print(-ans)