Harryxun/stf_run huggingface dataset:
r1,c1,r2,c2 = map(int, input().split())

def nCr_mod_p(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

p = 10 ** 9 + 7
N = 2*10 ** 6 + 1  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p), 0! = 1! = 1
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p), 0! = 1! = 1
inv = [0, 1]  # inv[n] = n^(-1) mod p, 0! = 1　だけど便宜上inv[0]=0にしてる

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[-1]) % p)

sum22 = nCr_mod_p(r2+1+c2+1,r2+1,p) - 1
sum21 = nCr_mod_p(r2+1+c1,r2+1,p) - 1
sum12 = nCr_mod_p(r1+c2+1,c2+1,p) - 1
sum11 = nCr_mod_p(r1+c1,c1,p) - 1

ans = sum22 - sum21 - sum12 + sum11
ans %= p

print(ans)


### FIXED CODE ###

r1,c1,r2,c2 = map(int, input().split())

def nCr_mod_p(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

p = 10 ** 9 + 7
N = 2*10 ** 6 + 10  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p), 0! = 1! = 1
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p), 0! = 1! = 1
inv = [0, 1]  # inv[n] = n^(-1) mod p, 0! = 1　だけど便宜上inv[0]=0にしてる

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[-1]) % p)

sum22 = nCr_mod_p(r2+1+c2+1,r2+1,p) - 1
sum21 = nCr_mod_p(r2+1+c1,r2+1,p) - 1
sum12 = nCr_mod_p(r1+c2+1,c2+1,p) - 1
sum11 = nCr_mod_p(r1+c1,c1,p) - 1

ans = sum22 - sum21 - sum12 + sum11
ans %= p

print(ans)
from itertools import groupby


s=input()
x,y=map(int,input().split())
data=[s[i] for i in range(0,len(s))]
data=groupby(data)
LR=[]
UD=[]
point='LR'
flag=0
for key,group in data:
    g=len(list(group))
    if key=='F':
        if flag==0:
            x-=g
            flag=1
        else:
            if point=='LR':
                LR.append(g)
            else:
                UD.append(g)
    else:
        if g%2==1:
            if point=='LR':
                point='UD'
            else:
                point='LR'
        flag=1

checkx=2**8000
for i in range(0,len(LR)):
    checkx=(checkx<<LR[i])|(checkx>>LR[i])

checky=2**8000
for i in range(0,len(UD)):
    checky=(checky<<UD[i])|(checky>>UD[i])

if checkx>>(x+8000) &1==1 and checky>>(y+8000) &1==1:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

from itertools import groupby


s=input()
x,y=map(int,input().split())
data=[s[i] for i in range(0,len(s))]
data=groupby(data)
LR=[]
UD=[]
point='LR'
flag=0
checkx=2**8000
for key,group in data:
    g=len(list(group))
    if key=='F':
        if flag==0:
            checkx=checkx<<g
            flag=1
        else:
            if point=='LR':
                LR.append(g)
            else:
                UD.append(g)
    else:
        if g%2==1:
            if point=='LR':
                point='UD'
            else:
                point='LR'
        flag=1


for i in range(0,len(LR)):
    checkx=(checkx<<LR[i])|(checkx>>LR[i])

checky=2**8000
for i in range(0,len(UD)):
    checky=(checky<<UD[i])|(checky>>UD[i])


if checkx>>(x+8000) &1==1 and checky>>(y+8000) &1==1:
    print('Yes')
else:
    print('No')
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
mod=10**9+7
ans=0
MOD=10**9+7

from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

a = cmb(n, r)
for i in range(n-k+1):
    ans-=a[i]*cmb(n-i-1,k-1)%mod
    ans%=mod
a=a[::-1]
for i in range(n-k+1):
    ans+=a[i]*cmb(n-i-1,k-1)%mod
    ans%=mod

print(ans%mod)

### FIXED CODE ###

n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
mod=10**9+7
ans=0
MOD=10**9+7

factorial = [1]
inverse = [1]
for i in range(1, n+2):
    factorial.append(factorial[-1] * i % MOD)
    inverse.append(pow(factorial[-1], MOD - 2, MOD))
 
 
# 組み合わせ計算
def nCr(n, r):
    if n < r or r < 0:
        return 0
    elif r == 0:
        return 1
    return factorial[n] * inverse[r] * inverse[n - r] % MOD
for i in range(n-k+1):
    ans-=a[i]*nCr(n-i-1,k-1)%mod
    ans%=mod
a=a[::-1]
for i in range(n-k+1):
    ans+=a[i]*nCr(n-i-1,k-1)%mod
    ans%=mod

print(ans%mod)
import sys
count = 1
while True:
  x,y = sys.stdin.readline().split.strip()
  if x == 0 and y == 0:
    break
    if x < y:
      result = (x,y)
    else:
      result = (y,x)
  print(result)
  count = count + 1

### FIXED CODE ###

import sys
while True:
    a,b=map(int,sys.stdin.readline().split())
    if a==0 and b==0:
        break
    if a<b:print(a,b)
    else:print(b,a)
def read_int(): return int(input())
N = read_int()
def read_str(): return input().strip()
S = list(read_str())
 
__DEBUG__ = False
 
def solution():
    count = 0    
    for i in range(N-2):
        if __DEBUG__: print(f"checking {S[i]} at index: {i}")
        if S[i] == 'A':
            if S[i+1] == 'B' and S[i+2] == 'C':
                count += 1
                # continue
    return count
 
    
if __name__ == '__main__':
  	import sys, threading
  	sys.setrecursionlimit(200000)
    threading.stack_size(10240000)
    print(solution())
    


### FIXED CODE ###

N = int(input())
S = str(input())
 


count = 0    
for i in range(N-2):
  if S[i] == 'A':
    if S[i+1] == 'B' and S[i+2] == 'C':
      count += 1
    
print(count)
a, b, k = map(int, input().split())
while a != b:
    if a > b:
        a = a - b
    else:
        b = b - a
ans = []
for i in range(1, a):
    if a%i == 0:
        ans.append(i)
        ans.sort(reverse=True)
print(ans[k-1])

### FIXED CODE ###

a, b, k = map(int, input().split())
while a != b:
    if a > b:
        a = a - b
    else:
        b = b - a
ans = []
for i in range(1, a+1):
    if a%i == 0:
        ans.append(i)
        ans.sort(reverse=True)
print(ans[k-1])
import numpy as np
import itertools
n,m,d = map(int, input().split())

n = [x for x in range(1, n+1)]
x = np.array(list(itertools.product(n, repeat=m)))
print(np.sum((x[:,1:] - x[:,:-1]) == d) / x.shape[0])


### FIXED CODE ###

a, b = map(int, input().split())
print('+' if a + b ==15 else '*' if a * b == 15 else 'x')
a = int(input())
b = int(input())
c = a*b
d = c+1
print(c,d)

### FIXED CODE ###

a,b = [int(x) for x in input().split()]
print(a*b,(a+b)*2)
n=int(input())
i=1
while i**2<n:
    ans=i**2
    i+=1
print(ans)

### FIXED CODE ###

n=int(input())
i=1
while i**2<=n:
    ans=i**2
    i+=1
print(ans)
N, A, B = map(int, input().split())
if (A - B) % 2 == 0 :
  print (abs(A - B) // 2)
else:
  print(min(max(A, B) - 1, N - min(A, B))

### FIXED CODE ###

N, A, B = map(int, input().split())
if abs(A - B) % 2 == 0:
  print (abs(A - B) // 2)
else:
  hajiniyoru = min(min(A - 1, B - 1), min(N - A, N - B))
  print(hajiniyoru  + 1 + (abs(A - B) - 1) // 2)
n = int(input())
l = list(map(int,input().split()))
ans = 0
for i in range(n):
    ans += ((l[i]*sum(l[i+1:n]))%1000000007
print(ans%1000000007)

### FIXED CODE ###

n = int(input())
l = list(map(int,input().split()))
ans = 0
sum_n = [0]*n
sum_n[0] = l[0]
sumall = sum(l)
for i in range(1,n):
    sum_n[i] = sum_n[i-1] + l[i]
for i in range(n):
    ans += ((l[i]*(sumall-sum_n[i]))%1000000007)
print(ans%1000000007)
a,b,c,d = map(int,input().split())
answer =0
if b < 0:
	if c < 0:
		answer = a*c
	if c>=0:
		answer = a * c
if b>=0:
	if a <0:
		answer = max(a*c ,b * d,0)
	if a >= 0:
		if d< 0:
			if a == 0:
				answer = 0
			elif:
				answer = a*d
		if d>=0:
			answer = b*d
print(answer)


### FIXED CODE ###

a,b,c,d = map(int,input().split())
answer =0
if b < 0:
	if c < 0:
		answer = max(a*c,b*d)
	if c>=0:
		answer = max(a*c,b*d,b*c)
if b>=0:
	if a <0:
		answer = max(a*c ,b * d,0)
	if a >= 0:
		if d< 0:
			if a == 0:
				answer = 0
			else:
				answer = a*d
		if d>=0:
			answer = b*d
print(answer)
n=int(input())
a=int(input())
b=int(input())
if n==1:
  print("Hello World")
else:
  print(a+b)

### FIXED CODE ###

n=int(input())
if n==1:
  print("Hello World")
else:
  print(int(input())+int(input()))
num = input().split()

if (num[0] == num[1]):
    print "a == b"
if (num[0] <  num[1]):
    print "a < b"
if (num[0] >  num[1]):
    print "a > b"

### FIXED CODE ###

a, b = map(int, raw_input().split())

if (a == b):
    print "a == b"
if (a >  b):
    print "a > b"
if (a <  b):
    print "a < b"
a = list(map(int, input().split()))
x=a[0]*100+a[1]*10+a[2]
if x%4=0:
	print("YES")
else:
	print("NO")

### FIXED CODE ###

a = list(map(int, input().split()))
x=a[0]*100+a[1]*10+a[2]
if x%4==0:
	print("YES")
else:
	print("NO")
N, Y = map(int, input().split())
# x:10000円, y;5000円, z:1000円
for x in range(N+1):
    for y in range(N+1):
        z = N - (x + y)
        if (z >= 0) & (10000x + 5000y + 1000*z == Y):
            print(x, y, z)
            exit(0)
print(-1, -1, -1)

### FIXED CODE ###

n, y = map(int, input().split())
for i in range(n + 1):
    for j in range(n - i + 1):
        if i * 10000 + j * 5000 + (n - i - j) * 1000 == y:
            print(i, j, n - i - j)
            exit()
print("-1 -1 -1")
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)
"""
#memo化再帰
memo = [-1]*(110000)
def rec(n):
    if n==0:
        return 0
    if memo[n] != -1:
        return memo[n]
    res = n
    pow6,pow9 = 1,1
    while pow6 <=n:
        res = min(res,rec(n-pow6)+1)
        pow6 *= 6
    while pow9 <= n:
        res = min(res,rec(n-pow9)+1)
        pow9 *= 9
    memo[n] = res
    return memo[n]
N = int(input())
print(rec(N))
"""
"""
#もらうDP
N = int(input())
dp=[inf]*110000
dp[0] = 0
for n in range(1,N+1):
    pow6,pow9 = 1,1
    while pow6<=n:
        dp[n] = min(dp[n],dp[n-pow6]+1)
        pow6 *= 6
    while pow9 <= n:
        dp[n] = min(dp[n],dp[n-pow9]+1)
        pow9 *= 9
print(dp[N])
"""
#配るDP
N = int(input())
dp=[inf]*(110000)
dp[0]=0
for n in range(N):
    pow6,pow9 = 1,1
    while pow6<=N:
        dp[n+pow6] = min(dp[n+pow6],dp[n]+1)
        pow6 *= 6
    while pow9 <=N:
        dp[n+pow9] = min(dp[n+pow9],dp[n]+1)
        pow9 *= 9
print(dp[N])


### FIXED CODE ###

N = int(input())
l = [1,6,9,36,81,216,729,1296,6561,7776,46656,59049]
dp = [N]*(N+1)
dp[0]=0

for i in range(1,N+1):
    for j in l:
        if i-j >= 0:
            dp[i] = min(dp[i],dp[i-j]+1)
print(dp[N])
#input
r_1, c_1, r_2, c_2 = map(int, input().split())

#output
mod = 10**9 + 7

n_ = 10**6 + 3
fun = [1]*(n_+1)
for i in range(1,n_+1):
    fun[i] = fun[i-1]*i%mod
rev = [1]*(n_+1)
rev[n_] = pow(fun[n_],mod-2,mod)
for i in range(n_-1,0,-1):
    rev[i] = rev[i+1]*(i+1)%mod
def cmb(n,r):
    if n <= 0 or r < 0 or r > n: return 0
    return fun[n]*rev[r]%mod*rev[n-r]%mod

answer = 0
for i in range(r_1, r_2+1):
    for j in range(c_1, c_2+1):
        answer += cmb(i+j, j) % mod
print(answer % mod)

### FIXED CODE ###

#input
r_1, c_1, r_2, c_2 = map(int, input().split())

#output
mod = 10**9 + 7

n_ = 2*10**6 + 1
fun = [1]*(n_+1)
for i in range(1,n_+1):
    fun[i] = fun[i-1]*i%mod
rev = [1]*(n_+1)
rev[n_] = pow(fun[n_],mod-2,mod)
for i in range(n_-1,0,-1):
    rev[i] = rev[i+1]*(i+1)%mod
def cmb(n,r):
    if n <= 0 or r < 0 or r > n: return 0
    return fun[n]*rev[r]%mod*rev[n-r]%mod

answer = 0
for j in range(c_1, c_2+1):
    answer += cmb(r_2+j+1, j+1) % mod - cmb(r_1+j, j+1) % mod

print(answer % mod)
a,b,c,d=map(int,input().split())
from fractions import gcd
lcm=(c*d)//gcd(c,d)
n=(b//c)-((a-1)//c)
n+=(b//d)-((a-1)//d)
print(b-a+1-n+((b//lcm)-((a-1)//lcm)))


### FIXED CODE ###

pre = 0
for i in list(input()):
    if i == pre:
        print("Bad")
        exit()
    pre = i
print("Good")
A, B, C, D = map(int,input().split())
hpa = A
hhb = C
while(1):
    hpb -= B
    if(hpb <= 0):
        print('Yes')
        break
    hpa -= D
    if(hpa <= 0):
        print('No')
        break  


### FIXED CODE ###

import math
A, B, C, D = map(int,input().split())
hpa = math.ceil(A / D)
hpb = math.ceil(C / B)
if (hpa >= hpb):
    print('Yes')
else:
    print('No')
while 1:
 H, W = map(int,raw_input().split())
 if H + W == 0:
 break
 for h in range(H):
  if h % 2 == 0:
   if W % 2 == 0:
    print ('#.'*(W//2))
   else:
    print ('#.'*(W//2)+'#')
  else:
   if W % 2 == 0:
    print ('.#'*(W//2))
   else:
    print ('.#'*(W//2)+'.')
 print ''

### FIXED CODE ###

while 1:
 H, W = map(int,raw_input().split())
 if H + W == 0:break
 for h in range(H):
  if h % 2 == 0:
   if W % 2 == 0:
    print ('#.'*(W//2))
   else:
    print ('#.'*(W//2)+'#')
  else:
   if W % 2 == 0:
    print ('.#'*(W//2))
   else:
    print ('.#'*(W//2)+'.')
 print ''
yy,mm,dd =map(int,input().split('/'))

if yy>2019:
  print('TBD')
else:
  if mm>4:
    print('TBD')
  else:
    if mm==1 or m==3:
      if dd>31:
        print('TBD')
      else:
        print('Heisei')
    if mm==2:
      if d>29:
        print('TBD')
      else:
        print('Heisei')
    if mm==4:
      if d>30:
        print('TBD')
      else:
        print('Heisei')



  if mm<=4:
    if dd<=30:
      print('Heisei')
else:
  print('TBD')



### FIXED CODE ###

yy,mm,dd =map(int,input().split('/'))

if yy>2019:
  print('TBD')
else:
  if mm>4:
    print('TBD')
  else:
    if mm==1 or mm==3:
      if dd>31:
        print('TBD')
      else:
        print('Heisei')
    if mm==2:
      if dd>29:
        print('TBD')
      else:
        print('Heisei')
    if mm==4:
      if dd>30:
        print('TBD')
      else:
        print('Heisei')
K = int(input())
S = input()

if len(S) <= K:
    print(S)
else:
    print(S[0:K]　+ '...')

### FIXED CODE ###

N = int(input())
N = N % 10
if N in [2, 4, 5, 7, 9]:
    print('hon')

elif N in [0, 1, 6, 8]:
    print('pon')

else:
    print('bon')
import numpy as np

n = int(input())
a = [int(x) for x in input().split()]

cnt = 0
while sum(a%2) == 0:
    cnt += 1
    a = a//2
print(cnt)

### FIXED CODE ###

import numpy as np

n = int(input())
a = np.array([int(x) for x in input().split()])

cnt = 0
while sum(a%2) == 0:
    cnt += 1
    a = a//2
print(cnt)
n, d = map(int, input().split())
x = []
y = []
cnt = 0

for i in range(n):
  x.append(int(input()))
  y.append(int(input()))

for j in range(n):
  l = (x[j] ** 2 + y[j] ** 2) ** (1 / 2)
  if l <= d:
    cnt += 1
  else:
    continue

print(cnt)

### FIXED CODE ###

n, d = map(int, input().split())
lists = []
cnt = 0

for i in range(n):
  x, y = map(int, input().split())
  lists.append([x, y])
  

for j in range(n):
  l = (lists[j][0] ** 2 + lists[j][1] ** 2) ** (1 / 2)
  if l <= d:
    cnt += 1
  else:
    continue

print(cnt)
suf = ["dream", "dreamer", "erase", "eraser"]

s = input()
i = 0
while i < len(s):
  nx = s[i:i+5]
  if nx != suf[0] and nx != suf[2]:
    print("NO")
    exit(0)
  i += 5
  if s[i] == 'r':
  	i += 1
print("YES")

### FIXED CODE ###

suf = ["dream", "dreamer", "erase", "eraser"]

s = input()
dp = [0] * (len(s) + 1)
dp[0] = 1
for i in range(len(s)):
    if not dp[i]:
        continue
    for it in suf:
        if s[i:i+len(it)] == it:
            dp[i + len(it)] = 1
print("YES") if dp[len(s)] else print("NO")
#
N=int(input())
S=[]
for i in range(N):
    S.append(input())
ans=[]

#
while len(S):
    if len(S)==1:
        x = [S.pop(-1), 1]
        ans.append(x)
        break
    x = [S.pop(-1), 1]
    for i in S[:]:
        if x[0] == i:
            S.remove(i)
            x[1]+=1
    ans.append(x)
ans.sort()
ans.sort(key=lambda x:x[1],reverse=True)

for i in range(len(ans)):
    t=ans[0][1]
    if ans[i][1]==t:
        print(ans[i][0])


### FIXED CODE ###

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

if (A is B and B is C) or (A is not B and B is not C and C is not A):
    print("No")
else:
    print("Yes")
a,b = map(int, input().split())
x = a + b
print(math.floor(x))

### FIXED CODE ###

a,b = map(int, input().split())
x = a + b
if x%2 == 0:
  print(x//2)
else:
  print(x//2 + 1)
import math

A, B, C, D = map(int, input().split())
CD = math.ceil(C * D / math.gcd(C, D))
AC = math.ceil(A / C)
BC = math.ceil(B / C)
C = BC - AC + 1
AD = math.ceil(A / D)
BD = math.ceil(B / D)
D = BD - AD + 1
ACD = math.ceil(A / CD)
BCD = math.ceil(B / CD)
CD = BCD - ACD + 1
print((B-A+1) - (C + D - CD))

### FIXED CODE ###

import sys
input = sys.stdin.readline
from fractions import gcd
def lcm(a, b):
    return a*b // gcd(a, b)
def group(s, t, u):
    su = (s - 1) // u
    tu = t // u
    return  tu - su

A, B, C, D = map(int, input().split())
ABC = group(A, B, C)
ABD = group(A, B, D)
ABCD = group(A, B, lcm(C,D))
U = B - A + 1
print(U-(ABC+ABD-ABCD))
a, b, c = input.split()

print(a[0] + b[1] + c[2])

### FIXED CODE ###

a = input()
b = input()
c = input()
print(a[0] + b[1] + c[2])
n = input()
 a = []
  for i in range(n):
    l.append(int(raw_input())
 
  Min = a[0]
  Max = -1*10**9
  for j in range(1,N):
   Max = max(Max,a[j]-Min)
   Min = min(Min,a[j])
  print Max

### FIXED CODE ###

n = int(raw_input())
a = []
a.append(int(raw_input()))
Min = a[0]
Max = -1*10**9
for j in range(1,n):
    a.append(int(raw_input()))
    Max = max(Max,a[j]-Min)
    Min = min(Min,a[j])
print Max
a,b = map (int, input().split)
if(a<b):
    print("a < b")
    else if(a>b):
        print("a > b")
        else if(a == b):
            print("a == b")


### FIXED CODE ###

a,b = map (int, input().split())
if a<b:
    print("a < b")
elif a>b:
    print("a > b")
else:
    print("a == b")
x = int(input())
y = int(input())
z = int(input())

a = z
b = y
c = x

print("%i %i %i" %(a,b,c))

### FIXED CODE ###

x,y,z = input().split()

a = z
b = x
c = y

print(str(a)+" "+str(b)+" "+str(c))
N,M,C = map(int,input().split())
B = list(map(int,input().split()))
K = []
S = 0
ans = 0
J = []
for i in range(N):
  K.append(list(map(int,input().split())))
for i in range(N):
  for j in range(M):
    S += K[i][j]*B[j]
  S = S + C
  J.append(S)
for i in range(N):
  if J[i] >0:
    ans += 1
  else:
    ans += 0
print(ans)

### FIXED CODE ###

L = [2,1]
for i in range(100):
  L.append(L[i+1]+L[i])
n = int(input())
print(L[n])
import sys;sys.setrecursionlimit(100000);n,k=map(int,input().split());x,t=10**9+7,[set()for _ in range(n)]
for i in range(n-1):;a,b=map(int,input().split());t[a-1].add(b);t[b-1].add(a)
c=k
def b(o):
  global c
  for i,j in enumerate(t[o-1]):c=(c*(k-2-i))%x;t[j-1].discard(o);b(j)
for i,j in enumerate(t[0]):c=(c*(k-1-i))%x;t[j-1].discard(1);b(j)
print(c)

### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)
n,k=map(int,input().split())
ans=k
t=[set()for i in range(n)]
dp=[k]+[0]*(n-1)
for i in range(n-1):
  a,b=map(int,input().split())
  t[a-1].add(b)
  t[b-1].add(a)
no=1
w=k
b=True
def a(noo):
  global ans
  w=k
  for i in t[noo-1]:
    t[i-1].discard(noo)
    if w==0:print(0);exit()
    dp[i-1]=w-2;ans=(ans*(w-2))%(10**9+7)
    w-=1
    a(i)
for i in t[no-1]:
  t[i-1].discard(no)
  w-=1
  dp[i-1]=w;ans=(ans*w)%(10**9+7)
  a(i)
print(ans)
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def SI(): return input().split()

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')

from math import ceil, floor, log2
from collections import deque
from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product
import heapq


def solve():
    n, m = MI()

    AB = []
    for i in range(n):
        a, b = MI()
        AB.append((a, b))

    AB = sorted(AB, key=lambda x: x[0])
    # print(AB)

    q = [AB[0][1]]
    pre = AB[0][0]
    memo = {}
    for i in range(1, n):
        a, b = AB[i]
        if a == pre:
            q.append(b)
        else:
            memo[pre] = deque(sorted(q))
            q = [b]
            pre = a
    memo[pre] = deque(sorted(q))

    # print(memo)

    ans = 0
    for i in range(1, m+1):
        q = memo.get(i, deque([]))

        # print(i, hp)
        if len(q) > 0:
            ans += q.pop()

        q.extend(memo.get(i + 1, []))

        memo[i+1] = deque(sorted(q)[-m-i:])
    print(ans)


if __name__ == '__main__':
    solve()


### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def SI(): return input().split()

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')

from math import ceil, floor, log2
from collections import deque
from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product
from heapq import heapify, heappush, heappop


def solve():
    n, m = MI()

    jobs = [[] for _ in range(m)]
    for i in range(n):
        a, b = MI()
        if m-a >= 0:
            jobs[m-a].append(b)

    # print(jobs)
    hp = []
    heapify(hp)
    ans = 0
    for i in range(m-1, -1, -1):
        js = jobs[i]
        for j in js:
            heappush(hp, -j)

        if len(hp) > 0:
            ans += -heappop(hp)
    print(ans)





if __name__ == '__main__':
    solve()
MOD = 10**9+7
n = int(input())
la = list(map(int,input().split()))
L = [-1]*(n+1)
l = 0
 
MAX = n
factorial = [1, 1]
inverse = [0, 1]
inverse_factorial = [1, 1]
for i in range(2,MAX+1):
  factorial.append( (factorial[-1]*i)%MOD )
  inverse.append( (-inverse[MOD%i]*(MOD//i))%MOD )
  inverse_factorial.append( (inverse_factorial[-1]*inverse[-1])%MOD )
 
def C_MOD(n, k):
  if k < 0 or k > n:
    return 0
  k = min(k,n-k)
  return factorial[n] * inverse_factorial[k] * inverse_factorial[n-k] % MOD
 
print(n)
#print((2*C_MOD(n-1,1)-C_MOD(n-1-l,1)+C_MOD(n-1,2)+1)%MOD)
for i in range(2,n+1):
  if n > l+1:
    print((2*C_MOD(n-1,i-1)-C_MOD(n-1-l,i-1)+C_MOD(n-1,i)+C_MOD(n-1,i-2))%MOD)
  else:
    print((2*C_MOD(n-1,i-1)+C_MOD(n-1,i)+C_MOD(n-1,i-2))%MOD)
print(1)

### FIXED CODE ###

# ringing
a = list(map(int, input().split()))
a = sorted(a)
print( a[0]+a[1] )
A,B,C,D=map(int,input().split())
for i in range(0,99):
    C=C-B
    if C<=0:
        print('Yes')
         break
    else:
        A=A-D
        if A<=0:
            print('No')
             break


### FIXED CODE ###

A,B,C,D=map(int,input().split())
for i in range(0,100):
    C=C-B
    if C<=0:
        print('Yes')
        break
    else:
        A=A-D
        if A<=0:
            print('No')
            break
N = int(input())
sum = 0
for i in range[1,N+1]:
  if len(i) % 2 == 1:
    sum += 1
print(sum)

### FIXED CODE ###

N = int(input())
sum = 0
for i in range(1,N+1):
  if len(str(i)) % 2 == 1:
    sum += 1
print(sum)
N = int(input())
A = int(input())
B = int(input())

if N == 1:
    print("Hello World")
else:
    print(A + B)

### FIXED CODE ###

N = int(input())

if N == 1:
    print("Hello World")
if N == 2:
    A = int(input())
    B = int(input())
    print(A + B)