Harryxun/stf_run huggingface dataset:
INF = 10**10
arr = [INF,2,5,5,4,5,6,3,7,6]
N,M = map(int,input().split())
src = sorted(list(map(int,input().split())))

dp = [-INF]*(N+1)
dp[0] = 0
for i in range(N):
    for j in src:
        if i + arr[j] <= N:
            dp[i + arr[j]] = max(dp[i + arr[j]], dp[i] + 1)
ans = ''
dim = dp[N]
while(dim > 0):
    for i in src[::-1]:
        if dp[N-arr[i]] == dp[N] - 1:
            ans += str(i)
            N -= arr[i]
            dim -= 1
            break
print(0)

### FIXED CODE ###

INF = 10**10
arr = [INF,2,5,5,4,5,6,3,7,6]
N,M = map(int,input().split())
src = sorted(list(map(int,input().split())))

dp = [-INF]*(N+1)
dp[0] = 0
for i in range(N):
    for j in src:
        if i + arr[j] <= N:
            dp[i+arr[j]] = max(dp[i+arr[j]],dp[i] + 1)
dim = dp[N]
ans  = ''
while(dim > 0):
    for i in src[::-1]:
        if N >= arr[i] and dp[N-arr[i]] + 1 == dp[N]:
            ans += str(i)
            N -= arr[i]
            dim -= 1
            break
print(ans)
n = list(map(int,input().split()))
if sum(n)/9 == sum(n)//9:
	print("Yes")
else:
	print("No")


### FIXED CODE ###

n = list(map(int,input()))
if sum(n)/9 == sum(n)//9:
	print("Yes")
else:
	print("No")
a, b, c = input().split()
print(f'{c},{a},{b}')


### FIXED CODE ###

a, b, c = input().split()
print(c, a, b)
from bisect import bisect_left, bisect_right, insort_left, insort_right


def solve():
    x = int(input())
    cumulative_sum = [(k * (k - 1)) // 2 for k in range(1, 46)]
    target = bisect_left(cumulative_sum, x)
    if x in cumulative_sum:
        print(cumulative_sum.index(x))
    else:
        print(target - 2 + (x - cumulative_sum[target - 1] + 1))


solve()

### FIXED CODE ###

def solve():
    a, b = list(map(str, input().split(" ")))

    if a == b:
        print("H")
    else:
        print("D")


solve()
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
if a[m] * 4 * m >= sum(a):
    print('Yes')
else:
    print('No')


### FIXED CODE ###

n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
if a[m - 1] * 4 * m >= sum(a):
    print('Yes')
else:
    print('No')
import sys
N, Q = [int(i) for i in input().split()]
tree = {i:[] for i in range(1,N+1)}
cost_ls = {i:0 for i in range(1,N+1)}
for i in range(N-1):
    a, b = [int(j) for j in sys.stdin.readline().split()]
    tree[a].append(b)
    tree[b].append(a)

yet = set()
def plus(node, _from):
    yet.add(node)
    #cost_ls[node] += num
    for child in tree[node]:
        if child == _from:
            continue
        cost_ls[child] += cost_ls[node]
        plus(child, node)

for i in range(Q):
    p, x = [int(j) for j in sys.stdin.readline().split()]
    cost_ls[p] += x

plus(1, 0)

print(" ".join([str(cost) for cost in cost_ls.values()]))

### FIXED CODE ###

import sys

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

N, Q = map(int, input().split())
V = {i: [] for i in range(1, N + 1)}
for _ in range(N - 1):
    a, b = map(int, input().split())
    V[a].append(b)
    V[b].append(a)

C = {i: 0 for i in range(1, N + 1)}

for _ in range(Q):
    p, x = map(int, input().split())
    C[p] += x


def propagate(u, p):
    for v in V[u]:
        if v == p:
            continue
        C[v] += C[u]
        propagate(v, u)


propagate(1, 0)

print(' '.join(str(C[i]) for i in range(1, N + 1)))
import numpy as np


def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]


X, Y = map(int, input().split())
list = list(map(int, input().split()))
list = sorted(list)


listHandred = []
for i in range(0,102):
    listHandred.append(i)
    
ansList = listHandred

for i in list:
    if i in ansList:
        ansList.remove(i)

print(getNearestValue(ansList,X))


### FIXED CODE ###

print(list(map(int,input().split())).index(0)+1)
s=list(input())
if s[3]==s[4] and s[5] == s[6]:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

s=list(input())
if s[2]==s[3] and s[4] == s[5]:
  print("Yes")
else:
  print("No")
N, Q, *D = map(int, open(0).read().split())
val = [0 for _ in range(N+1)]
E = [[] for _ in range(N+1)]
for i in range(N-1):
  l, r = D[2*i], D[2*i+1]
  E[l].append(r)
  E[r].append(l)
D = D[-2*Q:]
for i in range(Q):
  l, r = D[2*i], D[2*i+1]
  val[l] += r
visited = [False for _ in range(N+1)]
def dfs(c):
  visited[c] = True
  for ch in E[c]:
    if not visited[ch]:
      val[ch] += val[c]
      dfs(ch)
dfs(1)
print(' '.join(map(str, val[1:])))

### FIXED CODE ###

import sys
sys.setrecursionlimit(500000)
N, Q, *D = map(int, open(0).read().split())
val = [0 for _ in range(N+1)]
E = [[] for _ in range(N+1)]
D = list(zip(*[iter(D)]*2))
assert(len(D) == N+Q-1)
for i in range(N+Q-1):
  l, r = D[i][0], D[i][1]
  if i < N - 1:
  	E[l].append(r)
  	E[r].append(l)
  else:
    val[l] += r
visited = [False for _ in range(N+1)]
def dfs(c):
  visited[c] = True
  for ch in E[c]:
    if not visited[ch]:
      val[ch] += val[c]
      dfs(ch)
dfs(1)
print(' '.join(map(str, val[1:N+1])))
import heapq

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

for i in range(N):
    a,b = list(map(int,input().split()))
    A[a-1].append(-b)
    
ans = 0
cand = []

for i in range(M):
    
    for j in A[i]:
        cand.append(j)
        
    if cand:
        heapq.heapify(cand)
        ans -= heapq.heappop(cand)
    
print(ans)

### FIXED CODE ###

import heapq

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

for i in range(N):
    a, b = list(map(int,input().split()))
    if a <= M:
        A[a-1].append(-b)
    
ans = 0
cand = []

for i in range(M):
    
    for j in A[i]:
        heapq.heappush(cand, j)
        
    if cand:
        ans -= heapq.heappop(cand)
    
print(ans)
N = int(input())
otoshidama = []
otoshidama_sum = 0
for i in range(N):
    otoshidama.append(input().split())
for i in range(N):
    otoshidama[i][0] = int(otoshidama[i][0])
    if otoshidama[i][1] == 'BTC':
        otoshidama[i][0] = otoshidama[i][0]*380000
    otoshidama_sum += otoshidama[i][0]
print(otoshidama_sum)

### FIXED CODE ###

N = int(input())
otoshidama = []
otoshidama_sum = 0
for i in range(N):
    otoshidama.append(input().split())
for i in range(N):
    otoshidama[i][0] = float(otoshidama[i][0])
    if otoshidama[i][1] == 'BTC':
        otoshidama[i][0] = otoshidama[i][0]*380000
    otoshidama_sum += otoshidama[i][0]
print(otoshidama_sum)
import math

n = int(input())
s = int(input())
ans = -1

def func(b, n):
    if n < b:
        return n
    else:
        return func(b, n//b) + n%b

if n < s:
    ans = -1
elif n == s:
    ans = n+1
else:
    for b in range(2,int(math.sqrt(n))):
      if func(b, n) == s:
          ans = b
          break

    if ans == -1:
        for p in range(1,int(math.sqrt(n))):
            if func((n-s)/p+1, n) == s:
                ans = int((n-s)/p+1)
print(ans)

### FIXED CODE ###

import math

n = int(input())
s = int(input())
ans = -1

def func(b, n):
    if n < b:
        return n
    else:
        return func(b, n//b) + n%b

if n < s:
    ans = -1
elif n == s:
    ans = n+1
else:
    for b in range(2,int(math.sqrt(n))+1):
      if func(b, n) == s:
          ans = b
          break

    if ans == -1:
        for p in range(1,int(math.sqrt(n))+1):
            b = int((n-s)/p+1)
            if b >= 2 and func(b, n) == s:
                ans = b
print(ans)
N,  K=map(int, input(), split())
if N%K==0:
	print(0)
else:
	print(1)


### FIXED CODE ###

N, K=map(int, input(). split())
if N%K==0:
	print(0)
else:
	print(1)
from sys import stdin
import numpy as np

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

S = np.zeros((N, N))
T = np.zeros(N)
for n in range(N):
    if n < N - 1:
        S[n][n] = 1
        S[n][n + 1] = 1
        T[n] = A[n] * 2
    else:
        S[n][n] = 1
        S[n][0] = 1
        T[n] = A[n] * 2

X = np.linalg.solve(S, T)
for x in X:
    print(int(x), end=" ")


### FIXED CODE ###

from sys import stdin

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

S = sum(A)
ans = [0 for _ in range(N)]
s = 0
for k in range(int((N - 1) / 2)):
    s += A[2 * k + 1] * 2
ans[0] = S - s
for k in range(1, N):
    ans[k] = A[k - 1] * 2 - ans[k - 1]
print(*ans)
if __name__ == '__main__':
  a,b,c = map(int, input().spilt())
  if(a>b):
    a,b = b,a
  if(c > a and c < b):
    print("Yes")
  else:
    print("No")

### FIXED CODE ###

if __name__ == '__main__':
  a,b,c = map(int, input().split())
  if(a>b):
    a,b = b,a
  if(c > a and c < b):
    print("Yes")
  else:
    print("No")
print(int(((T+0.5)//A)*B))

### FIXED CODE ###

A,B,T = map(int,input().split())
print(int(((T+0.5)//A)*B))
N, Q = map(int, input().split())
tree = [[] for _ in range(N)]
 
for _ in range(N-1):
    a, b = map(int, input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)
 
X = [0]*N
for _ in range(Q):
    p, x = map(int, input().split())
    X[p-1] += x
 
ans = [0]*N
 
def dfs(u, parent=None):
    ans[u] = ans[parent] + X[u]
    for v in tree[u]:
        if v != parent:
            dfs(v, u)
 
dfs(0, 0)
print(' '.join([str(i) for i in ans]))

### FIXED CODE ###

from collections import deque
import sys
input = sys.stdin.readline
 
 
def main():
    n, q = map(int, input().split())
    node = [[]for _ in range(n)]
    looked = [1] * n
    for i in range(n - 1):
        a, b = map(int, input().split())
        node[b - 1].append(a - 1)
        node[a - 1].append(b - 1)
    counter = [0] * n
    for i in range(q):
        p, x = map(int, input().split())
        counter[p - 1] += x
    queue = deque([0])
    looked[0] = 0
    while queue:
        now = queue.pop()
        for i in node[now]:
            if looked[i]:
                queue.append(i)
                counter[i] += counter[now]
                looked[i] = 0
    print(*counter)
 
main()
N,K=map(int,input().split())
h_i=(int(x) for x in input().split())
count=0
for i in range(N):
  if h_i[i] >= K:
    count+=1
print(count)

### FIXED CODE ###

N,K=map(int,input().split())
h_i=list(int(x) for x in input().split())
count=0

for i in range(N):
  if h_i[i] >= K:
    count+=1
print(count)
n = int(input())
spade = hart = club = diamond = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}
trump = [spade, hart, club, diamond]
suit_def = ['S', 'H', 'C', 'D']

for i in range(n):
    card = list(input().split())
    suit = card[0]
    number = int(card[1])
    if suit == 'S':
        spade.remove(number)
    elif suit == 'H':
        hart.remove(number)
    elif suit == 'C':
        club.remove(number)
    elif suit == 'D':
        diamond.remove(number)

for i, j in zip(trump, suit_def):
    for k in i:
        print(j, k)

### FIXED CODE ###

n = int(input())
spade = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}
hart = set(spade)
club = set(spade)
diamond = set(spade)
trump = [spade, hart, club, diamond]
suit_def = ['S', 'H', 'C', 'D']

for i in range(n):
    card = list(input().split())
    suit = card[0]
    number = int(card[1])
    if suit == 'S':
        spade.remove(number)
    elif suit == 'H':
        hart.remove(number)
    elif suit == 'C':
        club.remove(number)
    else:
        diamond.remove(number)

for i, j in zip(trump, suit_def):
    for k in i:
        print(j, k)
N = int(raw_input())

for i in range(N):
    line = raw_input()
    a, b, c = sorted(int(i) for i in line.split())

    if a**2 + b**2 == c**2:
        print('YES')
    else:
        print('NO')

### FIXED CODE ###

N = int(input())

for i in range(N):
    line = input()
    a, b, c = sorted(int(w) for w in line.split())

    if a**2 + b**2 == c**2:
        print('YES')
    else:
        print('NO')
import numpy as np

N = int(input())
# P = np.array(input().split(' '), dtype = int)
P = np.array(list(map(int, input().split(' '))))

# print(N - sum([np.any(P[:i+1] < P[i]) for i in range(N)]))
for i in range(N):
    N -= np.any(P < P.reshape(-1,1))[i][:i+1]
print(N)

### FIXED CODE ###

N = int(input())
# P = np.array(input().split(' '), dtype = int)
P = list(map(int, input().split(' ')))

p_min = P[0]
ans = 0
for p in P:
    if p <= p_min:
        p_min = p
        ans += 1
print(ans)
N, A, B = map(int, input().split())

counter = [0 for _ in range(N)]
ans = 0

for i in range(N):
    string = str(i)
    for j in range(len(string)):
        counter[i] += string[j]

for i in range(N):
    if(counter[i]<=B and counter[i]>=A):
        ans += i

print(ans)

### FIXED CODE ###

N, A, B = map(int, input().split())
ans = 0

for i in range(1, N+1):
    num_sum = 0
    for j in str(i):
        num_sum += int(j)
    if A<= num_sum <= B:
        ans += i

print(ans)
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
S = list(input())
ls =[]
count = 0
for i in len(S):
    
    if S[i] in 'ATGC':
        count += 1
    else:
        ls.append(count)
        count = 0

print(max(ls))



### FIXED CODE ###

#! /usr/bin/env python3
# -*- coding: utf-8 -*-
S = list(input())
clst=[]
count = 0
for s in S:
    if s == 'A' or s == 'T' or s =='C' or s == 'G':
        count += 1
        clst.append(count)
    else:
        
        count = 0
        clst.append(count)
print(max(clst))
A, B, C, D, E, F = map(int, input().split())
con = 0
sugar = 0
for a in range(int(F / 100 / A) + 1):
    for b in range(int((F - a * 100 * A)/ 100 / B) + 1):
        if not a == b == 0:
            for c in range(int((a*A+b*B)*E/C)+1):
                for d in range(int(((a*A+b*B)*E-c*C)/D)+1):
                    if 100*(A*a+B*b)+C*c+D*d <= F:
                        if con < 100*((c*C+d*D)/(100*a*A+100*b*B+c*C+d*D)):
                            con = 100*((c*C+d*D)/(100*a*A+100*b*B+c*C+d*D))
                            sugar = c*C+d*D
                            water = 100*a*A+100*b*B+c*C+d*D
print(water, sugar)

### FIXED CODE ###

A, B, C, D, E, F = map(int, input().split())
con = 0
sugar_water = 0
sugar = 0
for a in range(int(F / 100 / A) + 1):
    for b in range(int((F - a * 100 * A)/ 100 / B) + 1):
        if not a == b == 0:
            for c in range(int((a*A+b*B)*E/C)+1):
                for d in range(int(((a*A+b*B)*E-c*C)/D)+1):
                    if 100*(A*a+B*b)+C*c+D*d <= F:
                        if con <= 100*((c*C+d*D)/(100*a*A+100*b*B+c*C+d*D)):
                            con = 100*((c*C+d*D)/(100*a*A+100*b*B+c*C+d*D))
                            sugar = c*C+d*D
                            sugar_water = 100*a*A+100*b*B+c*C+d*D
print(sugar_water, sugar)
S = input()
T = input()
count = 0
for n inrange(3):
  if S[n] = T[n]:
    count += 1
print(count)


### FIXED CODE ###

S = input()
T = input()
count = 0
for n in range(3):
  if S[n] == T[n]:
    count += 1
print(count)
import math

def lcm(x,y):
    return (x*y)//math.gcd(x,y)

a,b,c,d=map(int,input().split())
d1=math.floor(b/c)
d2=math.floor(b/d)
d3=math.floor(b/lcm(c,d))

d4=math.floor((a-1)/c)
d5=math.floor((a-1)/d)
d6=math.floor((a-1)/lcm(c,d))

ansb=b-(d1+d2-d3)
ansa=a-1-(d1+d2-d3)
print(ansb-ansa)

### FIXED CODE ###

import fractions

def lcm(x,y):
    return (x*y)//fractions.gcd(x,y)

a,b,c,d=map(int,input().split())
d1=b//c
d2=b//d
d3=b//lcm(c,d)

d4=(a-1)//c
d5=(a-1)//d
d6=(a-1)//lcm(c,d)

ansb=b-(d1+d2-d3)
ansa=a-1-(d4+d5-d6)
print(ansb-ansa)
from collections import deque

H,W = map(int, input().split())
A = [input()+'.' for _ in range(H)]
A.append('.'*(W+1))

total = sum([1 for a in A for s in a  if s=='#'])

que = deque([[0,0,1]])
while que:
    for x,y in [(1,0), (0,1)]:
        x_,y_,cnt = que.popleft()
        next_x, next_y = x_+x, y_+y
        if A[next_y][next_x] == '#':
            que.append([next_x,next_y,cnt+1])

print('Possible' if total == cnt else 'Impossible')

### FIXED CODE ###

H,W = map(int, input().split())
A = [input() for _ in range(H)]

total = sum([1 for a in A for s in a  if s=='#'])   
print('Possible' if total == W+H-1 else 'Impossible')
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, string, copy
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7
ans = inf
count = 0; pro = 1

d, g = map(int, input().split())
g //= 100
dp=[[inf]*11 for i in range(10**5+1010)]
dp[0][0]=0
for i in range(d):
    p,c=map(int,input().split());c//=100
    for j in range(10**5+1010):
        if dp[i][j]!=inf:
            dp[i+1][j]=min(dp[i+1][j],dp[i][j])
            for k in range(1,p):
                dp[i+1][j+(i+1)*k]=min(dp[i+1][j+(i+1)*k],dp[i][j]+k)
            dp[i+1][j+(i+1)*p+c] = min(dp[i+1][j+(i+1)*p+c],dp[i][j]+p)
for i in range(g,10**5+10):
    ans=min(ans,dp[10][i])
print(ans)




# for i in range(1, d+1):
#     p, c = map(int, input().split())
#     c //= 100
#     # for key, value in tuple(D.items()):
#     #     print(D[key],p)
#     #     D[key+i*p+c//100] = min(D[key+i*p+c//100], D[key]+p)
#     S = D.copy()
#     for key, value in S.items():
#         for k in range(1, p):
#             # print(D[key+i])
#             D[key+i*k] = min(D[key+i*k], S[key]+k)
#         D[key+i*p+c] = min(D[key+i*p+c], S[key]+p)
# ans = inf
# for key, value in D.items():
#     # print(key,value)
#     if key >= g:
#         ans = min(ans, value)
# print(ans)


### FIXED CODE ###

#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, string, copy
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7
ans = count = 0; pro = 1

d,g=map(int,input().split());g//=100
D=collections.defaultdict(lambda: inf )
D[0]=0
for i in range(1,d+1):
    p,c=map(int,input().split());c//=100
    # for key, value in tuple(D.items()):
    #     print(D[key],p)
    #     D[key+i*p+c//100] = min(D[key+i*p+c//100], D[key]+p)
    S=D.copy()
    for key,value in S.items():
        for k in range(1,p):    
        # print(D[key+i])
            D[key+i*k] = min(D[key+i*k],S[key]+k)
        D[key+i*p+c] = min(D[key+i*p+c],S[key]+p)
ans=inf
for key,value in D.items():
    # print(key,value)
    if key>=g:
        ans=min(ans,value)
print(ans)
N,M = map(int,input().split())
data = [list(map(int,input().split())) for i in range(M)]

A = [[] for i in range(3)]

for i in range(M):
    if data[i][0] == 1 and data[i][1] == 0:
        print(-1)
        exit()
    else:
        A[data[i][0]-1].append(data[i][1])

for i in range(N):
    A[i] = set(A[i])
    if len(A[i]) > 1:
        print(-1)
        exit()

B = []
for i in range(N):
    if len(A[i]) == 1:
        for s in A[i]:
            B.append(s)
    else:
        B.append(0)

ans = str(B[0])
for i in range(1,3):
    ans += str(B[i])

print(ans)

### FIXED CODE ###

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

A = [[] for i in range(3)]

for i in range(M):
    if data[i][0] == 1 and data[i][1] == 0 and N != 1:
        print(-1)
        exit()
    else:
        A[data[i][0]-1].append(data[i][1])

for i in range(N):
    A[i] = set(A[i])
    if len(A[i]) > 1:
        print(-1)
        exit()

B = []
for i in range(N):
    if len(A[i]) == 1:
        for s in A[i]:
            if i == 0 and s == 0 and N != 1:
                B.append(1)
            else:
                B.append(s)
    else:
        if i == 0 and N != 1:
            B.append(1)
        else:
            B.append(0)

ans = str(B[0])
for i in range(1,N):
    ans += str(B[i])

print(ans)
N = int(input())
A = [input() for i in range(N)]
count = 0 
can = True
while can:
  count += 1
  for i in range(N):
    if A[i]%2 == 0:
      A[i] = int(A[i]/2)
    else:
      count-=0
      can = False
      break
print(count)


### FIXED CODE ###

N = int(input())
A = [int(i) for i in input().split()]
en = 0
con = True
while con :
	en += 1
	for i in range(N) :
		if A[i] % 2 == 0 :
			A[i] = int( A[i] / 2 ) 
		else :
			en -= 1
			con = False
			break
print(en)
S=int(input())

h=S/3600

m=S%3600/60

s=S%3600%60

print(h:m:s)

### FIXED CODE ###

S=int(input())
 
h=S//3600
 
m=(S%3600)//60
 
s=(S%3600)%60
 
print('{0}:{1}:{2}'.format(h,m,s))
N, Q = map(int, input().split())
S = input()
lr = [list(map(int, input().split())) for _ in range(N)]

for lr_ in lr:
    l, r = lr_[0], lr_[1]
    
    print(S[l - 1: r].count('AC'))

### FIXED CODE ###

n, q = map(int, input().split())
s = input()
dp = [0 for _ in range(len(s))]

for i in range(1, len(s)):
    if(s[i-1: i+1] == 'AC'): dp[i] = dp[i-1] + 1
    else: dp[i] = dp[i-1]

for _ in range(q):
    l, r = map(int, input().split())
    print(dp[r-1] - dp[l-1])
from operator import itemgetter
N,M=map(int,input().split())
A=list(map(int,input().split()))
BC=[list(map(int,input().split())) for _ in range(M)]
A=sorted(A)
sum=0
BC.sort(key=itemgetter(1),reverse=True)

for a in A:
    sum+=a

i=0
for j in range(M):
    for k in range(BC[j][0]):
        if BC[j][1]>A[i] and i<=N:
            sum+=BC[j][1]-A[i]
            i+=1
        else:
            break

print(sum)

### FIXED CODE ###


from operator import itemgetter
N,M=map(int,input().split())
A=list(map(int,input().split()))
BC=[list(map(int,input().split())) for _ in range(M)]
A=sorted(A)
sum=0
BC.sort(key=itemgetter(1),reverse=True)

for a in A:
    sum+=a

i=0
#print(BC)

for j in range(M):
    #print(j)
    for k in range(BC[j][0]):
        if i<=N-1 and BC[j][1]>A[i]:
            sum+=BC[j][1]-A[i]
            i+=1
        else:
            break


print(sum)
from itertools import*
x,y,z,k=map(int,input().split())
a=map(int,input().split())
b=map(int,input().split())
c=map(int,input().split())
#print(a,b,c)
for e in sorted(sum(i)for i in product(a,b,c))[::-1][:k]:
    print(e)

### FIXED CODE ###

from itertools import*
a,b,c,d,e,k=map(int,open(0).read().split())
x=[a,b,c,d,e]
for i in combinations(x,2):
    p,q=list(i)
    if abs(p-q)>k:
        print(":(")
        exit()
print("Yay!")
N = int(input())
c = list(input())

r = c.count("R")
rs = c[:r]
rsr = rs.count("R")
a = r-rsr

w = list(reversed(c)).index("R")
w = (N - 1) - w
ws = c[:w]
b = ws.count("W")

print(min(a,b))




### FIXED CODE ###

import sys

N = int(input())
c = list(input())

r = c.count("R")
if r == 0 :
    print(0)
    sys.exit()   
rs = c[:r]
rsw = rs.count("W")
a = rsw

w = list(reversed(c)).index("R")
w = (N - 1) - w
ws = c[:w]
b = ws.count("W")
print(min(a,b))
a,b,c,d = list(map(int,input().split()))
if c<=a<=d<=b:
    print(d-a)
elif c<=a<=b<=d:
    print(b-a)
elif a<=c<=d<=b:
    pirnt(d-c)
elif a<=c<=b<=d:
    print(b-c)
else:
    print(0)

### FIXED CODE ###

a,b,c,d = list(map(int,input().split()))
if c<=a<=d<=b:
    print(d-a)
elif c<=a<=b<=d:
    print(b-a)
elif a<=c<=d<=b:
    print(d-c)
elif a<=c<=b<=d:
    print(b-c)
else:
    print(0)
def checkTriangle(a, b, c):
    if a + b > c and a + c > b and b + c > a:
        return True
    return False


def checkOct(a, b, c):
    a, b, c = [i * i for i in [a, b, c]]
    if a + b == c or a + c == b or b + c == a:
        return 0
    elif c < a + b or b < a + c or a < b + c:
        return 1
    else:
        return 2

for i in range(5):
    #a, b, c = map(int, input())
    result = [0] * 3
    if checkTriangle(a, b, c):
        result[checkOct(a, b, c)] += 1
print(sum(result),*result)


### FIXED CODE ###

result = [0]*3
while True:
    a, b, c = sorted(map(int, input().split()))
    if a + b <= c:
        print(sum(result),*result)
        break
    flag = a ** 2 + b ** 2 - c*c
    if flag == 0:
        result[0] +=1
    elif flag >0:
        result[1] += 1
    else:
        result[2] += 1
N,M=map(int,input().split())


ac = 0
wa = 0
aclist = {}
walist = {}

count_WA=0
for i in range(n):
    aclist[i + 1] = 0
    walist[i + 1] = 0

for i in range(M):
    a,b=input().split()
    a=int(a)
    if aclist[a] == 1:
        continue
    elif b == 'WA':
        walist[a] += 1
    elif b == 'AC':
        aclist[a] += 1
        ac += 1
        wa += walist[a]




print(ac,wa,sep=" ")


### FIXED CODE ###

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


ac = 0
wa = 0
aclist = {}
walist = {}

count_WA=0
for i in range(N):
    aclist[i + 1] = 0
    walist[i + 1] = 0

for i in range(M):
    a,b=input().split()
    a=int(a)
    if aclist[a] == 1:
        continue
    elif b == 'WA':
        walist[a] += 1
    elif b == 'AC':
        aclist[a] += 1
        ac += 1
        wa += walist[a]




print(ac,wa,sep=" ")