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

n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
d=[a[0]]
ans=0
for i in range(1,n):
  tmp=max(d)
  ans=ans+tmp
  d.remove(tmp)
  d.append(a[i])
  d.append(a[i])
print(ans)


### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
ans=0
for i in range(1,n):
  ans=ans+a[i//2]
print(ans)
### BUGGY CODE ###

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

x = x-1
y = y-1

G = [[i-1,i+1] for i in range(n)]

G[0] = [1]
G[-1]= [n-2]

G[x].append(y)
G[y].append(x)

count_mat = [[float('inf')]*n for i in range(n)]

def bfs(ini):
    visited = set()
    visited.add(ini)
    prev_steps = [ini]
    count_mat[ini][ini] = 0
    count = 0
    next_steps = set()
    
    while len(prev_steps) != 0:
        count +=1
        for prev_step in prev_steps:#前にいたところ
            for next_step in G[prev_step]:#次にいくところ
                next_steps.add(next_step)
        next_steps = next_steps - visited#すでに訪れたところを引く
        for next_step in next_steps:
            visited.add(next_step)
            count_mat[ini][next_step] = count
            count_mat[next_step][ini] = count
        prev_steps = next_steps
        next_steps = set()
for i in range(0, n):
    bfs(i)

count_dict = {i : 0 for i in range(0, n)}
for row in count_mat:
    for k in row:
        count_dict[k] =count_dict[k]  + 1

for i in range(1, n):
    print(count_dict[i] // 2)

### FIXED CODE ###

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

x = x-1
y = y-1

count_dict = {i : 0 for i in range(0, n)}

for i in range(n):
    for k in range(n):
        key = min(abs(i-k), abs(i-x)+abs(k-y) + 1, abs(i-y) +abs(k-x) + 1)
        count_dict[key] += 1

for i in range(1, n):
    print(count_dict[i] //2)
### BUGGY CODE ###

n, m = map(int, input().split())
city_list = [[0] for _ in range(n + 1)]
city = [[]]
for _ in range(m):
    p, y = map(int, input().split())
    city_list[p].append(y)
    city.append([p, y])
for i in range(1, n + 1):
    city_list[i].sort()
for i in range(1, m + 1):
    ID = ''
    p = city[i][0]
    order = str(city_list[p].index(city[i][1]))
    p = str(p)
    for _ in range(6 - len(p)):
        ID += '0'
    ID += p
    for _ in range(6 - len(order)):
        ID += '0'
    ID += order
    print(ID)

### FIXED CODE ###

from bisect import bisect_left
n, m = map(int, input().split())
city_list = [[0] for _ in range(n + 1)]
city = [[]]
for _ in range(m):
    p, y = map(int, input().split())
    city_list[p].append(y)
    city.append([p, y])
for i in range(1, n + 1):
    city_list[i].sort()
for i in range(1, m + 1):
    ID = ''
    p = city[i][0]
    order = str(bisect_left(city_list[p], city[i][1]))
    #order = str(city_list[p].index(city[i][1]))
    p = str(p)
    ID = ID + ('0' * (6 - len(p)))
    ID += p
    ID += ('0' * (6 - len(order)))
    ID += order
    print(ID)
### BUGGY CODE ###

from collections import deque

h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]
move = [(1,0), (0,1), (-1,0), (0,-1)]

queue = deque([(row, col, 0) for row in range(h) for col in range(w) if a[row][col] == "#"])
visited = [[-1]*w for _ in range(h)]

max_dist = 0
while queue:
    row, col, dist = queue.popleft()
    if visited[row][col] == -1:
        visited[row][col] = 0
    if max_dist < dist:
        max_dist = dist
    for drow, dcol in move:
        if row+drow>=0 and row+drow<h and col+dcol>=0 and col+dcol<w and visited[row+drow][col+dcol] == -1:
            visited[row+drow][col+dcol] == dist + 1
            queue.append((row+drow, col+dcol, dist+1))


print(max_dist)


### FIXED CODE ###

from collections import deque

h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]
move = [(1,0), (0,1), (-1,0), (0,-1)]

queue = deque()
visited = [[-1] * w for _ in range(h)]
for row in range(h):
    for col in range(w):
        if a[row][col] == "#":
            visited[row][col] = 0
            queue.append((row, col, 0))
dist = 0
while queue:
    row, col, dist = queue.popleft()
    for drow, dcol in move:
        if a[row+drow:row+drow+1] and a[row+drow][col+dcol:col+dcol+1] and visited[row+drow][col+dcol] == -1 and a[row+drow][col+dcol] == ".":
            visited[row+drow][col+dcol] = dist + 1
            queue.append((row+drow, col+dcol, dist+1))


print(dist)
### BUGGY CODE ###

import sys
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=A+B
C.sort()
if sum(C)<=K :
    print(len(C))
    sys.exit()
for i in range(len(C)) :
    if sum(C[:i])>K :
        print(i-1)
        sys.exit()

### FIXED CODE ###

N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

a=[0]
b=[0]

for i in range(N):
    a.append(a[i]+A[i])
for i in range(M):
    b.append(b[i]+B[i])
j=M
ans=0
for i in range(N+1):#aは小さい方から
    if a[i]>K:    #a[0]=0なのでいきなりbreakすることはない
        break
    while b[j]>K-a[i] : #bは大きい方から
        j-=1            #j,ansの値は次のループに引き継がれる
    ans=max(ans,i+j)
print(ans)
### BUGGY CODE ###

k, s = [int(n) for n in input().split()]

count = 0
for i in range(k+1):
    for j in range(k+1):
        for l in range(k+1):
            if i + j + l == s:
                count += 1

print(count)

### FIXED CODE ###

k, s = [int(n) for n in input().split()]

count = 0
for x in range(k+1):
    for y in range(k+1):
        if 0 <= s - (x + y) <= k:
            count += 1

print(count)
### BUGGY CODE ###

N=int(input())
S=input().split()
NS = [int(i) for i in S]
def exist():
    s=0
    for i in range(N):
      if min(NS[:i+1])>=NS[i]:
         s+=1
    return s
if __name__=='__main__':
   print(exist())
    

### FIXED CODE ###

N=int(input())
S=input().split()
NS = [int(i) for i in S]
def minL():
  ml=[NS[0]]
  for i in range(1,N):
     ml+=[min(ml[i-1],NS[i])]
  return ml  

MINL=minL()
def exist():
    s=0
    for i in range(N):
      if MINL[i]>=NS[i]:
         s+=1
    return s
if __name__=='__main__':
   print(exist())
### BUGGY CODE ###

#coding; utf-8
import copy
N, k = map(int,input().split())
A = list(map(int,input().split()))
B = [0] * N
A = [0] + A
#B = copy.copy(A)
for j in range(k):
    #print(A)
    n_light = [0] * (N+1)
    for i in range(N):
        d = A[i+1]
        l = i+1-d
        r = i+1+d
        #print(l, r)
        n_light[max(l, 1)] += 1
        if r+1 <= N:# and l != r:
            n_light[r+1] -= 1
        #print(n_light)
    #print(n_light)
    for i in range(1,N):
        n_light[i+1] += n_light[i]
    n_str = [str(i) for i in n_light]
    A = n_light 
print(' '.join(n_str[1:]))
    


### FIXED CODE ###

#coding; utf-8
import copy
N, k = map(int,input().split())
A = list(map(int,input().split()))
B = [0] * N
A = [0] + A
#B = copy.copy(A)
#k = 10
for j in range(k):
    #print(A)
    n_light = [0] * (N+1)
    for i in range(N):
        d = A[i+1]
        l = i+1-d
        r = i+1+d
        #print(l, r)
        n_light[max(l, 1)] += 1
        if r+1 <= N:# and l != r:
            n_light[r+1] -= 1
        #print(n_light)
    #print(n_light)
    for i in range(1,N):
        n_light[i+1] += n_light[i]
    n_str = [str(i) for i in n_light]
    if len(set(n_light[1:])) == 1 and j > 2:
        #print(n_light)
        break
    #n_str = [str(i) for i in n_light]
    A = n_light
    #print(n_light) 
print(' '.join(n_str[1:]))
### BUGGY CODE ###

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

ans = 1
for i in range(n):
    ans = ans * a[i]

if ans > pow(10,18):
    print("-1")
else:
    print(ans)

### FIXED CODE ###

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

ans = 1
a.sort()
for i in range(n):
    ans = ans * a[i]
    if ans == 0:
        ans = 0
        break
    if ans > pow(10,18):
        ans = -1
        break

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

def resolve():

    N=int(input())
    A=list(map(int,input().split()))
    ls=[0]*N
    for i in range(N):
        ls[i]=(i,A[i]-1)
    cnt=0
    for (s,t) in ls:
        if (t,s) in ls:
            cnt+=1
    print(cnt//2)



resolve()

### FIXED CODE ###

def resolve():

    N=int(input())
    A=list(map(int,input().split()))
    cnt=0
    for i in range(N):
        if A[A[i]-1]==i+1:
            cnt+=1
    print(cnt//2)



resolve()
### BUGGY CODE ###

NK = input().split()
N, K = int(NK[0]), int(NK[1])
lis_p = list(map(lambda x: int(x), input().split()))
lis_exp = list(map(lambda x: x*(x+1)/2/x, lis_p))
dp=0
for i in range(N):
    dp = max(sum(lis_exp[i:i+K]), dp)
print(dp)

### FIXED CODE ###

N, K = map(int, input().split())
lis_p = map(int, input().split())
def calc_exp(x):
    return (int(x) + 1)/2
lis_exp = list(map(calc_exp, lis_p))
dp= sum(lis_exp[0:K])
cumKsum = sum(lis_exp[0:K])
for i in range(1, N-K+1):
    cumKsum = cumKsum - lis_exp[i-1] + lis_exp[i+K-1]
    dp = max(cumKsum, dp)
print(dp)
### BUGGY CODE ###

# -*- coding:utf-8 -*-
import sys

# n??\???????´???°?????°?????????
def prime(n):
    l = range(0,n+1)
    i,k = 0,2
    result = 1

    if n >= 3:
        prime_nums = [2, 3]
    else:
        prime_nums = []

    while i <= n:
        while l[i] > k:
            result = l[i]%k
            k = k+1
            if result == 0:
                break
            if (l[i]-1 == k) and (result != 0):
                prime_nums.append(l[i])

        i, k = i+1, 2

    #return prime_nums
    return len(prime_nums)

while True:
    try:        
        psum = prime(int(input()))
        print(psum)
    except:
        break

### FIXED CODE ###

from math import sqrt
I_list=[]
prime_list=[]
while True:
    try:
        I_list.append(int(input()))
    except:
        break
I_max=max(I_list)
search_set={x for x in range(2,I_max+1)}
 
 
p=-1
while p<=sqrt(I_max):
    p=min(search_set)
    prime_list.append(p)
    search_set={x for x in search_set if x%p !=0 }
 
search_list=sorted(list(search_set))
prime_list+=search_list
 
#print(prime_list)
 
 
for i in I_list:
    lower_set={j for j in prime_list if j<=i } 
#   print(lower_set)
    print(len(lower_set))
### BUGGY CODE ###

n,k = list(map(int,input().split()))
h = list(map(int, input().split()))
if n<=k:
  print("0")
  exit()
for i in range(k):
  h.remove(max(h))
print(sum(h))

### FIXED CODE ###

n,k = list(map(int,input().split()))
h = list(map(int, input().split()))
if n<=k:
  print("0")
  exit()
new_h = sorted(h)
for i in range(k):
  new_h.pop(-1)
print(sum(new_h))
### BUGGY CODE ###

n, m = map(int, input().split())
a = [int(input()) for _ in range(m)]
s = [1]*(n+1)

if 1 in a:
    s[1] = 0

for i in range(n-1):
    if i+2 in a:
        s[i+2] = 0
        continue
    s[i+2] = (s[i+1] + s[i]) % (10**9+7)

print(s[-1])

### FIXED CODE ###

n, m = map(int, input().split())
a = set([int(input()) for _ in range(m)])

s = [1]*(n+1)

if 1 in a:
    s[1] = 0

for i in range(n-1):
    if i+2 in a:
        s[i+2] = 0
        continue
    s[i+2] = (s[i+1] + s[i]) % (10**9+7)
    
print(s[-1])
### BUGGY CODE ###

def main():
    n = int(input())
    a = sorted([int(input()) for _ in [0]*n])
    dp = [1]
    DP = [1]
    s = 1
    mod = 998244353
    for i in a:
        dp2 = dp+([0]*i)
        DP2 = DP+([0]*i)
        for j in range(s):
            dp2[i+j] = (dp2[i+j]+2*dp[j]) % mod
            DP2[i+j] = (DP2[i+j]+DP[j]) % mod
        dp = dp2
        DP = DP2
        s += i
    ALL = sum(dp)
    A = sum(dp[(s-1)//2+1:])
    if s % 2 == 1:
        B = DP[s//2]
    else:
        B = 0
    print((3*A-2*ALL+3*B) % mod)


main()


### FIXED CODE ###

def main():
    n = int(input())
    a = sorted([int(input()) for _ in [0]*n])
    dp = [1]
    DP = [1]
    s = 1
    mod = 998244353
    for i in a:
        dp2 = dp+([0]*i)
        DP2 = DP+([0]*i)
        for j in range(s):
            dp2[i+j] = (dp2[i+j]+2*dp[j]) % mod
            DP2[i+j] = (DP2[i+j]+DP[j]) % mod
        dp = dp2
        DP = DP2
        s += i
    ALL = sum(dp)
    A = sum(dp[(s-1)//2+1:])
    if s % 2 == 1:
        B = DP[s//2]
    else:
        B = 0
    print((3*A-2*ALL+3*B) % mod)


main()
### BUGGY CODE ###

import math
K = int(input())
gcd = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in (range(1, K+1)):
            tmp = math.gcd(a, b)
            gcd += math.gcd(tmp, c)
print(gcd)


### FIXED CODE ###

import math
K = int(input())
gcd: int = 0
a: int = 0
b: int = 0
c: int = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in (range(1, K+1)):
            tmp = math.gcd(a, b)
            gcd += math.gcd(tmp, c)
    
print(gcd)
### BUGGY CODE ###

n, q = map(int, raw_input().split())
fish = [0] * n
for i in range(q):
	a, v = map(int, raw_input().split())
	fish[a-1] = fish[a-1] + v
	ans1 = fish.index(max(fish)) + 1
	ans2 = max(fish)
	print "{} {}".format(ans1, ans2)

### FIXED CODE ###

n, q = map(int, raw_input().split())
fish = [0] * n
ans1 = 0
ans2 = 0
for i in range(q):
	a, v = map(int, raw_input().split())
	fish[a-1] = fish[a-1] + v
	if ans1 == a and v < 0:
		ans1 = fish.index(max(fish)) + 1
		ans2 = max(fish)
	elif ans2 < fish[a-1]:
		ans1 = a
		ans2 = fish[a-1]
	elif ans2 == fish[a-1] and a < ans1:
		ans1 = a
	print "{} {}".format(ans1, ans2)
### BUGGY CODE ###

N = int(input())

dct = {}

for i in range(N):
    s = input()
    if not s in dct:
        dct[s] = 1

    else:
        dct[s] +=  1
    
ans = [x[0] for x in dct.items() if x[1] == max(dct.values())]
for j in sorted(ans):
    print(j)

### FIXED CODE ###

N = int(input())

dct = {}

for i in range(N):
    s = input()
    if not s in dct:
        dct[s] = 1

    else:
        dct[s] +=  1
    
m = max(dct.values())
for s in sorted(k for k in dct if dct[k] == m):
    print(s)
### BUGGY CODE ###

s=input()

l=[0]
ans=[0]*(len(s))
for i in range(len(s)-1):
    if s[i]=="L" and s[i+1]=="R":
        l.append(i+1)
       
n=len(l)+1
l.append(len(s))
#print(set(s[l[0]:l[1]]))

for i in range(n-1):
    #print(s[l[i]:l[i+1]])
    for j in range(len(s[l[i]:l[i+1]])-1):
        p=len(s[l[i]:l[i+1]])
        if s[l[i]:l[i+1]][j]=="R" and s[l[i]:l[i+1]][j+1]=="L":
            if j%2==1:
                ans[l[i]+j]=p//2
                ans[l[i]+j+1]=p-p//2
                break
            else:
                ans[l[i]+j]=p-p//2
                ans[l[i]+j+1]=p//2
                break
        if set(s[l[i]:l[i+1]])=={"L"}:
            ans[l[i]]=p
        if set(s[l[i]:l[i+1]])=={"R"}:
            ans[l[i+1]-1]=p
print(*ans)


            
  


### FIXED CODE ###

s=input()

l=[0]
ans=[0]*(len(s))
for i in range(len(s)-1):
    if s[i]=="L" and s[i+1]=="R":
        l.append(i+1)
       
n=len(l)+1
l.append(len(s))
#print(set(s[l[0]:l[1]]))

for i in range(n-1):
    #print(s[l[i]:l[i+1]])
    for j in range(len(s[l[i]:l[i+1]])-1):
        p=len(s[l[i]:l[i+1]])
        if s[l[i]]=="L":
            ans[l[i]]=p
            break
        if s[l[i+1]-1]=="R":
            ans[l[i+1]-1]=p
            break
        if s[l[i]:l[i+1]][j]=="R" and s[l[i]:l[i+1]][j+1]=="L":
            if j%2==1:
                ans[l[i]+j]=p//2
                ans[l[i]+j+1]=p-p//2
                break
            else:
                ans[l[i]+j]=p-p//2
                ans[l[i]+j+1]=p//2
                break
print(*ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline


def read():
    N, S = map(int, input().strip().split())
    A = list(map(int, input().strip().split()))
    return N, S, A


def solve(N, S, A, MOD=998244353):
    A = list(sorted(A))
    dp = [0 for j in range(S+1)]
    dp[0] = 1
    for i in range(N):
        for j in range(S, -1, -1):
            v = 2 * dp[j]
            if j - A[i] >= 0:
                v += dp[j-A[i]]
            dp[j] = v % MOD
    return dp[S]


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


### FIXED CODE ###

import sys
input = sys.stdin.readline
import numpy as np
from numba import njit


def read():
    N, S = map(int, input().strip().split())
    A = np.fromstring(input().strip(), dtype=np.int32, sep=" ")
    return N, S, A


@njit
def solve(N, S, A, MOD=998244353):
    dp = np.zeros((S+1), dtype=np.int32)
    dp[0] = 1
    for i in range(N):
        for j in range(S, -1, -1):
            v = 2 * dp[j]
            if j - A[i] >= 0:
                v += dp[j-A[i]]
            dp[j] = v % MOD
    return dp[S]


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))
### BUGGY CODE ###

n, q = map(int, input().split())
s = input()
lr = [tuple(map(int, input().split())) for _ in range(q)]

# table[i] = i文字目以下のsにACは部分文字列として何回現れるか
table = []
for i in range(n+1):
    table.append(s[:i].count('AC'))

for l, r in lr:
    print(table[r] - table[l])

### FIXED CODE ###

n, q = map(int, input().split())
s = input()
lr = [tuple(map(int, input().split())) for _ in range(q)]

# table[i] = i文字目以下のsにACは部分文字列として何回現れるか
table = [None] * (n+1)
table[0] = 0
table[1] = 0
for i in range(2, n+1):
    if s[i-2:i] == 'AC':
        table[i] = table[i-1] + 1
    else:
        table[i] = table[i-1]

for l, r in lr:
    print(table[r] - table[l])
### BUGGY CODE ###

# coding: utf-8
R, G, B, N = map(int, input().split())

output = 0
for g in range(N // G + 1):
    for b in range(N // B + 1):
        if (N - g*G - b*B) % R == 0:
            if N >= g*G + b*B:
                output += 1
            else:
                break
print(output)


### FIXED CODE ###

# coding: utf-8
R, G, B, N = map(int, input().split())

output = 0
# for g in range(N // G + 1):
#     for b in range(N // B + 1):
#         if (N - g*G - b*B) % R == 0:
#             if N >= g*G + b*B:
#                 output += 1
#             else:
#                 break

for r in range(N // R + 1):
    C = N - r*R
    for g in range(C // G + 1):
        if (C - g*G) % B == 0:
            if C >= g*G:
                output += 1
            else:
                break

print(output)
### BUGGY CODE ###

a = list(input())
Q = int(input())
B = []
C = []
A = [list(input().split()) for _ in range(Q)]
for i in range(len(A)):
  if len(A[i]) == 1:
    a.reverse()
  elif A[i][1] == "1":
    a.insert(0,A[i][2])
  elif A[i][1] == "2":
    a.append(A[i][2])
print(''.join(a))

### FIXED CODE ###

from collections import deque
a = list(input())
Q = int(input())
d = deque(a)
ans = 1
for i in range(Q):
  b = list(input().split())
  if len(b) == 1:
    ans += 1
  elif b[1] == "1" and ans % 2 == 1:
    d.appendleft(b[2])
  elif b[1] == "1" and ans % 2 == 0:
    d.append(b[2])
  elif b[1] == "2" and ans % 2 == 1:
    d.append(b[2])
  elif b[1] == "2" and ans % 2 == 0:
    d.appendleft(b[2])
if ans % 2 == 0:
  d.reverse()
print("".join(d))
### BUGGY CODE ###

import collections

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

setB = list(set(B))
n = len(setB)
Num = [0]*n
for j in range(n):
  Num[j] = B.count(setB[j])
  
for i in range(N):
  res = 0
  for j in range(n):
    if B[i] == setB[j]:
      res += (Num[j]-1)*(Num[j]-2)/2
    else:
      res += Num[j]*(Num[j]-1)/2
  print(int(res))

### FIXED CODE ###

N = int(input())
B = list(map(int, input().split()))
count = {}

for i in B:
  if i in count:
    count[i] += 1
  else:
    count[i] = 1
    
total = 0
for i in count:
  total += count[i]*(count[i]-1)/2
  
for i in range(N):
  k = count[B[i]]
  print(int(total-k+1))
### BUGGY CODE ###

import itertools
while True:
    n,s=map(int,raw_input().split())
    if n==s==0:break
    cnt=0
    for i in itertools.combinations(range(101),n):
        if len(set(i))==n and sum(i)==s:
            cnt+=1
    print cnt

### FIXED CODE ###

dp=[[0]*1001 for i in range(11)]
dp[0][0]=1
for i in range(101):
    for j in range(10)[::-1]:
        for k in range(1001-i):
            dp[j+1][k+i]+=dp[j][k]
while True:
    n,s=map(int,raw_input().split())
    if n==s==0:break
    print dp[n][s]
### BUGGY CODE ###

import sys
input = sys.stdin.readline


def main():
    num = 0
    _ = input()
    A = sorted(list(map(int, input().split())))
    for i in range(len(A)-1):
        for j in range(i+1, len(A)):
            a = A[i]
            b = A[j]
            thresh = a + b
            ok = j
            ng = len(A)
            idx = binary_search(A, ok, ng, thresh)
            num += idx - j

    print(num)


def binary_search(li, ok, ng, value):
    while abs(ok-ng) > 1:
        mid = (ok + ng) // 2
        if li[mid] < value:
            ok = mid
        else:
            ng = mid

    return ok


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline
 
 
def main():
    num = 0
    _ = input()
    A = sorted(list(map(int, input().split())))
    for i in range(len(A)-1):
        for j in range(i+1, len(A)):
            a = A[i]
            b = A[j]
            thresh = a + b
            ok = j
            ng = len(A)
            idx = binary_search(A, ok, ng, thresh)
            num += idx - j
 
    print(num)
 
 
def binary_search(li, ok, ng, value):
    while abs(ok-ng) > 1:
        mid = (ok + ng) // 2
        if li[mid] < value:
            ok = mid
        else:
            ng = mid
 
    return ok
 
 
if __name__ == "__main__":
    main()
### BUGGY CODE ###

N,M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
used = [0]*N
ans = [0]*(M+1)

for i in range(1,M+1):
  m = 10**9+1
  for j in range(N):
    if AB[j][0] <= i and used[j] == 0:
      ans[i] = max(ans[i], AB[j][1])
      if ans[i] == AB[j][1]:
        m = j
  if m != 10**9+1:
    used[m] = 1
  else:
    pass
print(sum(ans))

### FIXED CODE ###

from heapq import *
N,M = map(int,input().split())
l = [[0] for _ in range(M+1)] 
for _ in range(N):
    a, b = map(int, input().split())
    if a<=M:
        l[a].append(b)

ans = 0
h = []

for i in range(1,M+1):
  for j in l[i]:
    heappush(h, -j)
  ans += heappop(h)
ans *= -1
print(ans)
### BUGGY CODE ###

import sys
import numpy as np
sys.setrecursionlimit(10 ** 7)

N, A, B = map(int, input().split())

MOD = 10 ** 9 + 7


ans = 2 ** N - 1
ans %= MOD


def cumprod(arr, MOD):
    L = len(arr)
    Lsq = int(L**.5+1)
    arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq)
    for n in range(1, Lsq):
        arr[:, n] *= arr[:, n-1]
        arr[:, n] %= MOD
    for n in range(1, Lsq):
        arr[n] *= arr[n-1, -1]
        arr[n] %= MOD
    return arr.ravel()[:L]


def make_fact(U, MOD):
    x = np.arange(U, dtype=np.int64)
    x[0] = 1
    fact = cumprod(x, MOD)
    x = np.arange(U, 0, -1, dtype=np.int64)
    x[0] = pow(int(fact[-1]), MOD-2, MOD)
    fact_inv = cumprod(x, MOD)[::-1]
    return fact, fact_inv


fact, fact_inv = make_fact(B + 10, MOD)

arr = cumprod(list(range(N, N-B, -1)), MOD)

a = arr[A - 1] * fact_inv[A]
a %= MOD
b = arr[B-1] * fact_inv[B]
b %= MOD

# print(mb)
# print(fact_inv)

'''
a = ma * fact_inv[A]
a %= MOD

b = mb * fact_inv[B]
b %= MOD
'''

ans -= (a + b)
ans %= MOD

print(ans)


### FIXED CODE ###

import sys
import numpy as np
sys.setrecursionlimit(10 ** 7)

N, A, B = map(int, input().split())

MOD = 10 ** 9 + 7


def myPow(x, n, MOD):
    if n == 0:
        return 1

    res = 1
    while(n > 0):
        if n & 1 == 1:
            res = res * x % MOD

        x = x * x % MOD
        n = n >> 1

    return res


ans = myPow(2, N, MOD)
ans -= 1

# print("hoge")


def cumprod(arr, MOD):
    L = len(arr)
    Lsq = int(L**.5+1)
    arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq)
    for n in range(1, Lsq):
        arr[:, n] *= arr[:, n-1]
        arr[:, n] %= MOD
    for n in range(1, Lsq):
        arr[n] *= arr[n-1, -1]
        arr[n] %= MOD
    return arr.ravel()[:L]


def make_fact(U, MOD):
    x = np.arange(U, dtype=np.int64)
    x[0] = 1
    fact = cumprod(x, MOD)
    x = np.arange(U, 0, -1, dtype=np.int64)
    x[0] = pow(int(fact[-1]), MOD-2, MOD)
    fact_inv = cumprod(x, MOD)[::-1]
    return fact, fact_inv


fact, fact_inv = make_fact(B + 10, MOD)

arr = cumprod(list(range(N, N-B, -1)), MOD)

a = arr[A - 1] * fact_inv[A]
a %= MOD
b = arr[B-1] * fact_inv[B]
b %= MOD

# print(mb)
# print(fact_inv)

'''
a = ma * fact_inv[A]
a %= MOD

b = mb * fact_inv[B]
b %= MOD
'''

ans -= (a + b)
ans %= MOD

print(ans)