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

n = int(input())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))

rates_list = [[],[]]
for i in range(3):
	if aa[i] > bb[i]:
		rates_list[1].append([bb[i], aa[i]])
	else:
		rates_list[0].append([aa[i], bb[i]])

max_d = n
for j in range(2):
	rates = rates_list[j]
	if len(rates) == 1:
		max_d = (max_d // rates[0][0]) * rates[0][1] + max_d % rates[0][0]
	elif len(rates) == 2:
		dp = [rates[0][1] * (d // rates[0][0]) + rates[1][1] * ((max_d - d + d % rates[0][0]) // rates[1][0]) + ((max_d - d + d % rates[0][0]) % rates[1][0]) for d in range(max_d + 1)]
		max_d = max(dp)
	elif len(rates) == 3:
		dp = [(d // rates[0][0]) * rates[0][1] + d % rates[0][0] for d in range(max_d + 1)]
		for d in range(1, max_d + 1):
			dp[d] = max([dp[d]] + [dp[d - rates[i][0]] + rates[i][1] if d - rates[i][0] >= 0 else d for i in range(1, len(rates))])
		max_d = dp[-1]
print (max_d)


### FIXED CODE ###

n = int(input())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))

rates_list = [[],[]]
for i in range(3):
	if aa[i] > bb[i]:
		rates_list[1].append([bb[i], aa[i]])
	else:
		rates_list[0].append([aa[i], bb[i]])

max_d = n
for j in range(2):
	rates = rates_list[j]
	if len(rates) == 1:
		max_d = (max_d // rates[0][0]) * rates[0][1] + max_d % rates[0][0]
	elif len(rates) == 2:
		val = [rates[0][1] * i for i in range(max_d // rates[0][0] + 1)]
		rest = [max_d - rates[0][0] * i for i in range(max_d // rates[0][0] + 1)]
		val = [val[i] + rates[1][1] * (rest[i] // rates[1][0]) + (rest[i] % rates[1][0]) if rest[i] > 0 else val[i] for i in range(len(val))]
		max_d = max(val)
	elif len(rates) == 3:
		dp = [(d // rates[0][0]) * rates[0][1] + d % rates[0][0] for d in range(max_d + 1)]
		for d in range(1, max_d + 1):
			dp[d] = max([dp[d]] + [dp[d - rates[i][0]] + rates[i][1] if d - rates[i][0] >= 0 else d for i in range(1, len(rates))])
		max_d = dp[-1]
print (max_d)
### BUGGY CODE ###

N, W = map(int, input().split())
ws = [0]*N
vs = [0]*N

for i in range(N):
  w, v = map(int, input().split())
  ws[i] = w
  vs[i] = v

V = N*(10**3)+1
dp = [[float('inf')]*V for _ in range(N+1)]
# dp[i][j]: i個の品物までを見てjの価値を実現する最小のw
dp[0][0] = 0
temp = 0

for i in range(N):
  w = ws[i]
  v = vs[i]
  for k in range(V):
    if k-v>=0:
      dp[i+1][k] = min(dp[i][k-v]+w, dp[i+1][k])
    dp[i+1][k] = min(dp[i][k], dp[i+1][k])

for j in range(V-1, -1, -1):
  if dp[N][j] <= W:
    print(j)
    exit()

### FIXED CODE ###

N, W = map(int, input().split())
ws = [0]*N
vs = [0]*N

for i in range(N):
  w, v = map(int, input().split())
  ws[i] = w
  vs[i] = v

V = N*(10**3)+1
dp = [[float('inf')]*V for _ in range(N+1)]
# dp[i][j]: i個の品物までを見てjの価値を実現する最小のw
dp[0][0] = 0
temp = 0

for i in range(N):
  w = ws[i]
  v = vs[i]
  for k in range(V):
    if k-v>=0:
      dp[i+1][k] = min(dp[i][k-v]+w, dp[i+1][k])
    dp[i+1][k] = min(dp[i][k], dp[i+1][k])

for j in range(V-1, -1, -1):
  if dp[N][j] <= W:
    print(j)
    exit()
### BUGGY CODE ###

N = int(input())
S = list(input())
count_list = []
for i in range(N):
  count = 0
  for j in range(N):
#   leader = i
    if j < i and S[j] == "W":
      count += 1
    elif i < j and S[j] == "E":
      count += 1
  count_list.append(count)
print(min(count_list))

### FIXED CODE ###

N = int(input())
S = list(input())
count_E = S.count("E")
count_W = 0
ans = count_E
for i in range(N):
    if S[i] == "E":
        count_E -= 1
    if S[i-1] == "W" and i != 0:
        count_W += 1
    if count_E + count_W < ans :
        ans = count_E + count_W
print(ans)
### BUGGY CODE ###

n = int(input())
a = [input() for i in range(n)] 
ans = 1
s = [a[0]]
 
for i in a[1:]:
    if not i in s:
        ans += 1
        s.append(i)
print(ans) 

### FIXED CODE ###

import collections
N=int(input())
S=[]
for i in range(N):
    S.append(input())
s=collections.Counter(S)
s_key=s.keys()
print(len(s_key))
### BUGGY CODE ###

import numpy as np
H, W, N = map(int, input().split())
d = 10**9+1
L = []
S = set()
for _ in range(N):
    a, b = map(int, input().split())
    S.add((a, b))
Map = np.zeros([5, 5], dtype = 'int')
ans = [0]*10
for i in S:
    a, b = i
    for i in range(-2, 3):
        for j in range(-2, 3):
            a1, b1 = a+i, b+j
            if (1<=a1<=H) and (1<=b1<=W):
                if (a1, b1) in S:
                    Map[i+2][j+2] = 1
                else:
                    Map[i+2][j+2] = 0
            else:
                Map[i+2][j+2] = -100
    for i in range(-1, 2):
        for j in range(-1, 2):
            k = Map[i+1:i+4, j+1:j+4].sum()
            if k>=0:
                ans[k]+=1
for i in range(1, 10)[::-1]:
    ans[i] //=i
ans[0] = (W-2)*(H-2)-sum(ans)
for i in ans:
    print(i)
        

### FIXED CODE ###

H, W, N = map(int, input().split())
d = 10**9+1
L = []
S = set()
for _ in range(N):
    a, b = map(int, input().split())
    S.add((a, b))
Map =[[0]*5 for _ in range(5)]
ans = [0]*10
for i in S:
    a, b = i
    for i in range(-2, 3):
        for j in range(-2, 3):
            a1, b1 = a+i, b+j

            if (1<=a1<=H) and (1<=b1<=W):
                if (a1, b1) in S:
                    Map[i+2][j+2] = 1
                else:
                    Map[i+2][j+2] = 0
            else:
                Map[i+2][j+2] = -100
    for i in range(-1, 2):
        for j in range(-1, 2):
            res = 0
            for k in range(3):
                for l in range(3):
                    res+=Map[i+1+k][j+1+l]
            if res>=0:
                ans[res]+=1
for i in range(1, 10)[::-1]:
    ans[i] //=i
ans[0] = (W-2)*(H-2)-sum(ans)
for i in ans:
    print(i)
### BUGGY CODE ###

def prime(n):
    if (n==2):
        return True
    elif(n == 1):
        return False
    else:
        pr = [2]
        for i in range(3,n):
            c = 0
            for p in pr:
                if (i % p != 0):
                    c = c + 1
            if (c == len(pr)):
                if n%i == 0:
                    return False 
                    break
                pr.append(i)
        cc = 0        
        for p in pr:
            if(n%p != 0):
                cc = cc + 1
            elif(n%p == 0):
                return False
                break
    
    if(cc == len(pr)):
        return True
    else:
        return False
        
    
N = int(input())

count = 0
for i in range(N):
    n = int(input())
    if prime(n) == True:
        count = count + 1 
print(count)   


### FIXED CODE ###

n = int(input())
mlist = []
plist = [2]
for i in range(3,10000):
    count = 0
    for k in plist:
        if (i%k != 0):
            count += 1
        else:
            break
    if (count == len(plist)):
        plist.append(i)
def check(m):
    for p in plist:
        if (m <= p):
            return True
        if m%p == 0:
            return False     ##한번이라도 False가 return되면 False가 되기에 prime인지 아닌지 check가능
    return True

count = 0
for i in range(n):
    m = int(input())
    if check(m):
        count += 1
        
print(count)
### BUGGY CODE ###

r,g,b,n = map(int, input().split())
ans = 0
for i in range(3001):
    for j in range(3001):
        k = n - (i*r + j*g)
        if k >= 0 and k%b == 0:
            ans += 1
print(ans)


### FIXED CODE ###

r,g,b,n = map(int, input().split())
ans = 0
for i in range(n+1):
    for j in range(n+1):
        k = n - (i*r + j*g)
        if k < 0:
            break
        elif k >= 0 and k%b == 0:
            ans += 1
print(ans)
### BUGGY CODE ###

import bisect
class SegmentTreeRMQ(object):  # 1-indexed
    def __init__(self, size, value):
        self.len = 1 << size.bit_length()
        # print(self.len)
        self.array = [value] * (2 * self.len)

    def update(self, i, x):
        i += self.len
        while i > 0:
            self.array[i] = max(self.array[i], x)
            i >>= 1
        # print(self.array)

    def get(self, i):
        return self.array[i + self.len]

    def query(self, l, r, i, a, b):
        if l == a and r == b:
            return self.array[i]
        center = (a + b) // 2
        if center >= r:
            return self.query(l, r, i * 2, a, center)
        elif center <= l:
            return self.query(l, r, i * 2 + 1, center, b)
        else:
            return max(
                self.query(l, center, i * 2, a, center),
                self.query(center, r, i * 2 + 1, center, b))

    def get_maximum(self, l, r):
        return self.query(l, r, 1, 0, self.len)


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

xd_array = sorted(xd_array, key=lambda x: x[0])
x_array = [i[0] for i in xd_array]
d_array = [i[1] for i in xd_array]

mod = 998244353

tree = SegmentTreeRMQ(N, -1)
ans_array = [0] * (N+1)
ans_array[-1] = 1
for i in range(N-1, -1, -1):
    move = x_array[i] + d_array[i] - 0.1
    max_index = bisect.bisect_left(x_array, move)
    max_move = max(i, tree.get_maximum(i, max_index))
    tree.update(i, max_move)
    ans_array[i] = (ans_array[i+1] + ans_array[max_move + 1]) % mod

print(ans_array[0])


### FIXED CODE ###

import bisect
import sys
input = sys.stdin.readline


class SegmentTreeRMQ(object):  # 1-indexed
    def __init__(self, size, value):
        self.len = 1 << size.bit_length()
        # print(self.len)
        self.array = [value] * (2 * self.len)

    def update(self, i, x):
        i += self.len
        while i > 0:
            self.array[i] = max(self.array[i], x)
            i >>= 1
        # print(self.array)

    def get(self, i):
        return self.array[i + self.len]

    def get_maximum(self, l, r):
        L = l+self.len
        R = r+self.len
        ANS = -1 << 30

        while L < R:
            if L & 1:
                ANS = max(ANS, self.array[L])
                L += 1

            if R & 1:
                R -= 1
                ANS = max(ANS, self.array[R])
            L >>= 1
            R >>= 1

        return ANS


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

xd_array = sorted(xd_array, key=lambda x: x[0])
x_array = [i[0] for i in xd_array]
d_array = [i[1] for i in xd_array]

mod = 998244353

tree = SegmentTreeRMQ(N, -1)
ans_array = [0] * (N+1)
ans_array[-1] = 1
for i in range(N-1, -1, -1):
    move = x_array[i] + d_array[i] - 0.1
    max_index = bisect.bisect_left(x_array, move)
    max_move = max(i, tree.get_maximum(i, max_index))
    tree.update(i, max_move)
    ans_array[i] = (ans_array[i+1] + ans_array[max_move + 1]) % mod

print(ans_array[0])
### BUGGY CODE ###

H, W = map(int, input().split())
H += 2
W += 2
grid = '#' * W
for _ in range(H-2):
    grid += '#' + input() + '#'
grid += '#' * W

def dfs(start):
    move_list = [-1, 1, W, -W]
    L = 1
    for move in move_list:
      v = start
      cnt = 0
      while grid[v] == ".":
        v += move
        if grid[v] != "#":
          cnt += 1
      L += cnt
    return L

ans = max(dfs(v) for v in range(H*W) if grid[v] != "#")
print(ans)

### FIXED CODE ###

import copy

H, W = map(int, input().split())
grid = [[1 if c == "." else 0 for c in input()] for _ in range(H)]

L = copy.deepcopy(grid)
R = copy.deepcopy(grid)
U = copy.deepcopy(grid)
D = copy.deepcopy(grid)

for i in range(H):
  for j in range(1, W):
    L[i][j] = (L[i][j-1] + 1) * L[i][j]
    R[i][-1-j] = (R[i][-j] + 1) * R[i][-1-j]

for j in range(W):
  for i in range(1, H):
    U[i][j] = (U[i-1][j] + 1) * U[i][j]
    D[-1-i][j] = (D[-i][j] + 1) * D[-1-i][j]

ans = 0

for i in range(H):
  for j in range(W):
    ans = max(ans, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3, 0)

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

# -*- coding: utf-8 -*-
from pprint import pprint

S = list(input())
MOD = 10**9 + 7

dp = [[0 for _ in range(4)] for _ in range(len(S)+1)]

dp[len(S)][0] = 0
dp[len(S)][1] = 0
dp[len(S)][2] = 0
dp[len(S)][3] = 1

for i in reversed( range(len(S))):
    dp[i][0] = dp[i+1][0]
    if S[i] == 'C':
        dp[i][3] = dp[i+1][3]
        dp[i][2] = dp[i+1][2] + dp[i+1][3]
        dp[i][1] = dp[i+1][1] 
        dp[i][0] = dp[i+1][0]
    elif S[i] == 'B':
        dp[i][3] = dp[i+1][3]
        dp[i][2] = dp[i+1][2]
        dp[i][1] = dp[i+1][1] + dp[i+1][2]
        dp[i][0] = dp[i+1][0]
    elif S[i] == 'A':
        dp[i][3] = dp[i+1][3]
        dp[i][2] = dp[i+1][2] 
        dp[i][1] = dp[i+1][1] 
        dp[i][0] = dp[i+1][0] + dp[i+1][1]
    elif S[i] == '?':
        dp[i][3] = 3*dp[i+1][3]
        dp[i][2] = 3*dp[i+1][2] + dp[i+1][3]
        dp[i][1] = 3*dp[i+1][1] + dp[i+1][2]
        dp[i][0] = 3*dp[i+1][0] + dp[i+1][1]

# pprint(dp)
print(dp[0][0]%MOD)


### FIXED CODE ###

# -*- coding: utf-8 -*-
from pprint import pprint

S = list(input())
MOD = 10**9 + 7

dp = [[0 for _ in range(4)] for _ in range(len(S)+1)]

dp[len(S)][0] = 0
dp[len(S)][1] = 0
dp[len(S)][2] = 0
dp[len(S)][3] = 1

for i in reversed( range(len(S))):
    dp[i][0] = dp[i+1][0]
    if S[i] == 'C':
        dp[i][3] = dp[i+1][3]
        dp[i][2] = dp[i+1][2] + dp[i+1][3]
        dp[i][1] = dp[i+1][1] 
        dp[i][0] = dp[i+1][0]
    elif S[i] == 'B':
        dp[i][3] = dp[i+1][3]
        dp[i][2] = dp[i+1][2]
        dp[i][1] = dp[i+1][1] + dp[i+1][2]
        dp[i][0] = dp[i+1][0]
    elif S[i] == 'A':
        dp[i][3] = dp[i+1][3]
        dp[i][2] = dp[i+1][2] 
        dp[i][1] = dp[i+1][1] 
        dp[i][0] = dp[i+1][0] + dp[i+1][1]
    elif S[i] == '?':
        dp[i][3] = 3*dp[i+1][3]
        dp[i][2] = 3*dp[i+1][2] + dp[i+1][3]
        dp[i][1] = 3*dp[i+1][1] + dp[i+1][2]
        dp[i][0] = 3*dp[i+1][0] + dp[i+1][1]

    dp[i][3] %= MOD
    dp[i][2] %= MOD
    dp[i][1] %= MOD
    dp[i][0] %= MOD


# pprint(dp)
print(dp[0][0]%MOD)
### BUGGY CODE ###

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

ls = []
ans = 0

for i in range(k):
    ans += p[i]
    
ls.append([ans,0])

for i in range(n-k):
    ans -= p[i]
    ans += p[i+k]
    ls.append([ans,i+1])

ls = sorted(ls,reverse=True)

ans = 0
for i in range(k):
    for j in range(p[ls[0][1]+i]):
        ans += (1/p[ls[0][1]+i]*(j+1))
    
print(ans)
        

### FIXED CODE ###

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

ls = []
ans = 0

for i in range(k):
    ans += p[i]
    
max_ans = ans
max_index = 0

for i in range(n-k):
    ans -= p[i]
    ans += p[i+k]
    if max_ans < ans:
        max_ans = ans
        max_index = i+1

ans = 0
for i in range(k):
    pp = p[max_index+i]
    for j in range(pp):
        ans += (1/pp*(j+1))
    
print(ans)
### BUGGY CODE ###

k = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
z = [int(i) for i in input().split()]

x.sort()
y.sort()
z.sort()

e = []

for i in x:
  for j in y:
    e.append(i+j)

e.sort()

f = []

for i in e:
  for j in z:
    f.append(i+j)

f.sort()
f.reverse()

for i in range(k[3]):
  print(f[i])


### FIXED CODE ###

X,Y,Z,K=map(int,input().split())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
C=[int(i) for i in input().split()]
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
SUM=[]
for i in range(X):
  for j in range(Y):
    for k in range(Z):
      if (i+1)*(j+1)*(k+1)<=K:
        SUM.append(A[i]+B[j]+C[k])
      else:
        break
SUM.sort(reverse=True)
for i in range(K):
  print(SUM[i])
### BUGGY CODE ###

n,m=map(int,input().split(' '))
war=[tuple(map(int,input().split(' '))) for _ in range(m)]
war.sort(key=lambda x:x[1])
bridge=[0]*n
for w in war:
    if sum(bridge[w[0]:w[1]])==0:
        bridge[w[1]-1]=1
print(sum(bridge))

### FIXED CODE ###

n,m=map(int,input().split(' '))
war=[tuple(map(int,input().split(' '))) for _ in range(m)]
war.sort(key=lambda x:x[1])
bridge=[0]*n
flag=0
for w in war:
    if not w[0]<=flag<w[1]:
        flag=w[1]-1
        bridge[flag]=1
print(sum(bridge))
### BUGGY CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def abc168_d():
    N, _ = map(int, readline().split())
    adj = [[] for _ in range(N+1)]
    for ln in readlines():
        a, b = map(int, ln.split())
        adj[a].append(b)
        adj[b].append(a)

    dist = [-1] * (N+1)
    label = [-1] * (N+1)
    dist[0] = dist[1] = 0
    label[0] = label[1] = 0

    stack = [1]
    while stack:
        x = stack.pop()
        for ch in adj[x]:
            if dist[ch] != -1 and dist[ch] < dist[x] + 1: continue
            dist[ch] = dist[x] + 1
            label[ch] = x
            stack.append(ch)

    if -1 in label:
        print('No')
        return
    else:
        print('Yes')
        print(*label[2:], sep='\n')

abc168_d()

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def abc168_d():
    N, _ = map(int, readline().split())
    adj = [[] for _ in range(N+1)]
    for ln in readlines():
        a, b = map(int, ln.split())
        adj[a].append(b)
        adj[b].append(a)

    label = [-1] * (N+1)
    label[0] = label[1] = 0

    from collections import deque
    que = deque([1])

    while que:
        k = que.popleft()
        for x in adj[k]:
            if label[x] != -1: continue  # 訪問済み
            label[x] = k  # 行先表示が確定
            que.append(x)  # キューに追加

    if -1 in label:
        print('No')
        return
    else:
        print('Yes')
        print(*label[2:], sep='\n')

abc168_d()
### BUGGY CODE ###

import bisect
import sys

sys.setrecursionlimit(200000)

n,q = (int(num) for num in input().split())
par = [i for i in range(n)]
nex = [[] for _ in range(n)]
ch = [0] * n
rank = [0] * n
val = [0] * n
ab = []
for i in range(n-1):
    a,b = (int(num)-1 for num in input().split())
    if a > b:
        a,b = b,a
    ab.append((a,b))
ab.sort(key = lambda x: x[0])
    
for item in ab:
    a = item[0]
    b = item[1]
    if rank[a] > rank[b]:
        nex[a].append(b)
        rank[a] = max(rank[a],rank[b])
    elif rank[a] < rank[b]:
        nex[b].append(a)
        rank[b] = max(rank[b],rank[a])
    elif a < b:
        nex[a].append(b)
        rank[a] += 1
    else:
        nex[b].append(a)
        rank[b] += 1
        
#print(par)
#print(nex)
#print(rank)

for _ in range(q):
    p,x = (int(num) for num in input().split())
    p -= 1
    val[p] += x
    
def calc(idx,nex,val,bias):
    val[idx] += bias
    if nex[idx] == []:
        return
    else:
        for i in nex[idx]:
            calc(i,nex,val,val[idx])
        
calc(0,nex,val,0)    
ans = ""    
for num in val:
    ans += str(num) + " "
print(ans)




### FIXED CODE ###

n,q = (int(num) for num in input().split())
par = [n] * n
visited = [0] * n
val = [0] * n
ab = []
for i in range(n-1):
    a,b = (int(num)-1 for num in input().split())
    par[b] = a
    
for _ in range(q):
    p,x = (int(num) for num in input().split())
    p -= 1
    val[p] += x

for i in range(1,n):
    val[i] += val[par[i]]
    
ans = ""
for num in val:
    ans += str(num) + " "
print(ans)
### BUGGY CODE ###

mod = 10**9 + 7
n = int(input())
A = [int(i) for i in input().split()]
for i in range(1,n+1):
	l = 0
	if A.count(i) > 1:
		l = i
		p = []
		for j in range(n+1):
			if A[j] == l:
				p.append(j)
		break
	if l:
		break

t = 1
d = 1
for k in range(n+1):

	t *= (n+1-k)%mod*pow(k+1,mod-2,mod)#n+1Ck
	t %= mod
	if not k:
		print(n)
	elif k <= n+p[0]-p[1]:
		d *= (n+p[0]-p[1]-k+1)%mod*pow(k,mod-2,mod)
		d %= mod
		print((t - d)%mod)
	else:
		print(t%mod)



### FIXED CODE ###

from collections import Counter
mod = 10**9 + 7
n = int(input())
A = [int(i) for i in input().split()]
C = Counter(A)
l = 0
for i in range(1,n+1):
	if C[i] > 1:
		l = i
		p = []
		for j in range(n+1):
			if A[j] == l:
				p.append(j)
				if len(p) > 1:
					break
		break
	if l:
		break

t = 1
d = 1
for k in range(n+1):

	t *= (n+1-k)%mod
	t %= mod
	t *= pow(k+1,mod-2,mod)
	t %= mod
	if not k:
		print(n)
	elif k <= n+p[0]-p[1]:
		d *= (n+p[0]-p[1]-k+1)%mod
		d %= mod
		d *= pow(k,mod-2,mod)
		d %= mod
		print((t - d)%mod)
	else:
		print(t%mod)
### BUGGY CODE ###

n = int(input())
n_list = [[] for _ in range(n+1)]
l_list = [0 for _ in range(n-1)]
for i in range(n-1):
    a,b = [int(_) for _ in input().split()]
    n_list[a].append((b,i))
    n_list[b].append((a,i))
# print(n_list)
k = 0
for i in range(n+1):
    k = max(k, len(n_list[i]))
# print(k)
c_list = []
for i in range(1, k+1):
    c_list.append(i)
# print(c_list)
todo = [(1,0)]
seen = [1]
while len(todo) != 0:
    p_from, c_from = todo.pop()
    i = 0
    for t in n_list[p_from]:
        p, l = t
        if p in seen:
            continue
        else:
            while c_list[i] == c_from:
                i += 1
            color = c_list[i]
            i += 1
            todo.append((p,color))
            l_list[l] = color
            seen.append(p)
    # print(todo)
    # print(seen)
# print(l_list)
print(k)
for i in l_list:
    print(i)

### FIXED CODE ###

n = int(input())
n_list = [[] for _ in range(n+1)]
l_list = [0 for _ in range(n-1)]
for i in range(n-1):
    a,b = [int(_) for _ in input().split()]
    n_list[a].append((b,i))
    n_list[b].append((a,i))
# print(n_list)
k = 0
for i in range(n+1):
    k = max(k, len(n_list[i]))
# print(k)
c_list = []
for i in range(1, k+1):
    c_list.append(i)
# print(c_list)
todo = [(1,0,0)]
seen = [1]
while len(todo) != 0:
    p_from, c_from, before = todo.pop()
    i = 0
    for t in n_list[p_from]:
        p, l = t
        if p == before:
            continue
        else:
            while c_list[i] == c_from:
                i += 1
            color = c_list[i]
            i += 1
            todo.append((p,color,p_from))
            l_list[l] = color
            seen.append(p)
        # print(todo)
    # print(seen)
# print(l_list)
print(k)
for i in l_list:
    print(i)
### BUGGY CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
val = 1
for i in range(0, k):
    val *= a[i]
    
for i in range(k, n):
    num = 1
    for j in range(i-k+1, i+1):
        num *= a[j]
    if num > val:
        print('Yes')
    else:
        print('No')
    val = num


### FIXED CODE ###

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

for i in range(k, n):
    if a[i] > a[i-k]:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

import sys

def main():
    N = int(input())
    A = list(map(int, sys.stdin.readlines()))
    
    arr = [A[0]]
    for a in A[1:]:
        for i in range(len(arr)):
            if a > arr[i]:
                arr[i] = a
                break
        else:
            arr.append(a)
        arr.sort(reverse=True)
    print(len(arr))
    
if __name__=='__main__':
    main()

### FIXED CODE ###

import sys
import bisect
from collections import deque

def main():
    _ = int(input())
    A = list(map(int, sys.stdin.readlines()))
    
    arr = deque()
    arr.append(A[0])
    for a in A[1:]:
        if a <= arr[0]:
            arr.appendleft(a)
        else:
            insert_index = bisect.bisect_left(arr, a)
            update = max(0, insert_index-1)
            arr[update] = a
    print(len(arr))
    
if __name__=='__main__':
    main()
### BUGGY CODE ###

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

allhiyatoi = []
for i in range(N):
    temp = list(map(int,input().split()))
    allhiyatoi.append(temp)

allhiyatoi.sort(key=lambda x: x[1], reverse = True)

reward = [0] * (M+1)
finish = set([])
remain = set(range(M+1))
for hiya in allhiyatoi:
    if hiya[0]>M:
        continue
    if max(remain)<hiya[0]:
        continue
    now = remain - finish
    for i in remain:
        if i<hiya[0]:
            continue
        if reward[i] == 0:
            reward[i] = hiya[1]
            finish.add(i)
            break

print(sum(reward))

### FIXED CODE ###

from heapq import heappush, heappop
 
N,M = map(int,input().split())

allhiyatoi = [[] for j in range(M+1)]
for i in range(N):
    temp = list(map(int,input().split()))
    if temp[0] > M:
        continue
    allhiyatoi[temp[0]].append(temp[1])
 
reward = 0
Q = []
for i in allhiyatoi:
    for j in i:
        heappush(Q,j*-1)
    if len(Q) == 0:
        continue
    reward -= (heappop(Q))

print(reward)