Harryxun/stf_run huggingface dataset:
N, M = list(map(int, input().split()))
S = input()
T = input()

from fractions import gcd
L = (N * M) // gcd(N, M)

L1 = [1]
L2 = [1]
# for i in range(1, N):
#     t = i * (L // N) + 1
#     L1.append(t)

# for i in range(1, M):
#     t = i * (L // M) + 1
#     L2.append(t)

LS = [None] * L
# for i, li in enumerate(L1):
#     ind = li-1
#     LS[ind] = S[i]

ans = True
# for i, li in enumerate(L2):
#     ind = li-1
#     if LS[ind] is not None:
#         if LS[ind] != T[i]:
#             ans = False

if ans:
    print(L)
else:
    print(-1)


# print(L1)
# print(L2)
# print(LS)

### FIXED CODE ###

from fractions import gcd

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

L = (N * M) // gcd(N, M)

L1 = [0]
L2 = [0]

from collections import Counter
c = Counter()

for i in range(1, N):
    t = i * (L // N) + 1
    L1.append(t-1)

for i in range(1, M):
    t = i * (L // M) + 1
    L2.append(t-1)


d = {}
for i, li in enumerate(L1):
    d[li] = S[i]

# print(d)

ans = True

for i, li in enumerate(L2):
    if not d.get(li):
        continue
    if d[li] != T[i]:
        ans = False

# print(L1)
# print(L2)
# print(common)
# print(dic)

if ans:
    print(L)
else:
    print(-1)
n=int(input())
l=[int(input()) for i in range(n)]
print(len(set(l))

### FIXED CODE ###

n=int(input())
l=[int(input()) for _ in range(n)]
print(len(set(l)))
while True:
    try:
	h = 0
	for i in range(10):
            tmp = raw_input()
            if sum(int(tmp)) != 0:
                a[h] = tmp
		h += 1
      	if h == 4:
	    print "B"
	elif h == 1:
	    print "C"
	elif h == 2:
            c = int(a[0])/int(a[1])
            if c == 1:
            	print "A"
	    elif c == 10:
		print "E"
	    elif c == 0:
            	print "G"
	else:
	    c = int(a[0])/int(a[2])
	    if c ==	10:
            	print "F"
	    else:
            	print "D"

### FIXED CODE ###

while True:
    try:
        h = 0
        a=["","","",""]
        for i in range(8):
            tmp = raw_input()
            if int(tmp) != 0:
                a[h] = tmp
                h += 1
    	if h == 1:
            print "C"
        elif h == 2:
            c = a[0].index("1") - a[1].index("1")
            if c == 0:
                print "A"
            elif c == -1:
                print "E"
            else:
                print "G"
        elif h == 3:
            c = a[0].index("1") - a[2].index("1")
            print "D" if c == 1 else "F"
        else:
            print "B"
    	raw_input()
    except:
	break
from itertools import accumulate
import heapq as hq
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(n)]
ab.sort()
ls = []
hq.heapify(ls)
k = max([a[0] for a in ab])
daylist = [0]*(k+1)
for i in range(n):
  daylist[ab[i][0]] += 1
daylistsum = list(accumulate(daylist))
ans = 0
for i in range(1,m+1):
  for j in range(daylistsum[i-1],daylistsum[i]):
    hq.heappush(ls,-ab[j][1])
  if ls:
    ans -= hq.heappop(ls)
print(ans)

### FIXED CODE ###

from itertools import accumulate
import heapq as hq
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(n)]
ab.sort()
ls = []
hq.heapify(ls)
k = max([a[0] for a in ab]+[m])
daylist = [0]*(k+1)
for i in range(n):
  daylist[ab[i][0]] += 1
daylistsum = list(accumulate(daylist))
ans = 0
for i in range(1,m+1):
  for j in range(daylistsum[i-1],daylistsum[i]):
    hq.heappush(ls,-ab[j][1])
  if ls:
    ans -= hq.heappop(ls)
print(ans)
from math import sqrt, inf

l, r = map(int, input().split())

flag = False
if r // 2019 - l // 2019 != 0:
    flag = True

if flag:
    print(0)
else:
    lmod = l % 2019
    rmod = r % 2019
    root = int(sqrt(2019))

    n1, n2 = inf, inf
    p = lmod // root
    q = rmod // root + 1
    for m in range(p, q+1):
        for i in range(lmod, rmod+1):
            if i - m * root > 0 and i - m * root < n1:
                tmp = n1
                n1 = i
                n2 = tmp
            elif i - m * root > 0 and i - m * root < n2:
                n2 = i

    print((n1 * n2) % 2019)


### FIXED CODE ###

l, r = map(int, input().split())

flag = False
if l % 2019 == 0 or r // 2019 - l // 2019 != 0:
    flag = True

if flag:
    print(0)
else:
    lmod = l % 2019
    rmod = r % 2019

    ans = 10**5
    for i in range(lmod, rmod):
        for j in range(i+1, rmod+1):
            ans = min((i * j) % 2019, ans)
    print(ans)
d=input()
t=input()
s=input()

    
    if s*t >= d:
        print ('Yes')
    
    else:
        print ('No')

### FIXED CODE ###

#輸入字串並分隔，以list儲存
str_in = input()
num = [int(n) for n in str_in.split()]
num =list(map(int, str_in.strip().split()))  
#print(num) #D,T,S

#若T<(D/S)->遲到
if num[1] > (num[0]/num[2]):
    print("Yes")
elif num[1] == (num[0]/num[2]):
    print("Yes")
else:
    print("No")
a, b, c = map(int, input())

print("{} {} {}".format(c, a, b))

### FIXED CODE ###

a, b, c = map(int, input().split())
 
print("{} {} {}".format(c, a, b))
# coding: utf-8
# Your code here!
n,a,b = map(int,input().split())
c = a+b

count = int(n/c)*a+min(n%c,a)

print(count)# coding: utf-8
# Your code here!
n,a,b = map(int,input().split())
c = a+b

count = int(n/c)*a+min(n%c,a)

print(count)

### FIXED CODE ###

# coding: utf-8
# Your code here!
n,a,b = map(int,input().split())
c = a+b

count = int(n/c)*a+min(n%c,a)

print(count)
import math
n,m=map(int,input().split())
lis  = list(map(int,input().split()))
#aそれぞれを2で割ったものを持っておく
div = []
for i in range(n):
    div.append(lis[i]//2)
#lisそれぞれの要素を2で割り切れる回数をすべて数える
L = []
for i in range(n):
    cnt = 0
    while lis[i] %2 ==0:
        lis[i] //= 2
        cnt += 1
    L.append(cnt)

bl = True
for i in range(n-1):
    if L[0] != L[i+1]:
        bl = False
        print(0)
        break
#div内の最小子公倍数Tを求める
T = 0
ans = div[0]
for i in range(1,n):
    ans =ans*div[i]//math.gcd(ans,div[i])
    T = ans

S = m//T
if S %2 ==0:
    print(S//2)
else:
    print(S//2 +1)


### FIXED CODE ###

import fractions
n,m=map(int,input().split())
lis  = list(map(int,input().split()))
#aそれぞれを2で割ったものを持っておく
div = []
for i in range(n):
    div.append(lis[i]//2)
#lisそれぞれの要素を2で割り切れる回数をすべて数える
L = []
for i in range(n):
    cnt = 0
    while lis[i] %2 ==0:
        lis[i] //= 2
        cnt += 1
    L.append(cnt)

bl = True
#重複要素を削除して要素数でLがすべて一緒か判断
def set_list(es):
    return len(list(set(es))) == 1

if set_list(L) != 1:
    print(0)
    exit()

#div内の最小子公倍数ansを求める

ans = div[0]
for i in range(1,n):
    ans =ans*div[i]//fractions.gcd(ans,div[i])

S = m//ans
if S %2 ==0:
    print(S//2)
else:
    print(S//2 +1)
n, m = map(int, input().split())
g = {i: [] for i in range(n)}
for i in range(m):
    l, r, d = map(int, input().split())
    g[l - 1].append((r - 1, d))
    g[r - 1].append((l - 1, -d))
l = [-1] * n
l[0] = n
stack = [r]
s = set()
while stack:
    d = stack.pop()
    if d in s:
        continue
    for node, cost in g[d]:
        if l[node] == -1:
            l[node] = l[d] + cost
        else:
            if l[node] != l[d] + cost:
                print('No')
                exit()
        stack.append(node)
    s.add(d)
print('Yes')


### FIXED CODE ###

n, m = map(int, input().split())
g = [[] for _ in range(n)]
for i in range(m):
    l, r, d = map(int, input().split())
    g[l - 1].append((r - 1, d))
    g[r - 1].append((l - 1, -d))
l = [None] * n
for i in range(n):
    if l[i] != None:
        continue
    l[i] = 0
    stack = [i]
    while stack:
        d = stack.pop()
        for node, cost in g[d]:
            if l[node] == None:
                l[node] = l[d] + cost
                stack.append(node)
            else:
                if l[node] != l[d] + cost:
                    print('No')
                    exit(0)
print('Yes')
def main() :
    n = int(input())
    nums = [int(i) for i in input().split()]
    exchange_count = 0

    for i in range(n) :
        minj = i
        for j in range(i,n) :
            if nums[j] < nums[minj] :
                minj = j
        if minj != i :
                exchange_count += 1
        nums[i], nums[minj] = nums[minj], nums[i]

    print(" ".join(map(str, nums)))
    print(excnage_count)

if __name__ == '__main__' :
    main()

### FIXED CODE ###

def main() :
    n = int(input())
    nums = [int(i) for i in input().split()]
    exchange_count = 0

    for i in range(n) :
        minj = i
        for j in range(i, n) :
            if nums[j] < nums[minj] :
                minj = j
        if minj != i :
                exchange_count += 1
        nums[i], nums[minj] = nums[minj], nums[i]

    print(" ".join(map(str, nums)))
    print(exchange_count)

if __name__ == '__main__' :
    main()
from scipy.sparse.csgraph import floyd_warshall

N, M, L = map(int, input().split())
edges = [[0] * N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    edges[a - 1][b - 1] = c
    edges[b - 1][a - 1] = c

Q = int(input())
st = []
for _ in range(Q):
    st.append([int(j) - 1 for j in input().split()])

edges = floyd_warshall(edges)

for i in range(N):
    for j in range(N):
        if edges[i][j] <= L:
            edges[i][j] = 1
        else:
            edges[i][j] = 0

edges = floyd_warshall(edges)

for i, j in st:
    if edges[i][j] == float("inf"):
        print(-1)
    else:
        print(int(edges[i][j]) - 1)


### FIXED CODE ###

from scipy.sparse.csgraph import floyd_warshall

N, M, L = map(int, input().split())
edges = [[0] * N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    edges[a - 1][b - 1] = c
    edges[b - 1][a - 1] = c

Q = int(input())
st = []
for _ in range(Q):
    st.append([int(j) - 1 for j in input().split()])

edges = floyd_warshall(edges)

for i in range(N):
    for j in range(N):
        if edges[i][j] <= L:
            edges[i][j] = 1
        else:
            edges[i][j] = 0

edges = floyd_warshall(edges)

for i, j in st:
    if edges[i][j] == float("inf"):
        print(-1)
    else:
        print(int(edges[i][j]) - 1)
from collections import deque

N,M=map(int,input().split())
a=[set() for i in range(N)] # 0-index
for i in range(M):
    u,v=map(lambda x:int(x)-1,input().split())
    a[u].add(v)
S,T=map(lambda x:int(x)-1,input().split())
# print(a)

r=[-1 for i in range(N)]
q0=deque();q1=deque();q2=deque()
q0.append(S);r[S]=0
while q0:
    u=q0.popleft()
    for v in a[u]:
        q1.append(v)
    for w in a[v]:
        q2.append(w)
    for x in a[w]:
        if r[x]==-1:
            r[x]=r[u]+1
            q0.append(x)
# print(r)
print(r[T])

### FIXED CODE ###

from collections import deque

N,M=map(int,input().split())
a=[[[] for j in range(N)] for i in range(3)] # 0-indexのグラフが3つある
for i in range(M):
    u,v=map(lambda x:int(x)-1,input().split())
    a[0][u].append((1,v))
    a[1][u].append((2,v))
    a[2][u].append((0,v))
S,T=map(lambda x:int(x)-1,input().split())
# print(a)

r=[[-3 for j in range(N)] for i in range(3)]
q=deque()
q.append((0,S));r[0][S]=0
while q:
    ui,uj=q.popleft()
    for vi,vj in a[ui][uj]:
        if r[vi][vj]==-3:
            r[vi][vj]=r[ui][uj]+1
            q.append((vi,vj))
# print(r)
print(r[0][T]//3)
s = list(innput())

if len(s) == len(set(s)):
    print('yes')
else:
    print('no')


### FIXED CODE ###

s = list(input())

if len(s) == len(set(s)):
    print('yes')
else:
    print('no')
a, b = input().split()
s = a * int(b)
t = b * int(a)
print(s if s < t else t)* int(b)
t = b * int(a)
print(s if s < t else t)


### FIXED CODE ###

a, b = input().split()
s = a * int(b)
t = b * int(a)
print(s if s < t else t)
while True:
    n,w=map(int,raw_input().split())
    if n==w==0:break
    L=[0]*(w+1)
    for i in range(n):
        v=input()
        L[v/w]+=1
    maxh=max(L)
    r=n-1
    while r>0 and L[r]==0:
        r-=1
    ink=0.01
    for i in range(r+1):
        if r<>0:
            ink+=float(r-i)/r*float(L[i])/maxh
        else:
            ink+=L[i]
    print ink

### FIXED CODE ###

while True:
    n,w=map(int,raw_input().split())
    if n==w==0:break
    L=[0]*(w+1)
    for i in range(n):
        v=input()
        L[v/w]+=1
    maxh=max(L)
    r=w
    while r>0 and L[r]==0:
        r-=1
    ink=0.01
    for i in range(r+1):
        if r<>0:
            ink+=float(r-i)/r*float(L[i])/maxh
        else:
            ink+=L[i]
    print ink
N, Q = map(int, input().split())

AB = [[int(x) for x in input().split()] for _ in range(N-1)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]

graph = [[] for _ in range(N+1)]
for a, b in AB:
  graph[a].append(b)
  graph[b].append(a)

value = [0] * (N+1)
for p, x in PX:
  value[p] += x

def dfs(v, parent, add):
  value[v] += add
  for x in graph[v]:
    if x == parent:
      continue
    dfs(x, v, value[v])

dfs(1, 0, 0)    
ans = ' '.join(map(str, value[1:]))
print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
N, Q = map(int, input().split())

AB = [[int(x) for x in input().split()] for _ in range(N-1)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]

graph = [[] for _ in range(N+1)]
for a, b in AB:
  graph[a].append(b)
  graph[b].append(a)

value = [0] * (N+1)
for p, x in PX:
  value[p] += x

def dfs(v, parent):  
  for i in graph[v]:
    if i == parent:
      continue
    value[i] += value[v]
    dfs(i, v)

dfs(1, 0)    
ans = ' '.join(map(str, value[1:]))
print(ans)
a,b,c = list(map(int,input().split()))
if a**2 + b**2 + c**2 -2*(a*b +*b*c +*c*a) >0:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

a,b,c = list(map(int,input().split()))
if (c-a-b)**2 -4*a*b >0 and c-a-b>0:
  print('Yes')
else:
  print('No')
N = int(input())
S = list(input())
K = int(input())

 
for i in range(N):
    if(S[i] != S[K]):
        S[i] = '*'
 
S = "".join(S)
 
print(S)

### FIXED CODE ###

N = int(input())
S = list(input())
K = int(input())

for i in range(N):
    if(S[i] != S[K-1]):
        S[i] = '*'

S = "".join(S)

print(S)
import sys
s1=input ()
s2=input ()
for _ in range(len (s1)):
  if s1==s2:
    print ('Yes ')
    sys.exit ()
  s1=s1[-1]+s[:-1]
print ('No ')

### FIXED CODE ###

import sys
s1=input ()
s2=input ()
for _ in range(len (s1)):
  if s1==s2:
    print ('Yes ')
    sys.exit ()
  s1=s1[-1]+s1[:-1]
print ('No ')
n=int(input())
a_list=list(map(int,input().split()))
ans=0
tmp=a_list[0]
for i in range(n-1):
    if tmp>a_list[i+1]:
        #print(tmp,ans)
        ans+=tmp-a_list[i+1]
    else:
        ans+=tmp-a_list[i]
        tmp=a_list[i+1]
print(ans)

### FIXED CODE ###

N,X,T=map(int,input().split())
a=N//X
if N%X==0:
    print(a*T)
else:
    print(a*T+T)
S = input()
T = input()

import sys
sys.setrecursionlimit(2147483647)

def dfs(i,j):
    if (i,j) in dic: return dic[(i,j)]
    if i > len(S) - 1 or j > len(T) - 1:
        return ""
    ans  = ""
    if S[i] == T[j]:
        ans = S[i] + dfs(i + 1,j + 1)
    else:
        res1 = dfs(i + 1,j)
        res2 = dfs(i, j + 1)
        if max([len(res1),len(res2)]) == len(res1):
            ans = res1
        else:
            ans = res
    dic[(i,j)] = ans
    return ans
dic = {}
print(dfs(0,0))
    

### FIXED CODE ###

S = input()
T = input()
dp = [[ 0] * (len(S) + 1 ) for _ in range(len(T) + 1)]
ma = 0
for i in range(len(dp)-1):
    for j in range(len(dp[0])-1):
        if T[i ] == S[j]:
            dp[i + 1][j + 1] = dp[i][j] + 1
        else:
             dp[i + 1][j + 1]  = max(dp[i][j + 1],dp[i +1][j])
i = len(T) - 1
j = len(S) - 1 
ans = ""
while i >=0 and j >= 0:
    if dp[i][j+1] == dp[i + 1][j + 1]:
        i-=1
    elif dp[i + 1][j] == dp[i + 1][j + 1]:
        j-=1
    else:
        #print(j,i)
        ans = S[j] + ans
        i-=1
        j-=1
print(ans)
x,y,z,k=map(int,input().split())
*a,=map(int,input().split())
*b,=map(int,input().split())
*c,=map(int,input().split())

def merge_sort(array):
    if len(array) <= 1:
        return array
    cnt=len(array)//2
    left=array[:cnt]
    right=array[cnt:]
    left = merge_sort(left)
    right = merge_sort(right)
    return merge(left, right)


def merge(left, right):
    array = [0]*3000
    l,r,ind=0,0,0
    if right[0]<left[-1]:
        return left
    while l < len(left) and r < len(right):
        if left[l] >= right[r]:
            array[ind]=left[l]
            l+=1
            ind+=1
        else:
            array[ind]=right[r]
            r+=1
            ind+=1
        if ind>=3000:
            return array
    if l < len(left):
        return array[:ind]+left[l:]
    if r < len(right):
        return array[:ind]+right[r:]

a=merge_sort(a)
b=merge_sort(b)
c=merge_sort(c)
l,r=[],[]
for i in a:
  for j in b:
    l.append(i+j)
l=merge_sort(l)
for i in l:
  for j in c:
    r.append(i+j)
r=merge_sort(r)
for i in range(k):
    print(r[i])

### FIXED CODE ###

x,y,z,q=map(int,input().split())
a=sorted(map(int,input().split()),reverse=True)
b=sorted(map(int,input().split()),reverse=True)
c=sorted(map(int,input().split()),reverse=True)
 
def bisect(l,r):
  cnt=(l+r)//2
  if cnt==l:
    return l-1+judge(l)
  if judge(cnt):
    return bisect(cnt+1,r)
  else:
    return bisect(l,cnt)
def judge(thr):
  m=0
  for i in range(x):
    for j in range(y):
      if i*j>q:
        break
      for k in range(z):
        if i*j*k>q or a[i]+b[j]+c[k]<thr:
          break
        m+=1
        if m>=q:
          return True
  return False
def make(thr):
  m=0
  l=[]
  for i in a:
    for j in b:
      for k in c:
        n=i+j+k
        if n<thr+1:
          break
        m+=1
        l+=[n]
  l.sort(reverse=True)
  return l+[thr]*(q-len(l))
thr=bisect(0,a[0]+b[0]+c[0]+1)
ans=make(thr)
for w in ans:
  print(w)
import numpy as np
import math
import itertools
n = int(input())
l = list(map(int, input().split()))
ans = 0
pos = [0] * n
for i in range(n):
    pos[i] = list(map(lambda x: abs(x - i), list(range(n))))
pos = np.array(pos)
tot = np.zeros(math.factorial(n))
for i in range(n):
    pos[i, :] = pos[i, :] * l[i]
for i, x in enumerate(itertools.permutations(range(n))):
    tot[i] = np.sum(pos[list(range(n)), x])
print(int(np.max(tot)))


### FIXED CODE ###

import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
A = np.array(read().split(), np.int64)
I = np.argsort(A)[::-1].tolist()
A = A[I].tolist()

dp = np.zeros(1, np.int64)

for n, (i, x) in enumerate(zip(I, A)):
    newdp = np.zeros(len(dp) + 1, np.int64)
    left_ind = np.arange(len(dp))
    right_ind = N - 1 - n + left_ind
    left_cost = x * np.abs(left_ind - i)
    right_cost = x * np.abs(right_ind - i)
    np.maximum(newdp[:-1], dp + right_cost, out=newdp[:-1])
    np.maximum(newdp[1:], dp + left_cost, out=newdp[1:])
    dp = newdp

print(dp.max())
import sys
import itertools
from operator import itemgetter #sortedの対象を決めたい
from fractions import gcd #最大公約数
from math import ceil, floor, sqrt, isinf #小数点切り上げ、切り捨て、平方根
from copy import deepcopy #参照で影響されないコピー
from collections import Counter, deque #要素ごとの出現回数、双方向アクセス可能データ型
import heapq
import numpy as np
from functools import reduce
sys.setrecursionlimit(200000)

input = sys.stdin.readline
# template


n = int(input())
#h = list(map(int, input().split()))
h = [int(x) for x in input().split()]

dp = 1e9 * n

dp[0] = 0

for i in range(1, n):
    dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]))
    if(i > 1):
        dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]))

print(dp[n-1])


### FIXED CODE ###

import sys
import itertools
from operator import itemgetter #sortedの対象を決めたい
from fractions import gcd #最大公約数
from math import ceil, floor, sqrt, isinf #小数点切り上げ、切り捨て、平方根
from copy import deepcopy #参照で影響されないコピー
from collections import Counter, deque #要素ごとの出現回数、双方向アクセス可能データ型
import heapq
import numpy as np
from functools import reduce
sys.setrecursionlimit(200000)

input = sys.stdin.readline
# template


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

dp = [1e9] * n

dp[0] = 0

for i in range(1, n):
    dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]))
    if(i > 1):
         dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]))

print(dp[-1])
list =[int(input()) for i in range(3)]
N ,A, B= list[0],list[1],list[2]

ans = 0
for i in range(1,N+1):
    i1 =  i%10
    i10 = (i%100 -i1)/10
    i100 = (i%1000 -i1 - 10*i10)/100
    i1000 = (i%10000 -i1 - 10*i10-100*i100)/100
    i10000 = (i -i1 -10*i10 -100*i100 - 1000*i1000)/10000
    if A<=i1+i10+i100+i1000+i10000<=B:
        ans +=1
print(ans)

### FIXED CODE ###

lis=list(map(int,input().split()))
N ,A, B= lis[0],lis[1],lis[2]

ans = 0
for i in range(1,N+1):
    i1 =  i%10
    i10 = (i%100 -i1)/10
    i100 = (i%1000 -i1 - 10*i10)/100
    i1000 = (i%10000 -i1 - 10*i10-100*i100)/1000
    i10000 = (i -i1 -10*i10 -100*i100 - 1000*i1000)/10000
    if A<=i1+i10+i100+i1000+i10000<=B:
        ans += i
print(ans)
n,m = map(int,input().split())
lis = [[] for _ in range(10)]
for _ in range(n):
    a,b = map(int,input().split())
    lis[a-1].append(b)
ans = 0
li = []
for i in range(m):
    li += lis[i]
    li.sort(reverse=True)
    try:
        p = li.pop(0)
        ans += p
    except:
        continue
print(ans)

### FIXED CODE ###

from heapq import heappush,heappop,heapify

n,m = map(int,input().split())
lis = [[] for i in range(m+1)]

for _ in range(n):
    a,b = map(int,input().split())
    if a <= m:
        lis[a].append(-b)

ans = 0
num = []
heapify(num)

for j in range(1,m+1):
    for nu in lis[j]:
        heappush(num,nu)
    if len(num) > 0:
        work = heappop(num)
        ans += -work
print(ans)
a, b = map(int, input(),split())

if a + b < 10:
    print(a + b)
else:
    print('error')

### FIXED CODE ###

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

if a + b < 10:
    print(a + b)
else:
    print('error')
_,p = [list(map(int, s.split())) for s in open(0)]
lcm = np.lcm.reduce(p)
x = 1e9 + 7
ans = 0
for q in p:
    ans += int((lcm/q)%x)
print(int(ans%x))

### FIXED CODE ###

from fractions import gcd
from functools import reduce

#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

def lcm_mod(a, mod=-1):
    x = a[0]
    if mod == -1:
        for i in range(1, len(a)):
            x = (x * a[i]) // gcd(x, a[i])
    else:
        for i in range(1, len(a)):
            x *= (a[i] * mod_inv(gcd(x, a[i]), P)) % P
    return x

_,a = [list(map(int, s.split())) for s in open(0)]

P = 10**9 + 7
N = max(a)

lcm_ = lcm_mod(a, P)

ans = 0
for x in a:
    ans += int((lcm_*mod_inv(x,P))%P)
print(int(ans%P))
a = str(input())
if a.isupper():
  print(A)
else:
  print(a)

### FIXED CODE ###

x = str(input())
if x.isupper() == True:
  print("A")
else:
  print("a")
N,K=map(int,input().split())
A=list(map(int,input().split()))

ans=[]
judge={}
j=0 #A進み
while judge[A[j]]!=2:
    ans.append(A[j])
    if A[j] not in judge.keys():
        judge[A[j]]=0
    judge[A[j]]+=1
    j=A[j]-1
ans.append(A[j])

st=ans.index(A[j])
ans=ans[st:-1]
K-=st
l=len(ans)
#print(ans)
print(ans[K%l-1])

### FIXED CODE ###

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

ans=[]
judge={}
j=0 #A進み
while A[j] not in judge.keys() or judge[A[j]]!=2:
    ans.append(A[j])
    if A[j] not in judge.keys():
        judge[A[j]]=0
    judge[A[j]]+=1
    j=A[j]-1

st=ans.index(A[j])

if st<K:
    ans=ans[st:]
    K-=st
    l=len(ans)
    #print(ans)
    print(ans[K%l-1])
else:
    print(ans[K-1])
n=int(input())
a=list(map(int,input().split()))
m=int(input())
s=sum(a)
for i in range(m):
    p,x=map(int,input().split())
    print(s-a[p]+x)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
m=int(input())
s=sum(a)
for i in range(m):
    p,x=map(int,input().split())
    print(s-a[p-1]+x)
N = int(input())
P = list(map(int,input().split()))
cnt = 1
flag = 0 #flag 0=,1=+,2=-
for i in range(1,N+1):
    if P[i-1]!=P[i] and flag == 0:
        flag = 1
    elif flag == 1 and ((P[i-1] > P[i]) != (P[i-2]>P[i-1])):
        cnt += 1
        flag = 0
print(cnt)



### FIXED CODE ###

N = int(input())
P = list(map(int,input().split()))
cnt = 1
flag = 0 
for i in range(1,N):
    if P[i-1]>P[i] and flag == 0:
        flag = 1
    elif P[i-1]<P[i] and flag == 0:
        flag = 2
    elif flag == 1 and (P[i-1] < P[i]) :
        cnt += 1
        flag = 0
    elif flag == 2 and (P[i-1] > P[i]) :
        cnt += 1
        flag = 0
print(cnt)