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

L,R = list(map(int, input().split()))


MOD=[0] * (2019*2019)

def myidx(i,j):
    return i * 2019 + j

for i in range(2019):
    for j in range(2019):
        idx = myidx(i,j)
        MOD[idx] = (i*j) % 2019

for i in range(2019):
    idx = myidx(i,i)
    MOD[idx] = 2019

MMM = []
Lmod = L % 2019
Rmod = R % 2019

if L+2019 <= R:
    for i in range(2019):
        for j in range(i+1,2019):
            idx = myidx(i,j)
            MMM.append(MOD[idx])
elif Lmod <= Rmod:
    for i in range(Lmod, Rmod+1):
        for j in range(i+1, Rmod+1):
            idx = myidx(i,j)
            MMM.append(MOD[idx])

elif Lmod > Rmod:
    for i in list(range(0,Rmod+1)) + list(range(Lmod, 2019)):
        for j in list(range(i+1,Rmod+1)) + list(range(i+1, 2019)):
            idx = myidx(i,j)
            MMM.append(MOD[idx])

MMM.sort()
print(MMM.pop(0))


### FIXED CODE ###

L,R = list(map(int, input().split()))

MOD=[0] * (2019*2019)

def myidx(i,j):
    return i * 2019 + j

for i in range(2019):
    for j in range(i+1,2019):
        idx = myidx(i,j)
        MOD[idx] = (i*j) % 2019

#for i in range(2019):
#    idx = myidx(i,i)
#    MOD[idx] = 2019

MMM = []
MIN = 2019
Lmod = L % 2019
Rmod = R % 2019

if L+2019 <= R:
    for i in range(2019):
        for j in range(i+1,2019):
            idx = myidx(i,j)
            MIN = min(MIN, MOD[idx])
            #MMM.append(MOD[idx])
elif Lmod <= Rmod:
    for i in range(Lmod, Rmod+1):
        for j in range(i+1, Rmod+1):
            idx = myidx(i,j)
            MIN = min(MIN, MOD[idx])
            #MMM.append(MOD[idx])

elif Lmod > Rmod:
    for i in list(range(0,Rmod+1)) + list(range(Lmod, 2019)):
        for j in list(range(i+1,Rmod+1)) + list(range(max(Lmod,i+1), 2019)):
            idx = myidx(i,j)
            MIN = min(MIN, MOD[idx])
            #MMM.append(MOD[idx])

#MMM=list(set(MMM))
#MMM.sort()
#print(MMM.pop(0))
print(MIN)
### BUGGY CODE ###

from queue import Queue
n, x, y = map(int, input().split())

links = [[] for i in range(n)]
for i in range(1, n):
        links[i-1].append(i)
        links[i].append(i-1)
links[x-1].append(y-1)
links[y-1].append(x-1)

ans = [0] * n
for i in range(n):
        dist = [1e5] * n
        used = [0] * n
        que = Queue()
        que.put([i, 0])
        while not que.empty():
                v, dis = que.get()
                used[v] = True
                for to in links[v]:
                        if not used[to]:
                                dist[to] = min(dist[to], dis)
                                que.put([to, dis+1])
        for a in dist:
                if a<1e5: ans[a] += 1
for i in range(n-1): print(ans[i]//2)

### FIXED CODE ###

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

ans = [0] * (n+1)
for i in range(1, n+1):
        for j in range(i+1, n+1):
                ans[min(j-i, abs(i-x)+1+abs(j-y))] += 1
for i in range(1, n): print(ans[i])
### BUGGY CODE ###

import fractions
N = int(input())
A = [int(i) for i in input().split()]

mod = 10**9 + 7


lcm = 1
for a in A:
    lcm = lcm*a//fractions.gcd(lcm, a)
# print(lcm)

ans = 0
for a in A:
    ans += lcm//a
    ans %= mod
print(ans)


### FIXED CODE ###

import functools
import fractions
N = int(input())
A = [int(i) for i in input().split()]
S = set(A)


mod = 10**9 + 7


def multiple(a, b):
    return a*b // fractions.gcd(a, b)


def lcm(nums):
    return functools.reduce(multiple, nums)


lcm = lcm(S)

ans = 0
for a in A:
    ans += lcm//a
    # ans %= mod
print(ans % mod)
### BUGGY CODE ###

tmp=input()
list=input().split(" ")
#list = map((lambda e: int(e)), list)
#array=numpy.zeros(len(list),dtype=">i4")
#for i in range(len(list)):
#  array[i]=int(list[i])

a=int(input())

for i in range(a):
  b=input().split(" ")
  list = [s.replace(b[0],b[1]) for s in list]
  print(sum(int(j) for j in list))
  #if int(b[0]) in array:
  #  pos=numpy.where(array==int(b[0]))[0]
  #  for j in pos:
  #    array[j]=int(b[1])
  #  sum=numpy.sum(array)
  #  print(sum)
  #else:
  #  sum=numpy.sum(array)
  #  print(sum)
  


### FIXED CODE ###

import numpy

tmp=input()
list=input().split(" ")
list=[int(x) for x in list]
array=numpy.array(list,dtype=">i4")
sum=numpy.sum(array)
all=numpy.zeros(100001,dtype=">i4")
for i in array:
  all[i]+=1
#for i in range(len(list)):
#  array[i]=int(list[i])

a=int(input())

for i in range(a):
  b=input().split(" ")
  b0=int(b[0])
  b1=int(b[1])
  diff=all[b0]*(b1-b0)
  sum+=diff
  all[b1]+=all[b0]
  all[b0]=0
  print(sum)
### BUGGY CODE ###

import math
n,m = map(int,input().split())
 
a = input()
list1 = list(map(int,a.split()))
 
list1.sort()
 
for i in range(m):
    list1[-1] = math.floor(list1[-1]/2)
    list1.sort()
print(sum(list1))

### FIXED CODE ###

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

a = input()
list1 = list(map(int,a.split()))
list1.sort()
list1.reverse()
i = 0
s = math.floor(list1[0]/2)

if n == 1:
    print(math.floor(list1[0]/(2**m)))
    exit()

while True:
    while True:
        if i+1 > n:
            break
        if list1[i] < s or m == 0:
            break
        list1[i] = math.floor(list1[i]/2)
        m -= 1
        i += 1
    if m == 0:
        break
    list1.sort()
    list1.reverse()
    s = math.floor(list1[0]/2)
    i = 0
print(sum(list1))
### BUGGY CODE ###

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

argmax = lambda a: a.index(max(a))
ids = {i:[] for i in range(1, N+1)}
[ids[p].append(y) for p, y in cities]
for k in ids:
    for _ in ids[k]:
        ids[k][argmax(ids[k])] = 0
        ids[k] = list(map(lambda x: x+1, ids[k]))

[print("{:06}{:06}".format(p, ids[p].pop(0))) for p, _ in cities]


### FIXED CODE ###

N, M = map(int, input().split())
cities = [int("{}{:010}".format(*tuple(map(int, input().split())))) for _ in range(M)]
sorted_cities = sorted(cities)

ids = {}
cnt = 1
before = -1
for c in sorted_cities:
    id_ = c//10000000000
    if before != id_:
        before = id_
        cnt = 1
    else:
        cnt += 1
    ids[c] = cnt

[print("{:06}{:06}".format(c//10000000000, ids[c])) for c in cities]
### BUGGY CODE ###

MOD = 10**9+7

def add(a,b):
  return (a+b) % MOD

def sub(a,b):
  return (a-b) % MOD

def mul(a,b):
  return ((a%MOD) * (b%MOD)) % MOD

def pow(a,n):
  ans = 1
  mag = a
  for b in reversed(str(bin(n))):
    if b == 'b': break
    if b == '1':
      ans = mul(ans, mag)
    mag = mul(mag, mag)
  return ans

def inv(a):
  return pow(a, MOD-2)

H,W,A,B = map(int,raw_input().split())

factorical = [1]
factorical_inv = [1]
for n in range (1,H+W+1):
  f = mul(factorical[-1], n)
  factorical.append(f)
  factorical_inv.append(inv(f))

def ncr(n,r):
  return mul(mul(factorical[n], factorical_inv[n-r]), factorical_inv[r])

def paths(w,h):
  return ncr(w+h,w)

ans = 0
for i in range(W-B):
  p = mul(paths(H-A-1, B+i), paths(A-1, W-B-1-i))
  ans = add(ans, p)
print ans


### FIXED CODE ###

MOD = 10**9+7

def add(a,b):
  return (a+b) % MOD

def mul(a,b):
  return (a*b) % MOD

def pow(a,n):
  ans = 1
  mag = a
  for b in reversed(str(bin(n))):
    if b == 'b': break
    if b == '1':
      ans = mul(ans, mag)
    mag = mul(mag, mag)
  return ans

def inv(a):
  return pow(a, MOD-2)

H,W,A,B = map(int,raw_input().split())

factorical = [1]
factorical_inv = [1]
for n in range (1,H+W+1):
  f = mul(factorical[n-1], n)
  factorical.append(f)
  if(n <= max(H,W)):
    factorical_inv.append(inv(f))

def ncr(n,r):
  return mul(mul(factorical[n], factorical_inv[n-r]), factorical_inv[r])

def paths(w,h):
  return ncr(w+h,w)

ans = 0
for i in range(W-B):
  p = mul(paths(H-A-1, B+i), paths(A-1, W-B-1-i))
  ans = add(ans, p)
print ans
### BUGGY CODE ###

if __name__ == '__main__':
    N, A = map(int, input().split())
    x = list(map(int, input().split()))

    x.insert(0, 0)

    dp = [[[0 for _ in range(N * A + 1)] for _ in range(N + 1)] for _ in range(N + 1)]
    for i in range(N + 1):
        dp[i][0][0] = 1

    for i in range(1, N + 1):
        for j in range(1, i + 1):
            for k in range(1, N * A + 1):
                dp[i][j][k] = dp[i - 1][j][k]
                if k >= x[i]:
                    dp[i][j][k] += dp[i - 1][j - 1][k - x[i]]

    ans = 0
    for j in range(1, N + 1):
        ans += dp[N][j][A * j]

    print(ans)


### FIXED CODE ###

if __name__ == '__main__':
    N, A = map(int, input().split())
    x = list(map(int, input().split()))

    x.insert(0, 0)

    dp = [[[0 for _ in range(N * A + 1)] for _ in range(N + 1)] for _ in range(N + 1)]
    for i in range(N + 1):
        dp[i][0][0] = 1

    for i in range(1, N + 1):
        for j in range(1, i + 1):
            for k in range(1, N * A + 1):
                dp[i][j][k] = dp[i - 1][j][k]
                if k >= x[i]:
                    dp[i][j][k] += dp[i - 1][j - 1][k - x[i]]

    ans = 0
    for j in range(1, N + 1):
        ans += dp[N][j][A * j]

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

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

ans = [0 for i in range(n-k+1)]
for i in range(n-k+1):
    for j in range(k):
        ans[i] += (p[i+j]+1)/2

print(max(ans))

### FIXED CODE ###

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

for i in range(n):
    p[i] = (p[i]+1)/2

ans = [0]*(n)
tem = 0
for i in range(n):
    tem = tem
    if i < k:
        tem = tem + p[i]
    else:
        tem = tem + p[i] - p[i-k]
    ans[i] = tem

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

import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
input = sys.stdin.readline
S = input().rstrip()
input()
rev = 0
for line in readlines():
    q, *query, = line.split()
    if q == '1':
        rev ^= 1
    else:
        f, c = query
        if f == '1':
            if not rev:
                S = c+S
            else:
                S = S+c
        else:
            if not rev:
                S = S+c
            else:
                S = c+S

print(S if not rev else S[::-1])


### FIXED CODE ###

def m():
    s = input()
    q = int(input())
    inv = 0
    pre = []
    sub = []

    for i in range(q):
        raw = input().split()
        if len(raw) == 1:
            inv = inv ^ 1
        else:
            f = int(raw[1])-1
            c = raw[2]
            if inv==f:
                pre.append(c)
            else:
                sub.append(c)
    
    if inv==0:
        print(''.join(pre[::-1])+s+''.join(sub))
    else:
        print(''.join(sub[::-1])+s[::-1]+''.join(pre))

m()
### BUGGY CODE ###

N = int(input())
A = list(map(float,input().split()))
K = N//2 + 1
import sys
sys.setrecursionlimit(10000000)


def dfs(i,K):
    if (i,K) in cache: return cache[(i,K)]
    if i>=N: 
        cache[(i,K)] = 1
        return 1
    if len(A[i:]) < K: 
        res = (1-A[i])*dfs(i+1,K)
    elif len(A[i:]) == K: 
        res = A[i]*dfs(i + 1,K-1)
    else:
        res = A[i]*dfs(i+1,K-1) + (1-A[i])*dfs(i+1,K)
    cache[(i,K)] = res
    return res
cache={}
print(dfs(0,K))
            



### FIXED CODE ###

import collections
N = int(input())
A = list(map(float,input().split()))
K = N//2  + 1
dp = [[0 for _ in range(N + 1) ] for _ in range(N + 1)]
if N == 0: 
    print(0)
    exit
dp[0][0] = 1
ans = 0
for i in range(1,N+1):
    for j in range(i+1):
        if j - 1 < 0:
            dp[i][j] = dp[i-1][j]*(1-A[i-1])
        else:
            dp[i][j] = dp[i-1][j-1]*A[i-1] + dp[i-1][j]*(1-A[i-1])
for i in range(K,len(dp[N])):
        ans+=dp[N][i]
print(ans)
### BUGGY CODE ###

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

ans = 0

for x in range(min(a),max(a)+1):
    tmp = 0
    for i in range(N):
        if a[i]+1 == x or a[i] == x or a[i]-1 == x:
            tmp += 1
    
    ans = max(ans,tmp)
    
print(ans)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
 
cnt = [0] * 100010
for a in A:
    if a > 0:
        cnt[a - 1] += 1
    cnt[a] += 1
    cnt[a + 1] += 1

print(max(cnt))
### BUGGY CODE ###

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

### FIXED CODE ###

N = int(input())
X = list(map(int,input().split()))
a = sorted(X)
b = a[N//2]
c = a[(N//2)-1]
for i in X:
    print(b if i<b else c)
### BUGGY CODE ###

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

for l,r in l_r:
    sub_s = s[l-1:r]
    print(len(sub_s.split('AC'))-1)

### FIXED CODE ###

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

memo = [0] * (n+1)


for i in range(n):
    if s[i:i+2] == 'AC':
         memo[i+1] = memo[i] + 1
    else:
         memo[i+1] = memo[i]

for l,r in l_r:
    print(memo[r-1]-memo[l-1])
### BUGGY CODE ###

import numpy as np
X = int(input())

t = np.arange(-1000000, 1000001, 1)
t = t**5
S = set(t)

for B in t**5:
    if X+B**5 in S:
        print("%d %d"%((X+B**5)**0.2, B))
        break


### FIXED CODE ###

import numpy as np
X = int(input())

t = np.arange(0, 2000001, 1)
t = t**5
S = set(t)

for B in range(0,200001,1):
    if X+B**5 in S:
        print("%d %d"%((X+B**5)**0.2, B))
        break
    if X-B**5 in S:
        print("%d %d"%((X-B**5)**0.2, -B))
        break
### BUGGY CODE ###

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


hist = []
for _ in range(M):
    p, s = input().split()

    try:
        hist.index(p+'AC')
    except:
        hist.append(p+s)

ans = ''.join(hist)
ans_ac = ans.count('AC')
ans_wa = ans.count('WA')
print(ans_ac, ans_wa)


### FIXED CODE ###

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

ac = 0
wa = 0

hist_ac = [0] * N
hist_wa = [0] * N
for _ in range(M):
    p, s = input().split()
    p = int(p) - 1
    if hist_ac[p] == 0:
        if s == 'AC':
            hist_ac[p] = 1
            ac += 1
            wa += hist_wa[p]
        else:
            hist_wa[p] += 1

print(ac, wa)
### BUGGY CODE ###

n = int(input())
s = [0] * n
inc = []
zeros = []
dec = []

for i in range(n):
    s[i] = input()
    start = 0
    minimum = 0
    now = 0
    for c in s[i]:
        if c == '(':now += 1
        else: now -= 1
        minimum = min(minimum, now)
    end = now
    
    if end == 0:
        zeros.append((minimum, i))
    elif start < end:
        inc.append((minimum, i))
    else:
        minimum = minimum - end
        dec.append((minimum, i))

inc.sort(reverse=True)
dec.sort()


now = 0
for (m, i) in inc:
    for c in s[i]:
        if c == '(':now += 1
        else: now -= 1
        if now < 0:
            print("No")
            exit()
        
for (m, i) in zeros:
    for c in s[i]:
        if c == '(':now += 1
        else: now -= 1
        if now < 0:
            print("No")
            exit()

for (m, i) in dec:
    for c in s[i]:
        if c == '(':now += 1
        else: now -= 1
        if now < 0:
            print("No")
            exit()

if now != 0:
    print("No")
else:
    print("Yes")

### FIXED CODE ###

n = int(input())
s = [0] * n
inc = [[] for _ in range(1100000)]
zeros = []
dec = [[] for _ in range(1100000)]

for i in range(n):
    s[i] = input()
    start = 0
    minimum = 0
    now = 0
    for c in s[i]:
        if c == '(':now += 1
        else: now -= 1
        minimum = min(minimum, now)
    end = now
    
    if end == 0:
        zeros.append(i)
    elif start < end:
        inc[minimum].append(i)
    else:
        minimum = minimum - end
        dec[minimum].append(i)

now = 0
for m in range(0, -1000000, -1):
    for i in inc[m]:
        for c in s[i]:
            if c == '(':now += 1
            else: now -= 1
            if now < 0:
                print("No")
                exit()
        
for i in zeros:
    for c in s[i]:
        if c == '(':now += 1
        else: now -= 1
        if now < 0:
            print("No")
            exit()
            
for m in range(-1000000, 1):
    for  i in dec[m]:
        for c in s[i]:
            if c == '(':now += 1
            else: now -= 1
            if now < 0:
                print("No")
                exit()
                
if now != 0:
    print("No")
else:
    print("Yes")
### BUGGY CODE ###



def main():
    t = input()
    if t == "1":
        print(1)
        exit(0)
    li = [int(v) for v in input().split(' ')]
    s_li = sorted(li)
    count = 0
    for v in range(s_li[0] - 1, s_li[-1] + 1):
        t_c = 0
        for vv in s_li:
            if v == vv or v - 1 == vv or v + 1 == vv:
                t_c += 1
            if vv > v + 2:
                break
        if t_c > count:
            count = t_c

    print(count)



if __name__ == '__main__':
    main()


### FIXED CODE ###

n = int(input())
cnt = [0] * 100002
a = list(map(int, input().split()))
for v in a:
    cnt[v] += 1
    cnt[v+1] += 1
    cnt[v+2] += 1
    
print(max(cnt))
### BUGGY CODE ###

import numpy as np
def main():
  H, W, D = map(int, input().split())
  num = [[] for _  in range(H*W)]
  for i in range(H):
    temp = list(map(int, input().split()))
    for j in range(len(temp)):
      num[temp[j]-1] = [i, j]
  num = np.array(num)
  Q = int(input())
  for i in range(Q):
    L, R = map(int, input().split())
    print(np.sum(np.abs(num[L+D-1:R+D-1:D]-num[L-1:R-1:D])))
if __name__ == "__main__":
  main()

### FIXED CODE ###

def main():
  H, W, D = map(int, input().split())
  num = [[] for _  in range(H*W)]
  for i in range(H):
    temp = list(map(int, input().split()))
    for j in range(len(temp)):
      num[temp[j]-1] = [i, j]
  #num = np.array(num)
  num_sum = [0]*(H*W)
  for i in range(D, H*W):
    num_sum[i] = num_sum[i-D] + (abs(num[i][0]-num[i-D][0])+ abs(num[i][1]-num[i-D][1]))
  Q = int(input())
  for i in range(Q):
    L, R = map(int, input().split())
    print(num_sum[R-1]-num_sum[L-1])
if __name__ == "__main__":
  main()
### BUGGY CODE ###

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

for _ in range(m):
    b,c = map(int, input().split())
    a.extend([c]*b)

a.sort(reverse=True)
print(sum(a[:n]))


### FIXED CODE ###

n,m = map(int, input().split())
a = sorted(list(map(int,input().split())))
bc = [list(map(int, input().split())) for _ in range(m)]
bc.sort(key=lambda x: x[1], reverse=True )
count = 0
for b,c in bc:
    for _ in range(b):
        if count == n or a[count] >= c:
            break

        a[count] = c
        count += 1

print(sum(a))
### BUGGY CODE ###

import numpy as np

N, A = map(int, input().split())
X = [0] + list(map(int, input().split()))
NX = N * max(X + [A])

dp = np.zeros((N + 1, N + 1, NX + 1), dtype=int)

dp[0][0][0] = 1

for j in range(N + 1):
    for k in range(N + 1):
        for s in range(NX + 1):
            if j >= 1 and s < X[j]:
                dp[j][k][s] = dp[j - 1][k][s]
            elif j >= 1 and k >= 1 and s >= X[j]:
                dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - X[j]]

ret = 0

for k in range(1, N + 1):
    ret += dp[N][k][k * A]

print(ret)


### FIXED CODE ###

import numpy as np

N, A = map(int, input().split())
X = [0] + list(map(int, input().split()))
NX = N * max(X + [A])

dp = np.zeros((N + 1, 2 * NX + 1), dtype=int)

dp[0][NX] = 1

for j in range(1, N + 1):
    y = X[j] - A
    for t in range(2 * NX + 1):
        if 0 <= t - y < 2 * NX:
            dp[j][t] = dp[j - 1][t] + dp[j - 1][t - y]
        else:
            dp[j][t] = dp[j - 1][t]

print(dp[N][NX] - 1)
### BUGGY CODE ###

def gcd(a,b):
    if a < b:
        a, b = b, a
    while b >= 1:
        a, b = b, a % b
    return a

def shave(n):
    n_root = int(n**0.5)
    candidate = [i for i in range(3,n+1,2)]
    for i in range(3,n_root+2,2):
        candidate = [ j for j in candidate if j == i or j % i != 0]   
    candidate = [2] + candidate
    return candidate

x, y = [ int(v) for v in input().split() ]

gcd1 = gcd(x, y)
prime_list = shave(gcd1)

ans = 1
for i in prime_list:
    if gcd1 % i == 0:
        ans += 1
print(ans)

### FIXED CODE ###

def gcd(a,b):
    if a < b:
        a, b = b, a
    while b >= 1:
        a, b = b, a % b
    return a

def shave(n):
    n_root = int(n**0.5)
    candidate = [i for i in range(3,n+1,2)]
    for i in range(3,n_root+2,2):
        candidate = [ j for j in candidate if j == i or j % i != 0]   
    candidate = [2] + candidate
    return candidate

x, y = [ int(v) for v in input().split() ]

gcd1 = gcd(x, y)
prime_list = shave(int(gcd1**0.5)+1)

ans = 1
for i in prime_list:
    if gcd1 % i == 0:
        ans += 1
        while gcd1 % i == 0:
            gcd1 //= i
if gcd1 != 1:
    ans += 1
print(ans)
### BUGGY CODE ###

import numpy as np
N,M=[int(i) for i in input().split()]
a=[]
for j in range(N):
  a.append([int(i) for i in input().split()])
a.sort(key=lambda x:x[0])

cost=0
for j in range(M):
  if a[0][1]==0:
    a.pop(0)
  if a[0][1]>=1:
    a[0][1]-=1
    cost+=a[0][0]
print(cost)

### FIXED CODE ###

import numpy as np
N,M=[int(i) for i in input().split()]
a=[]
for j in range(N):
  a.append([int(i) for i in input().split()])
 
a.sort(key=lambda x:x[0])
 
cost=0
shop=0
for j in range(M):
  if a[shop][1]==0:
    shop+=1
  a[shop][1]-=1
  cost+=a[shop][0]
print(cost)
### BUGGY CODE ###

_num = int(input())
_sumlist = []
for i in range(1, _num + 1):
    _sum = 0
    while i:
        _sum += i % 10
        i //= 10
    _sumlist.append(_sum)
print(max(_sumlist))

### FIXED CODE ###

def digit_num(_num):
    _digit = 0
    while _num:
        _digit += 1
        _num //= 10
    return _digit


_num = int(input())
_digit = digit_num(_num)
_topdig = _num // 10 ** (_digit - 1)
_sumlist = [9 * (_digit - 1)]
if (_num - _topdig * 10 ** (_digit - 1)) == 10 ** (_digit - 1) - 1:
    _sumlist.append(_topdig + 9 * (_digit - 1))
else:
    _sumlist.append(_topdig - 1 + 9 * (_digit - 1))

print(max(_sumlist))
### BUGGY CODE ###

from collections import Counter
N = int(input())
A = list(map(int, input().split()))
B = Counter(A)
for i in range(N):
    B[A[i]] -= 1
    ans = 0
    for n in B.values():
        ans += n*(n-1)//2
    print(ans)
    B[A[i]] += 1

### FIXED CODE ###

from collections import Counter
N = int(input())
A = list(map(int, input().split()))
B = Counter(A)

ans = 0
for i in B.values():
    ans += i*(i-1)//2

for a in A:
    k = B[a]
    print(ans - (k*(k-1)//2)+((k-1)*(k-2)//2))
### BUGGY CODE ###

N,K,Q = [int(x) for x in input().split()]
a = [K]*N
for _ in range(Q):
    ai = int(input())
    for i,aa in enumerate(a):
        if i != ai-1:
            a[i] -= 1

for aa in a:
    if aa > 0:
        print('Yes')
    else:
        print('No')


### FIXED CODE ###

N,K,Q = [int(x) for x in input().split()]
AI = [0]*N
for _ in range(Q):
    ai = int(input())
    AI[ai-1] += 1
sum_a = sum(AI)

for ai in AI:
    if sum_a - ai >= K:
        print('No')
    else:
        print('Yes')
### BUGGY CODE ###

from itertools import product

N = int(input())
added = set()
ans = []
a = [[i for i in range(j)] for j in range(1,N+1)]
for x in product(*a):
    count = 0
    appeared = set()
    temp = []
    order = [float('inf')] * N
    for y in x:
        if y not in appeared:
            order[y] = 97 + count
            count += 1
            appeared.add(y)
            temp.append(chr(order[y]))
        else:
            temp.append(chr(order[y]))
    s = ''.join(temp)
    if s not in added:
        ans.append(s)
        added.add(s)
print('\n'.join(sorted(ans)))

### FIXED CODE ###

def dfs(s,n):
    if len(s) == n:
        print(s)
    else:
        for i in range(len(set(s))+1):
            dfs(''.join([s,chr(97+i)]),n)

N = int(input())
dfs('a',N)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
#A=[1,1,1,1,1,1,1]
#N=7
A.sort(reverse=True)
L=[]
dis=[A[0]]
L.append(A[0])
L.append(A[0])
#print(L)
num=0
for i in range(1,len(A)):
    ind=dis.index(max(dis))
    num+=dis[ind]
    L.insert(ind+1,A[i])
    del dis[ind]
    dis[ind:ind]=[A[i],A[i]]
print(num)
#print(L)
#print(dis)

### FIXED CODE ###

from collections import deque
N = int(input())
A = list(map(int, input().split()))
#A=[1,1,1,1,1,1,1]
#N=7
A.sort(reverse=True)
dis=deque([A[0]])
num=0
for i in range(1,len(A)):
    num+=dis.popleft()
    #L.insert(ind+1,A[i])
    dis.append(A[i])
    dis.append(A[i])
print(num)
#print(L)
#print(dis)