Harryxun/stf_run huggingface dataset:
import sys
import numpy as np
def main():
    input = sys.stdin.readline
    N = int(input())
    ans = (1 + (N - 1)) / 2 * (N - 1)

    if N <= 1e07:
      a = np.arange(start=1, step=1, stop=N+1)
      if N %2 == 1:
        bol = (a % ((N+1)/2) >= a)
        ans += np.sum((a % ((N+1)/2)[bol] - a[bol]))
      else:
        bol = (a % (N/2) >= a)
        ans += np.sum((a % (N/2)[bol] - a[bol]))

    print(int(ans))

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
import numpy as np
def main():
    input = sys.stdin.readline
    N = np.int64(input())
    #print(N)
    #ans = np.int64((1 + (N - 1)) / 2 * (N - 1))
    ans = (1 + (N - 1)) * (N - 1) // 2
    print(int(ans))
if __name__ == '__main__':
    main()
k=int(input())
s=input()
import numpy as np
p=list(s)
l=len(p)
if l<=k:
  print(s)
else:
  arr=np.array(p)
  print(p+'...')

### FIXED CODE ###

k=int(input())
s=input()
import numpy as np
p=list(s)
l=len(p)
if l<=k:
  print(s)
else:
  arr=np.array(p)
  arr=arr[0:k]
  print(''.join(list(arr))+'...')
N = input()
N = N%1000
ans = 1000 - N if not N else 0
print(ans)

### FIXED CODE ###

N = int(input())
N = N % 1000
ans = 1000 - N if N else 0
print(ans)
# -*- coding: utf-8 -*-
import sys
import itertools#これは色々使える組み込み関数みたいなやつ
import math#数学的計算はこれでいける。普通に0.5乗しても計算可能
#w=input()
i=0
#N=int(input())
A, B=input().split()
A=int(A)
B=int(B)
print(int((A*B)/math.gcd(A, B)))


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
import itertools#これは色々使える組み込み関数みたいなやつ
#import math#数学的計算はこれでいける。普通に0.5乗しても計算可能
#w=input()
#a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#a,bの最小公倍数
def lcm(a, b):
    return a * b // gcd (a, b)
i=0
#N=int(input())
A, B=input().split()
A=int(A)
B=int(B)
print(lcm(A, B))
if a + W < b:
    print(b - a - W)
elif a + W = b:
    print(0)
elif (b < a + W) & (a < b):
    print(0)
elif a == b:
    print(0)
elif b < a:
    print(0)
elif a = b + W:
    print(0)
elif b + W < a:
    print(a - b - W)
else:
    pass


### FIXED CODE ###

a, b = map(str, input().split())

if a == b:
    print("H")
elif not a == b:
    print("D")
N=int(input())
lis=[]
res=[]
for i in range(101):
    for j in range(101):
        lis.append([i,j])
l2=[]
for i in range(N):
    l2.append(list(map(int, input().split())))
l2.sort(key=lambda x:x[2])
for i in lis:
    n=N
    l=0
    for j in l2:
        if j[2]==0:
            k=abs(i[0]-j[0])+abs(i[1]-j[1])+j[2]
            if k<l:
                n-=1
                continue
            else:
                if l==k or l==0:
                    l=k
                    n-=1
                else: break
        else:
            k=abs(i[0]-j[0])+abs(i[1]-j[1])+j[2]
            if l==k or l==0:
                l=k
                n-=1
            else: break
        if n==0:
            m=(i[0],i[1],l)
print('{} {} {}'.format(m[0],m[1],m[2]))

### FIXED CODE ###

N=int(input())
lis=[]
for i in range(101):
    for j in range(101):
        lis.append([i,j])
l2=[]
for i in range(N):
    l2.append(list(map(int, input().split())))
l2.sort(key=lambda x:x[2],reverse=True)
for i in lis:
    n=N
    l=0
    for j in l2:
        k=abs(i[0]-j[0])+abs(i[1]-j[1])+j[2]
        if j[2]==0:
            if k>l:
                n-=1
            else:
                if l==k or l==0:
                    l=k
                    n-=1
                else: break
        else:
            if l==k or l==0:
                l=k
                n-=1
            else: break
        if n==0:
            m=(i[0],i[1],l)
print('{} {} {}'.format(m[0],m[1],m[2]))
n = int(input())
c = input()
d = c.count(w)
e = c.count(w)[:d]
print(d-e)

### FIXED CODE ###

n = int(input())
c = input()
d = c.count('R')
e = c[:d].count('R')
print(d-e)
n,m = map(int,input().split(" "))
a=[]
ans = 1
for i in range(m):
    a.append(int(input()))
    if a[i]-1 == a[i-1]:
        ans = 0
if ans == 1:
    t,w,v = 0,0,0
    for j in range(len(a)):
        if j+1 == m:
            if n-a[j] >= 3:
                v += 1
                w += n-a[j]
            break
        elif a[j] - t >= 3:
            v += 1
            w += a[j] - t
            t = a[j] + 1
        else:
            t = a[j] + 1
ans = v * 2
t = ans // 2
for k in range(w):
    temp = ans
    ans += t
    t = temp

print(ans % 1000000007)


### FIXED CODE ###

n,m = map(int,input().split(" "))
a=[0] * (n+1)
mod = 10 ** 9 + 7
for i in range(m):
    a[int(input())] = 1

dp = [0] * (n+1)
for j in range(n+1):
    if a[j] == 1:
        dp[j] = 0
    elif j == 1 or j == 0:
        dp[j] = 1
    else:
        dp[j] = (dp[j-1] + dp[j-2]) % mod

print(dp[n])
import fractions
n=int(input())
lists=[]
for s in range(n):
    s=int(input())
    lists.append(s)
lists.append(1)
print(lists)
glm=lists[0]
cnt=0
while cnt<n:
    gcd=fractions.gcd(glm,lists[cnt+1])
    glm=int(glm*lists[cnt+1]/gcd)
    cnt+=1    
print(glm)

### FIXED CODE ###

#早くmathを導入してほしい
from fractions import gcd
n=int(input())
glm=1
for i in range(n):
    nums=int(input())
    glm=int(glm*nums//gcd(nums,glm))
print(glm)
from itertools import accumulate
N, C = map(int, input().split())
TimeTable = [[0] * (10 ** 5 + 1) for i in range(C + 1)]
for i in range(N):
    s, t, c = map(int, input().split())
    TimeTable[c][s] += 1
    TimeTable[c][t + 1] -= 1

for c in range(C + 1):
    TimeTable[c] = list(accumulate(TimeTable[c]))


ans = 0
for i in range(10 ** 5 + 1):
    cnt = 0
    for c in range(C + 1):
        cnt += min(TimeTable[c][i], 1)
    ans = max(ans, cnt)

print(ans)


### FIXED CODE ###

import numpy

N, C = map(int, input().split())
STC = [list(map(int, input().split())) for i in range(N)]
Channel = numpy.array([[0]*(2*10**5+1) for i in range(C+1)])

for s, t, c in STC:
    Channel[c][2*s-1] += 1
    Channel[c][2*t] -= 1
    
for i in range(len(Channel)):
    Channel[i] = numpy.cumsum(Channel[i])
bool_Channel = Channel.astype(numpy.bool_)

needs = numpy.sum(bool_Channel, axis=0)
print(needs.max())
import math

x = int(input())
y = double(input())

z = math.floor(x * y)
print(z)


### FIXED CODE ###

import math
from decimal import *

a,b = input().split()

a = int(a)
b = Decimal(b)

print(math.floor(a * b))
H, W = map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())
S=[list(map(str, list(input()))) for i in range(H)]

ah = Ch
aw = Cw
count = 0

while (ah != Dh) or (aw != Dw):
    h = Dh - ah
    w = Dw - aw
    if h > 0:
        if S[ah+1][aw] == '.':
            ah = ah + 1
    if h < 0:
        if S[ah-1][aw] == '.':
            ah = ah - 1
    if w > 0:
        if S[ah][aw+1] == '.':
            aw = aw + 1
    if w < 0:
        if S[ah][aw-1] == '.':
            aw = aw - 1
print(count)    

### FIXED CODE ###

N, X, T = map(int, input().split())
import math
a = math.ceil(N/X)
b = a*T
print(b)
n, a, b = map(int, raw_input().split())
if a < b:
  max = b
else:
  max = a

print(str(max*n))


### FIXED CODE ###

n, a, b = map(int, raw_input().split())
if a*n > b:
  min_value = b
else:
  min_value = a*n

print str(min_value)
import sys
sys.setrecursionlimit(10**6)

n = int(input())
info = []
for _ in range(n-1):
    c, s, f = map(int, input().split())
    info.append([c, s, f])
# print(info)

def func(i, low):
    if i == low:
        return info[i][1] + info[i][0]

    return func2(func(i-1, low), info[i][2], info[i][1]) + info[i][0]

def func2(n, f, s):
    if n <= s:
        return s
    if n % f == 0:
        return n
    else:
        return n//f * f + f

# print(func(n-2, 0))
for i in range(n):
    if i == n-1:
        print(0)
    print(func(n-2, i))

### FIXED CODE ###

n = int(input())
C = []
S = []
F = []
for _ in range(n-1):
    c, s, f = map(int, input().split())
    C.append(c)
    S.append(s)
    F.append(f)

def f(n, s, f):
    if n <= s:
        return s
    if n % f == 0:
        return n
    else:
        return n // f * f + f

for i in range(n-1):
    now = S[i] + C[i]
    for j in range(i+1, n-1):
        now = f(now, S[j], F[j]) + C[j]
    print(now)
print(0)
N = int(input())
data = [list(map(int,input().split())) for i in range(N)]

A = []

for i in range(N):
    A.append((data[i][1],data[i][0]))

A = sorted(A)

a = 0  #i番目にやった仕事の終了時間
for i in range(N):
    a += A[i][1]
    if a > A[i][0]:
        print('No')
        break
    else:
        continue
else:
    print('Yes')

### FIXED CODE ###

S = list(input())

for i in range(len(S)-1):
  if S[i] == S[i+1]:
    print('Bad')
    break
else:
  print('Good')
import sys
from collections import deque
sys.setrecursionlimit(10000000)
readline = sys.stdin.buffer.readline
n = int(readline())

g = [[] for _ in range(n+1)] #隣接リスト
for i in range(n-1):
    a,b = map(int,readline().split())
    g[a].append(b)
    g[b].append(a)

colors = [0] * (n+1)
 
colors[1] = 1
 
todo = []
for to in g[1]:
    todo.append([to, -1])
 
while todo:
    node, color = todo.pop()
 
    if colors[node] != 0:
        continue
 
    colors[node] = color
    new_color = -color
    for to in g[node]:
        if colors[to] != 0:
            continue
        todo.append([to, new_color])
ans = [0]*(n+1)
t0 = deque([])
t1 = deque([])
t2 = deque([])
for i in range(1,n+1):
    if i%3==1:
        t1.append(i)
    elif i%3==2:
        t2.append(i)
    else:
        t0.append(i)
black = 0
for i in colors[1:]:
    if i == 1:
        black += 1

if black <= n//3:
    for i in range(1,n+1):
        if colors[i] == 1:
            ans[i] = t0.pop()
        else:
            if t1:
                ans[i] = t1.pop()
            elif t2:
                ans[i] = t2.pop()
            else:
                ans[i] = t0.pop()
else:
    for i in range(1,n+1):
        if colors[i] == 1:
            if t1:
                ans[i] = t1.pop()
            else:
                ans[i] = t0.pop()
        else:
            if t2:
                ans[i] = t2.pop()
            else:
                ans[i] = t0.pop()
print(*ans[1:])

### FIXED CODE ###

import sys
from collections import deque
sys.setrecursionlimit(1000000)
readline = sys.stdin.buffer.readline
n = int(readline())

g = [[] for _ in range(n+1)] #隣接リスト
for i in range(n-1):
    a,b = map(int,readline().split())
    g[a].append(b)
    g[b].append(a)

colors = [0] * (n+1)
 
colors[1] = 1
 
todo = []
for to in g[1]:
    todo.append([to, -1])
 
while todo:
    node, color = todo.pop()
 
    if colors[node] != 0:
        continue
 
    colors[node] = color
    new_color = -color
    for to in g[node]:
        if colors[to] != 0:
            continue
        todo.append([to, new_color])
ans = [0]*(n+1)
t0 = deque([])
t1 = deque([])
t2 = deque([])
for i in range(1,n+1):
    if i%3==1:
        t1.append(i)
    elif i%3==2:
        t2.append(i)
    else:
        t0.append(i)
black = 0
for i in colors[1:]:
    if i == 1:
        black += 1

if black <= n//3:
    for i in range(1,n+1):
        if colors[i] == 1:
            ans[i] = t0.pop()
        else:
            if t1:
                ans[i] = t1.pop()
            elif t2:
                ans[i] = t2.pop()
            else:
                ans[i] = t0.pop()
elif black >= n-n//3:
    for i in range(1,n+1):
        if colors[i] == -1:
            ans[i] = t0.pop()
        else:
            if t1:
                ans[i] = t1.pop()
            elif t2:
                ans[i] = t2.pop()
            else:
                ans[i] = t0.pop()
else:
    for i in range(1,n+1):
        if colors[i] == 1:
            if t1:
                ans[i] = t1.pop()
            else:
                ans[i] = t0.pop()
        else:
            if t2:
                ans[i] = t2.pop()
            else:
                ans[i] = t0.pop()
print(*ans[1:])
N = int(input())
a = list(input().split())

s = [a.index(i)+1 for str(i) in range(1, N+1)]

result = " ".join(s)
print(result)


### FIXED CODE ###


N = int(input())
a = list(map(int, input().split()))
s = [-1]
s.extend(0 for _ in range(N))

for i, item in enumerate(a):
    s[item] = i+1

result = " ".join(map(str, s[1:]))
print(result)
A, B = [int(x) for x in innput().split()]
print(max(0, A - B*2))

### FIXED CODE ###

A, B = [int(x) for x in input().split()]
print(max(0, A - B*2))
data = int(input())
list = data.split(" ")

list.sort()

print("{a} {b} {c}").format(a=list[0], b=list[1], c=list[2])

### FIXED CODE ###

num = list(map(int, input().split()))
num.sort()
print(num[0], num[1], num[2])
sys.setrecursionlimit(100002)

L = input()
MOD = 10**9+7

num_ab = [1]
for i in range(1, len(L)+1):
    num_ab.append((num_ab[-1] * 3) % MOD)

def calc(L, m):
    m %= MOD
    if len(L) == 1:
        return (m * num_ab[int(L)]) % MOD
    elif '0' not in L:
        return (m * num_ab[len(L)]) % MOD
    elif '1' not in L[1:]:
        return ((m * num_ab[len(L) - 1]) % MOD + (2 * m) % MOD) % MOD
    else:
        return ((m * num_ab[len(L) - 1]) % MOD + calc(L[L[1:].index('1') + 1:], 2*m)) % MOD

print(calc(L,1))

### FIXED CODE ###

L = input()
MOD = 10**9+7

num_ab = [1]
for i in range(1, len(L)+1):
    num_ab.append((num_ab[-1] * 3) % MOD)

ans, m = 0, 1
while True:
    if '0' not in L:
        ans = (ans + (m * num_ab[len(L)]) % MOD) % MOD
        print(ans)
        exit()
    elif '1' not in L[1:]:
        ans = (ans + ((m * num_ab[len(L) - 1]) % MOD + (2 * m) % MOD) % MOD) % MOD
        print(ans)
        exit()
    else:
        ans = (ans + (m * num_ab[len(L) - 1]) % MOD) % MOD
        L = L[L[1:].index('1') + 1:]
        m = (2 * m) % MOD
import sys
sys.setrecursionlimit(100000000)

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

A = [0]*M

for i in range(M):
    A[i] = int(input())

A.append(N+1)

# DP version
DP = [0]*(N+1)
DP[0] = 1
# １段の階段を登るやり方の数
DP[1] = 1
# 2段の階段を登るやり方の数
DP[2] = 2

for i in range(3,N):
    DP[i] = DP[i-1] + DP[i-2]

def step_comb(L):
    if DP[L]>0:
        return DP[L]
    DP[L] = step_comb(L-1) + step_comb(L-2)
    return DP[L]
    
total_comb = 1
NOW = 0
for a in A:
    if NOW == a:
        print(0)
        sys.exit()
    L = a-1-NOW
    total_comb *= step_comb(L)
    NOW = a + 1
    
print(total_comb % 1000000007 )


### FIXED CODE ###

import sys
sys.setrecursionlimit(100000000)

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

if M == 0:
    A = []
else:
    A = [0]*M
    for i in range(M):
        A[i] = int(input())

A.append(N+1)

# DP version
DP = [0]*(N+1)
DP[0] = 1
# １段の階段を登るやり方の数
DP[1] = 1
# 2段の階段を登るやり方の数
#DP[2] = 2

for i in range(2,N+1):
    DP[i] = DP[i-1] + DP[i-2]

def step_comb(L):
    if DP[L]>0:
        return DP[L]
    DP[L] = step_comb(L-1) + step_comb(L-2)
    return DP[L]
    
total_comb = 1
NOW = 0
for a in A:
    if NOW == a:
        print(0)
        sys.exit()
    L = a-1-NOW
    total_comb *= step_comb(L)
    NOW = a + 1
    if NOW == N:
        break
    
print(total_comb % 1000000007 )
print(sum([1 if x=="+" else 01 for x in input()]))


### FIXED CODE ###

S=[1 if x=="+" else -1 for x in input()]

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

a_p =[]
a_m =[]
for i in a:
    if i >= 0:
        a_p.append(i)
    else :
        a_m.append(i)

a_p.sort()
a_m.sort(reverse=True)


a_select =[]

if len(a_p) == 0:
    for i in range(k):
        a_select.append(a_m[i])


while len(a_select) < k:
    if len(a_select) == k - 1:
        a_select.append(a_p[-1])
        break
    if len(a_p) == 1 and (k-len(a_select))%2 == 1:
        a_select.append(a_p[-1])
    elif len(a_p) == 0:
        a_select.append(a_m.pop(-1))
    elif len(a_m) <= 1:
        a_select.append(a_p.pop(-1))
    elif a_p[-1]*a_p[-2] > a_m[-1]*a_m[-2] :
        a_select.append(a_p.pop(-1))
    else:
        a_select.append(a_m.pop(-1))
        a_select.append(a_m.pop(-1))

#print(a_select)
ans = 1
for i in a_select:
    ans = ans*i % (10**9 + 7)

print(ans)


### FIXED CODE ###

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

a_p =[]
a_m =[]
for i in a:
    if i >= 0:
        a_p.append(i)
    else :
        a_m.append(i)

a_p.sort()
a_m.sort(reverse=True)


a_select =[]

if n == k:
    a_select = a
elif len(a_p) == 0 and k%2 == 1:
    for i in range(k):
        a_select.append(a_m[i])


while len(a_select) < k:
    if len(a_select) == k - 1:
        a_select.append(a_p[-1])
        break
    if len(a_p) == 1 and (k-len(a_select))%2 == 1:
        a_select.append(a_p.pop(-1))
    elif len(a_p) == 1 and (k-len(a_select))%2 == 0:
        a_select.append(a_m.pop(-1))
        a_select.append(a_m.pop(-1))
    elif len(a_p) == 0:
        a_select.append(a_m.pop(-1))
        a_select.append(a_m.pop(-1))
    elif len(a_m) <= 1:
        a_select.append(a_p.pop(-1))
    elif a_p[-1]*a_p[-2] > a_m[-1]*a_m[-2] :
        a_select.append(a_p.pop(-1))
    else:
        a_select.append(a_m.pop(-1))
        a_select.append(a_m.pop(-1))

#print(a_select)
ans = 1
for i in a_select:
    ans = ans*i % (10**9 + 7)

print(ans)
import math
float R
R=float(input())
print(2*math.pi*R)

### FIXED CODE ###

import math
R=float(input())
print(2*R*math.pi)
n=int(input()) 
l=list(map(int,input().split())) 
dic_l={} 
lst_1=[] 
for i in range(n): 
	dic_l[l[i]]=i 
	for j in range(1,n+1):
		lst_1.append(str(dic_l[j]+1)) 
print(" ".join(lst_1))

### FIXED CODE ###

n=int(input()) 
l=list(map(int,input().split())) 
dic_l={} 
lst_1=[] 
for i in range(n): 
	dic_l[l[i]]=i 
for j in range(1,n+1):
	lst_1.append(str(dic_l[j]+1)) 
print(" ".join(lst_1))
a=[]
for i in range(4):
    b=int(input())
    a.append(b)
c=int(input())
if max(a) - min(a) =< c:
    print('Yay!')
else:
    print(':(')

### FIXED CODE ###

a=[]
for i in range(5):
    b=int(input())
    a.append(b)
c=int(input())
if a[4] - a[0] <= c:
    print('Yay!')
else:
    print(':(')
n = int(input())
s, t = map(int, input().split())

result = ''
for idx in range(n):
  result += s[idx] + t[idx]

  print(result)

### FIXED CODE ###

n = int(input())
s, t = input().split()

result = ''
for idx in range(n):
  result += s[idx] + t[idx]

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

print(int(k * x + y * (n - k)))


### FIXED CODE ###

# x, y = [int(input()) for i in range(2)]
n, k, x, y = [int(input()) for i in range(4)]

if n > k:
    print(int(k * x + y * (n - k)))
else:
    print(int(n * x))
def calc(x, y):
    x2 = x
    y2 = y - 1
    x4 = x - 1
    y4 = y
    x5 = x + 1
    y5 = y
    x7 = x
    y7 = y + 1
    return x2, y2, x4, y4, x5, y5, x7, y7

h, w = map(int, input().split())
s = []
for _ in range(h):
    s.append(list(input()))

for i in range(h * w):
    x = i // h
    y = i % h
    c = 0
    if s[y][x] == "#":
        x2, y2, x4, y4, x5, y5, x7, y7 = calc(x, y)
        aaa = [[x2, y2], [x4, y4], [x5, y5], [x7, y7]]
        for (xx, yy) in aaa:
            if ((xx >= 0) & (xx < h) & (yy >= 0) & (yy < w)):
                if s[yy][xx] == "#":
                    c += 1
        if c == 0:
            ans = "No"
            break
        else:
            ans = "Yes"
print(ans)

### FIXED CODE ###

def calc(x, y):
    x2 = x
    y2 = y - 1
    x4 = x - 1
    y4 = y
    x5 = x + 1
    y5 = y
    x7 = x
    y7 = y + 1
    return x2, y2, x4, y4, x5, y5, x7, y7

h, w = map(int, input().split())
s = []
for _ in range(h):
    s.append(list(input()))
ans = "Yes"
for i in range(h * w):
    x = i // h
    y = i % h
    c = 0
    if s[y][x] == "#":
        x2, y2, x4, y4, x5, y5, x7, y7 = calc(x, y)
        aaa = [[x2, y2], [x4, y4], [x5, y5], [x7, y7]]
        for (xx, yy) in aaa:
            if ((xx >= 0) & (xx < w) & (yy >= 0) & (yy < h)):
                if s[yy][xx] == "#":
                    c += 1
        if c == 0:
            ans = "No"
            break
print(ans)
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, M = LI()
    AB = [LI() for _ in range(N)]
    A_max = max([i[0] for i in AB])

    W = [[] for _ in range(A_max + 1)]
    for a, b in AB:
        W[M-a].append(b)
    # print(W)

    # 選択肢の少ない後ろの日付から決めていく
    ans = 0
    hq = []
    for i in range(M - 1, -1, -1):
        for j in W[i]:
            heapq.heappush(hq, -j)
        if hq:
            ans -= heapq.heappop(hq)

    print(ans)

if __name__ == '__main__':
    resolve()


### FIXED CODE ###

import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, M = LI()
    AB = [LI() for _ in range(N)]

    W = [[] for _ in range(M + 1)]
    for a, b in AB:
        if 0 <= M - a:
            W[M-a].append(b)
    # print(W)

    # 選択肢の少ない後ろの日付から決めていく
    ans = 0
    hq = []
    for i in reversed(W):
        for j in i:
            heapq.heappush(hq, -j)
        if hq:
            ans -= heapq.heappop(hq)

    print(ans)

if __name__ == '__main__':
    resolve()
import numpy as np
N,M,C = (int(j) for j in input().split())
B = [int(j) for j in input().split()]
list = [[0]* M]*N
for j in range(0,N):
        list[j] = [int(k) for k in input().split()]
count = 0
for j in range(0,N):
    if np.sum(np.array(list[j]) * np.array(B)) + C > 0:
        count = count + 1
print(count)

### FIXED CODE ###

H,W = (int(j) for j in input().split())
h,w = (int(j) for j in input().split())
print(H*W-(h*W + H*w - h*w))
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
d=dict(Counter(a))
ans=sum(a)
q=int(input())
for _ in range(q):
    b,c=map(int,input().split())
    ans+=c*d[b]-b*d[b]
    print(ans)
    if c in d.keys(): d[c]+=d[b]
    else: d[c]=d[b]
    d[b]=0

### FIXED CODE ###

from collections import Counter
n=int(input())
a=list(map(int,input().split()))
d=dict(Counter(a))
ans=sum(a)
q=int(input())
for _ in range(q):
    b,c=map(int,input().split())
    if b not in d.keys():
        print(ans)
        continue
    ans+=(c*d[b]-b*d[b])
    print(ans)
    if c in d.keys(): d[c]+=d[b]
    else: d[c]=d[b]
    d[b]=0
re = 0
    if A % 3 == 0:    
        re = 1
    if B % 3 == 0:
        re = 1
    if (A+B) % 3 == 0:
        re = 1
        
    if re ==1:
        return "Possible"
    else:
        return "Impossible"

### FIXED CODE ###

Imp = list(map(int, input().split()))
A = Imp[0]
B = Imp[1]
re = 0
if A % 3 == 0:    
    re = 1
if B % 3 == 0:
    re = 1
if (A+B) % 3 == 0:
        re = 1
        
if re ==1:
    print("Possible")
else:
    print("Impossible")
# N=1079
N=int(input())

a=str(N*100/108)
b=str((N+1)*100/108)

print(a,b)

if a+1 <=b:
    print(round(a+0.5))
else:
    print(":(")


### FIXED CODE ###

# N=1079
N=int(input())

a=int(N*100/110)-1

flg=False

for i in range (N-a+1):
    if ((a+i)*1.08)//1==N:
        print(a+i)
        exit()
    else:
        pass
print(':(')
from collections import Counter
h, w, num = map(int, input().split())
lis = []
for i in range(num):
    k, j = map(lambda x: int(x) - 1,input().split())
    for a in range(3):
        for b in range(3):
            cou1 = k - a
            cou2 = j - b 
            if cou1 < 0 or cou1 > h - 3:
                continue
            if cou2 < 0 or cou2 > w - 3:
                continue
            lis.append((cou1, cou2))

lis = Counter(Counter(lis).values())

print((h - 2) * (w - 2) - sum(lis.values()))
for i in range(1, 10):print(lis[i])

### FIXED CODE ###

n = str(input())
ans = 0
if int(n) < 10:
  print(int(n))
  exit()
for i in range(2 ** (len(n) -1)):
  num = format(i,"b").zfill(len(n)-1)
  lis = ""
  for j in range(len(str(num))):
    if str(num[j]) == "1":
      lis += (str(n[j])+"+")
    else:
      lis += str(n[j])
  lis += n[-1]
  li = lis.split("+")
  for h in range(len(li)):
    li[h] = int(li[h])
  ans += sum(li)
print(ans)