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

# https://atcoder.jp/contests/abc120/tasks/abc120_d
from collections import Counter
n, m = map(int, input().split())

brides = []
for _ in range(m):
    a, b = map(int, input().split())
    brides.append((a, b))


class Union:
    def __init__(self, val):
        self.val = val
        self.parent = self
        self.rank = 0

    def get_root(self):
        n = self
        while n.parent != n:
            n = n.parent
        return n

    def find_set(self):
        return self.get_root().val

unions = []
for i in range(n):
    unions.append(Union(i))

def check_no_access(unions, a, b):
    roots = [u.find_set() for u in unions]
    cd = Counter(roots)
    return cd.get(roots[a]) * cd.get(roots[b])

ans = []
ans.append(n * (n - 1) // 2)

for a, b in brides[::-1]:
    x, y = unions[a - 1], unions[b - 1]
    x_root = x.get_root()
    y_root = y.get_root()
    if x_root.find_set() == y_root.find_set():
        ans.append(ans[-1])
        continue
    ans.append(ans[-1] - check_no_access(unions, a - 1, b - 1))
    if x_root.rank == y_root.rank:
        y_root.parent = x_root
        x_root.rank += 1
    elif x_root.rank > y_root.rank:
        y_root.parent = x_root
    else:
        x_root.parent = y_root
ans.pop()
for a in ans[::-1]:
    print(a)

### FIXED CODE ###

# https://atcoder.jp/contests/abc120/tasks/abc120_d
from collections import Counter
n, m = map(int, input().split())

brides = []
for _ in range(m):
    a, b = map(int, input().split())
    brides.append((a, b))


class Union:
    def __init__(self, val):
        self.val = val
        self.parent = self
        self.rank = 0
        self.size = 1

    def get_root(self):
        n = self
        while n.parent != n:
            n = n.parent
        return n

    def find_set(self):
        return self.get_root().val

unions = []
for i in range(n):
    unions.append(Union(i))

ans = []
ans.append(n * (n - 1) // 2)

for a, b in brides[::-1]:
    x, y = unions[a - 1], unions[b - 1]
    x_root = x.get_root()
    y_root = y.get_root()
    if x_root.find_set() == y_root.find_set():
        ans.append(ans[-1])
        continue
    ans.append(ans[-1] - x_root.size * y_root.size)
    if x_root.rank == y_root.rank:
        y_root.parent = x_root
        x_root.rank += 1
        size = x_root.size + y_root.size
    elif x_root.rank > y_root.rank:
        y_root.parent = x_root
    else:
        x_root.parent = y_root
    size = x_root.size + y_root.size
    x_root.size = size
    y_root.size = size
ans.pop()
for a in ans[::-1]:
    print(a)
### BUGGY CODE ###

N = int(input())
S = input()
S += S[0]
for key in ['SS', 'SW', 'WS', 'WW']:
    animals = key
    for i in range(N + 1):
        if i < 1:
            continue
        if animals[i] == 'S':
            if S[i] == 'o':
                animals += animals[-2]
            else:
                animals += 'S' if animals[-2] == 'W' else 'W'
        else:
            if S[i] == 'x':
                animals += animals[-2]
            else:
                animals += 'S' if animals[-2] == 'W' else 'W'
    if animals[0] == animals[-2] and animals[1] == animals[-1]:
        print(animals[:-2])
        exit(0)
print(-1)


### FIXED CODE ###

import sys
input = sys.stdin.readline

def main():
    N = int(input())
    S = input()
    for key in ['SS', 'SW', 'WS', 'WW']:
        animals = list(key)
        for i in range(N + 1):
            if i < 1:
                continue
            S_i = S[i] if i < N else S[0]
            if animals[i] == 'S':
                if S_i == 'o':
                    animals += animals[-2]
                else:
                    animals += 'S' if animals[-2] == 'W' else 'W'
            else:
                if S_i == 'x':
                    animals += animals[-2]
                else:
                    animals += 'S' if animals[-2] == 'W' else 'W'
        if animals[0] == animals[-2] and animals[1] == animals[-1]:
            print(''.join(animals[:-2]))
            exit(0)
    print(-1)


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

def solve(N,W,wv):
    dp=[[-1]*(W+1) for _ in range(N+1)]
    dp[0][0]=0
    for i in range(0,N):
        for j in range(W):
            cur_w=wv[i][0]
            cur_v=wv[i][1]
            if dp[i][j]>=0:
                dp[i+1][j]=max(dp[i+1][j],dp[i][j])
                if j+cur_w<=W:
                    dp[i+1][j+cur_w]=max(dp[i+1][j+cur_w],dp[i][j]+cur_v)
    ans=0
    for j in range(W+1):
        if ans < dp[N][j]:
            ans=dp[N][j]
    return ans
            


N,W=map(int,input().split())
wv=tuple(tuple(map(int,input().split())) for _ in range(N))
print(solve(N,W,wv))

### FIXED CODE ###

def solve(N,W,wv):
    dp=[-1]*(W+1)
    dp[0]=0
    for i in range(N):
        cur_w=wv[i][0]
        cur_v=wv[i][1]
        for j in range(W-cur_w,-1,-1):
            if dp[j]==-1:
                continue
            if dp[j+cur_w]<dp[j]+cur_v:
                dp[j+cur_w]=dp[j]+cur_v
    return max(dp)


N,W=map(int,input().split())
wv=tuple(tuple(map(int,input().split())) for _ in range(N))
print(solve(N,W,wv))
### BUGGY CODE ###

from heapq import *
def min_cost_flow_dijkstra(E, s, t, f):
    INF = 1<<100
    NN = T + 1
    G = [[] for _ in range(NN)]
    for a, b, cap, c in E:
        G[a].append([b, cap, c, len(G[b])])
        G[b].append([a, 0, -c, len(G[a])-1])
    prevv = [-1] * NN
    preve = [-1] * NN
    h = [0] * NN
    res = 0
    while f > 0:
        dist = [INF] * NN
        dist[s] = 0
        q = []
        heappush(q, (0, s))
        while q:
            di, v = q.pop()
            if dist[v] < di: continue
            for i, (b, _cap, c, r) in enumerate(G[v]):
                if _cap > 0 and dist[b] > dist[v] + c + h[v] - h[b]:
                    dist[b] = dist[v] + c + h[v] - h[b]
                    prevv[b] = v
                    preve[b] = i
                    heappush(q, (dist[b], b))
        
        
        if dist[t] == INF:
            return -1
        for v in range(NN):
            h[v] += dist[v]
        
        d = f
        v = t
        while v != s:
            d = min(d, G[prevv[v]][preve[v]][1])
            v = prevv[v]
        f -= d
        res += d * h[t]
        v = t
        while v != s:
            G[prevv[v]][preve[v]][1] -= d
            G[v][G[prevv[v]][preve[v]][3]][1] += d
            v = prevv[v]
    return res

E = []
inf = 1 << 17
N, H, W = map(int, input().split())
S, T = H+W+N, H+W+N+1
for i in range(H):
    E.append((S, i, 1, 0))
for i in range(W):
    E.append((S, H+i, 1, 0))
for i in range(N):
    r, c, a = map(int, input().split())
    r -= 1
    c -= 1
    E.append((r, H+W+i, 1, 0))
    E.append((H+c, H+W+i, 1, 0))
    E.append((H+W+i, T, 1, inf - a))

E.append((S, T, H+W, inf))
print(inf * (H+W) - min_cost_flow_dijkstra(E, S, T, H+W))

### FIXED CODE ###

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

def par(a):
    if P[a] < 0: return a
    t = par(P[a])
    P[a] = t
    return t
def unite(a, b):
    if par(a) == par(b): return 0
    C[par(a)], C[par(b)] = C[par(a)] + C[par(b)], C[par(a)] + C[par(b)]
    if P[par(b)] == P[par(a)]:
        P[par(b)] = par(a)
        P[par(a)] -= 1
    elif P[par(b)] > P[par(a)]:
        P[par(b)] = par(a)
    else:
        P[par(a)] = par(b)
N, H, W = map(int, input().split())
P = [-1 for i in range(H+W)]
C = [1] * (H+W)
X = []
for _ in range(N):
    r, c, a = map(int, input().split())
    X.append((a, r-1, c+H-1))
X = sorted(X)
ans = 0
while X:
    a, r, c = X.pop()
    unite(r, c)
    if C[par(r)]:
        ans += a
        C[par(r)] -= 1
print(ans)
### BUGGY CODE ###

import math

n,k = list(map(int, input().strip().split()))
a = list(map(int, input().strip().split()))
f = list(map(int, input().strip().split()))
a.sort()
f.sort()
f = f[::-1]
af = []
for i in range(n):
	af.append([a[i]*f[i], f[i]])
af.sort()
af = af[::-1]

r = af[0][0]
l = 0
while l < r:
	c = (l+r)//2
	training = 0
	for e in af:
		if c < e[0]:
			training += (e[0]-c + e[1]-1) // e[1]
	if training <= k:
		r = c
	else:
		l = c+1
print(l)


### FIXED CODE ###

import math

n,k = list(map(int, input().strip().split()))
a = list(map(int, input().strip().split()))
f = list(map(int, input().strip().split()))
a.sort()
f.sort()
#f = f[::-1]
af = [[] for i in range(n)]
r = 0
for i in range(n):
	af[i] = [a[n-1-i]*f[i], f[i]]
	r = max(r, af[i][0])
af.sort()
af = af[::-1]

#r = af[0][0]
l = 0
while l < r:
	c = (l+r)//2
	training = 0
	for e in af:
		if c >= e[0] or k < training:
			break
		training += (e[0]-c + e[1]-1) // e[1]
	if training <= k:
		r = c
	else:
		l = c+1
print(l)
### BUGGY CODE ###

if __name__ == '__main__':
    n = int(input().strip())
    A = list(map(int, input().strip().split()))
    A.sort(reverse=True)
    score = 0
    if not len(A) < 2:
        value_list = A[:2]
        min_max_list = [A[1], A[1]]
        score = A[0]
        for a in A[2:]:
            arg_max_index = min_max_list.index(max(min_max_list))
            score += min_max_list[arg_max_index]
            value_list.insert(arg_max_index + 1, a)
            min_max_list[arg_max_index] = a
            min_max_list.insert(arg_max_index, a)
    print(score)


### FIXED CODE ###

if __name__ == '__main__':
    n = int(input().strip())
    A = list(map(int, input().strip().split()))
    A.sort(reverse=True)

    score = A[0] + sum([A[1+int(i/2)]for i in range(0, n-2)])

    print(score)
### BUGGY CODE ###

def find_gcd(x, y):
    while(y): 
        x, y = y, x % y 
    return x


nums = int(input())
result = 0

for i in  range(1, nums+1):
    for j in range(1, nums+1):
        for l in range(1, nums+1):
            result += find_gcd(find_gcd(i, j), l)

print(result)

### FIXED CODE ###

from math import gcd

nums = int(input())
result = 0

gcd_dict = {}

for i in  range(1, nums+1):
    for j in range(1, nums+1):
        for l in range(1, nums+1):
            result += gcd(gcd(i, j), l)

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

import sys
from itertools import permutations


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n, l = inintm()

s = []
z = []

for _ in range(n):
    s.append(input())

for i in permutations(s,n):
    t = ""
    for j in i:
        t += j
    z.append(t)

z.sort()

print(z[0])


### FIXED CODE ###

import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n, l = inintm()

s = []

for _ in range(n):
    s.append(input())

s.sort()

print("".join(s))
### BUGGY CODE ###

import copy
K=200
primes=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199]
yakusuu_array=[]
for i in range(200):
  i+=1
  tmp=[]
  while i!=1:
    for prime in primes:
      if i % prime ==0:
        tmp.append(prime)
        i//=prime
  yakusuu_array.append(tmp)


def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)
    return x

ans=0
for i in range(1,K+1):
    for j in range(1,K+1):
        x=gcd(i,j)
        for k in range(1,K+1):
            ans+=gcd(x,k)
print(ans)


### FIXED CODE ###

n = int(input())
 
from math import gcd
 
y = 0
for i in range(1, n+1):
    for j in range(1, n+1):
        x = gcd(i, j)
        for k in range(1, n+1):
            y += gcd(x,k)
 
print(y)
### BUGGY CODE ###

H, W = map(int, input().split())

# 上下左右に余分に1マスとっとく
square = [[[0, 0, 0, 0] for _ in range(W + 2)] for _ in range(H + 2)]
for row in range(H + 2):
	for column in range(W + 2):
		if row == 0 or row == H + 1 or column == 0 or column == W + 1:
			square[row][column] = [-1, -1, -1, -1]

for row in range(H):
	S = list(map(str, input()))
	for column in range(W):
		if S[column] == "#":
			# 下駄をはかせるの忘れない
			square[row + 1][column + 1] = [-1, -1, -1, -1]
			

for row in range(1, H + 1):
	for column in range(1, W + 1):
		if square[row][column][0] == -1: continue
		square[row][column][0] = square[row][column - 1][0] + 1
		
for row in range(1, H + 1):
	for column in reversed(range(1, W + 1)):
		if square[row][column][0] == -1: continue
		square[row][column][1] = square[row][column + 1][1] + 1
		
for column in range(1, W + 1):
	for row in range(1, H + 1):
		if square[row][column][0] == -1: continue
		square[row][column][2] = square[row - 1][column][2] + 1
		
for column in range(1, W + 1):
	for row in reversed(range(1, H + 1)):
		if square[row][column][0] == -1: continue
		square[row][column][3] = square[row + 1][column][3] + 1

ret = 0
		
for row in range(1, H + 1):
	for column in range(1, W + 1):
		# print(row, column, 1 + sum(square[row][column]))
		ret = max(ret, 1 + sum(square[row][column]))
		
print(ret)

### FIXED CODE ###

H, W = map(int, input().split())

# 上下左右に余分に1マスとっとく
square = [[0 for _ in range(W)] for _ in range(H)]

for row in range(H):
	S = list(map(str, input()))
	for column in range(W):
		if S[column] == "#":
			# 下駄をはかせるの忘れない
			square[row][column] = -1
			
for row in range(H):
	done = [False for _ in range(W)]
	for column in range(W):
		if square[row][column] == -1: continue
		if done[column]: continue
		l = 1
		while column + l <= W - 1:
			if square[row][column + l] == -1: break
			l += 1
		for i in range(column, column + l):
			square[row][i] += l
			done[i] = True
			
for column in range(W):
	done = [False for _ in range(H)]
	for row in range(H):
		if square[row][column] == -1: continue
		if done[row]: continue
		l = 1
		while row + l <= H - 1:
			if square[row + l][column] == -1: break
			l += 1
		for i in range(row, row + l):
			square[i][column] += l
			done[i] = True

ret = 0			
for row in range(H):
	for column in range(W):
		ret = max(ret, square[row][column] - 1)
		
		
print(ret)
### BUGGY CODE ###

n,m = (int(i) for i in input().split())
p = list(0 for i in range(m))
y = list(0 for i in range(m))
for i in range(m):
    p[i], y[i] = (int(i) for i in input().split())

sum = 0
y_tmp = list([] for i in range(n))
y_sort = list([] for i in range(n))

for i in range(m):
    y_tmp[p[i]-1].append(y[i])
    sum+=1
    if sum == m:
        break

for i in range(n):
    y_sort[i] = sorted(y_tmp[i])


for i in range(m):
    print("{0:06d}{1:06d}".format(p[i], y_sort[p[i]-1].index(y[i])+1))

### FIXED CODE ###

N,M = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(M)]

cs = [[] for i in range(N+1)]
for i,(p,y) in enumerate(src):
    cs[p].append((y,i))
for cc in cs:
    cc.sort()

ans = [None] * M
for p in range(len(cs)):
    for i,(_,j) in enumerate(cs[p]):
        s = str(p).zfill(6) + str(i+1).zfill(6)
        ans[j] = s
print(*ans, sep='\n')
### BUGGY CODE ###

from functools import reduce
from operator import mul

n = int(input())
a_list = list(map(int, input().split()))

result = reduce(mul, a_list)
if result > 10**18:
    print(-1)
else:
    print(result)

### FIXED CODE ###

from functools import reduce
from operator import mul

n = int(input())
a_list = list(map(int, input().split()))

if 0 in a_list:
    print(0)
    exit()

result = 1
for i in range(n):
    result *= a_list[i]
    if result > 10**18:
        print(-1)
        exit()
print(result)
### BUGGY CODE ###

N = int(input())

power = 1
for i in range(1, N+1):
    power *= i
print(power % (10 ** 9 + 7))

### FIXED CODE ###

# N = int(input())

# power = 1
# for i in range(1, N+1):
#    power *= i
# print(power % (10 ** 9 + 7))

# TLEとなってしまう
# modの世界を使う

N = int(input())
power = 1
for i in range(1, N+1):
    power = power * i % (10 ** 9 + 7)

print(power)
### BUGGY CODE ###

from collections import defaultdict

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

keys = set()

def factorize(n):
    fct = defaultdict(int)
    b, e = 2, 0
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct[b] = e
        b, e = b + 1, 0
    if n > 1:
        fct[n] = 1

    for k, v in fct.items():
        keys.add(k)
    return fct
list(map(factorize, A))


max_factors = defaultdict(list)

def factorize2(n):
    fct = {}
    b, e = 2, 0
    for b in keys:
        while n % b == 0:
            n = n // b
            e = e + 1
        fct[b] = e
        max_factors[b].append(e)
        max_factors[b] = sorted(max_factors[b])[:2]
        b, e = b + 1, 0
    return fct
fcts = list(map(factorize2, A))

_res = 1

def it(fct):
    res = 1
    for k, ar in max_factors.items():

        if ar[0] == fct[k]:
            if len(ar) > 1:
                res *= k**ar[1]
        else:
            res *= k**ar[0]
    return res

print(max(it(fct) for fct in fcts))


### FIXED CODE ###

import numpy as np
from fractions import gcd

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


L = np.zeros(N, dtype=int)
R = np.zeros(N, dtype=int)

L[0] = A[0]


# L[i] .. A[0], A[1], A[i] の最大公約数
R[N-1] = A[N-1]
# R[i] .. A[-1], A[-2], .. A[(-(i+1)] の最大公約数
# R[i] .. A[N-1], A[N-2], .. A[(N-i-1)] の最大公約数

for i in range(1, N):
    L[i] = gcd(A[i], L[i-1])

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

def it(i):
    if i == 0:
        return R[1]
    if i == N-1:
        return L[N-2]
    return gcd(L[i-1], R[i+1])

# print(A)
# print(L)
# print(R)

print(max(it(i) for i in range(N)))
### BUGGY CODE ###

N = int(input())
T = [int(input()) for i in range(N)]
T.sort()
T.reverse()
result = T[0]

for i in range(1, N):
    a = 1
    while True:
        if (result * a) % T[i] == 0:
            result *= a
            break
        a += 1

print(result)


### FIXED CODE ###

N = int(input())
T = [int(input()) for i in range(N)]
result = T[0]

for i in range(1, N):
    n = T[i]
    m = result
    while n % m != 0:
        m, n = n%m, m
    result = (result * T[i]) // m

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

import sys
from functools import*
sys.setrecursionlimit(10**7)
@lru_cache(None)
def s(l,r):
  if r-l<2:return 0
  return min(s(l,i)+s(i,r)for i in range(l+1,r))+a[r-1]-a[l-1]
n,*a=map(int,open(0).read().split())
for i in range(n-1):a[i+1]+=a[i]
a+=[0]
print(s(0,n))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
def main():
  def s(l,r):
    k=l*n+r
    if d[k]:return d[k]
    if r-l<2:return 0
    d[k]=t=min(s(l,i)+s(i,r)for i in range(l+1,r))+a[r-1]-a[l-1]
    return t
  n,*a=map(int,open(0).read().split())
  d=[None]*(n*n+1)
  for i in range(n-1):a[i+1]+=a[i]
  a+=[0]
  print(s(0,n))
main()
### BUGGY CODE ###

import math
from sys import stdin


def get_result(data):
    A, B, N = data
    x = [B*(i+1)-1 for i in range(N//B+1)]
    ans = []
    for val in x:
        if val > N:
            val = N
        ans.append(math.floor(A*val/B) - A * math.floor(val/B))
    return max(ans)


if __name__ == '__main__':
    data = list(map(int, stdin.readline().rstrip().split(' ')))
    result = get_result(data)
    print(result)


### FIXED CODE ###

import math
from sys import stdin


def get_result(data):
    A, B, N = data
    if B == 1:
        return 0
    length = N//B+1
    x = [B*(i+1)-1 for i in range(length)]
    ans = []
    for val in x:
        if val > N:
            val = N
        ans.append(math.floor(A*val/B) - A*math.floor(val/B))
    return max(ans)


if __name__ == '__main__':
    data = list(map(int, stdin.readline().rstrip().split(' ')))
    result = get_result(data)
    print(result)
### BUGGY CODE ###

def main():
    import sys
    input = sys.stdin.readline
    N,Q = list(map(int, input().split()))
    S = list(input())
    L = []
    for _ in range(Q):
        temp = list(map(int, input().split()))
        L.append(temp)
    I = []
    for i in range(len(S)-1):
        if S[i] == "A" and S[i+1] == "C":
            I.append(i)
    for j in range(Q):
        cnt = 0
        l,r = L[j]
        R = []
        for k in range(l-1,r-1):
            R.append(k)
        for i in I:
            if i in R:
                cnt += 1
        print(cnt)
if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    import sys
    import re
    input = sys.stdin.readline
    N,Q = list(map(int, input().split()))
    S = list(input())
    L = []
    for _ in range(Q):
        temp = list(map(int, input().split()))
        L.append(temp)
    dp = [0] * N
    for i in range(1,N):
        if S[i] == "C" and S[i-1] == "A":
            dp[i] = dp[i-1] + 1
        else:
            dp[i] = dp[i-1]
    for j in range(Q):
        l,r = L[j]
        print(dp[r-1] - dp[l-1])
if __name__ == '__main__':
    main()
### BUGGY CODE ###

n = int(input())
list = []
max = 0
second = 0
max_index = []

for i in range(n):
    num = int(input())
    if num > max:
        max = num
    list.append(num)

for i,x in enumerate(list):
    if x == max:
        max_index.append(i)
    elif x > second:
        second = x

for i in range(n):
    if (i in max_index) & (len(max_index) == 1):
        print(second)
    else:
        print(max)


### FIXED CODE ###

n = int(input())
list = []
max = 0
second = 0
max_index = []

for i in range(n):
    num = int(input())
    if (num > max):
        max = num
    elif (num > second):
        second = num
    list.append(num)

counter = list.count(max)

for i,x in enumerate(list):
    if (x == max) & (counter == 1):
        print(second)
    else:
        print(max)
### BUGGY CODE ###

from heapq import heapify, heappush, heappop

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

day_value_dict = {}
for _ in range(n):
    a, b = map(int, input().split())
    day_value_dict[a] = day_value_dict.get(a, [])
    heappush(day_value_dict[a], -b)


res = 0
for m_i in range(1, m + 1):
    temp = 0
    selected_x = 0
    for x in range(1, m_i + 1):
        if x not in day_value_dict or not day_value_dict[x]:
            continue
        if day_value_dict[x][0] < temp:
            temp = day_value_dict[x][0]
            selected_x = x
    if selected_x:
        res += temp
        heappop(day_value_dict[selected_x])

print(-res)


### FIXED CODE ###

from heapq import heappush, heappop
n, m = map(int, input().split())

in_dict = {}
for _ in range(n):
    a, b = map(int, input().split())
    in_dict[a] = in_dict.get(a, [])
    in_dict[a].append(b)

heap = []
res = 0
for m_i in range(1, m + 1):
    for i in in_dict.get(m_i, []):
        heappush(heap, -i)
    if heap:
        res += -heappop(heap)

print(res)
### BUGGY CODE ###

from collections import  deque

x = int(input())

q = deque()
q.append((0, 0)) # (t, pos)
while q:
    t, pos = q.popleft()
#     print(t, pos)
    if pos == x:
        print(t)
        break
    else:
        q.append((t+1, pos))
        q.append((t+1, pos+t+1))
        if pos-t >= 1:
            q.append((t+1, pos-t-1))

### FIXED CODE ###

x = int(input())
s = 0
for i in range(1, x+1):
    s += i
    if s >= x:
        print(i)
        break
### BUGGY CODE ###

from math import log10
from collections import Counter
from scipy.special import comb
S = int(input())
l = int(log10(S)) + 1
counts = Counter((S := S % 10 ** (l - i)) % 2019 for i in range(l + 1))
print(sum(comb(n, 2, exact=True) for n in counts.values()))


### FIXED CODE ###

from collections import Counter
S = list(reversed(input()))
l = len(S)
N = 0
counts = Counter([(N := N + (pow(10, i, 2019) * int(S[i])) % 2019) % 2019 for i in range(l)] + [0])
print(sum(n * (n - 1) // 2 for n in counts.values()))
### BUGGY CODE ###

n = int(input())
A = [int(x) for x in input().split()]
A.sort()
ans = 0
for i, a in enumerate(A):
    if i != n - 1 and A[i + 1] == a:
        continue
    do_count = True
    for j in range(i):
        b = A[j]
        if a % b == 0:
            do_count = False
            break
    if do_count:
        ans += 1
print(ans)


### FIXED CODE ###

n = int(input())
A = [int(x) for x in input().split()]
A.sort()
lim = A[-1]
se = [True for i in range(lim + 1)]
ans = 0
for i, a in enumerate(A):
    if se[a]:
        if not((i != n - 1 and A[i + 1] == a) or (i != 0 and A[i - 1] == a)):
            ans += 1
        tmp = a
        while not tmp > lim:
            se[tmp] = False
            tmp += a
print(ans)