Harryxun/stf_run huggingface dataset:
D=int(input())
C=list(map(int,input().split()))
import sys
S=sys.stdin.readlines()
A=[0]*26
B=[0]*D
k=0
for i in range(26):
  k+=1/C[i]
for i in range(26):
  if i<25:
    A[i]=int(1/C[i]/k*365)
  else:
    A[i]=365-sum(A[:25])

for i in range(25):
  for j in range(A[i]):
    B[D//A[i]*j]=i+1

for i in range(D):
  if B[i]==0:
    B[i]=26

for i in range(D):
  print(B[i])

### FIXED CODE ###

D=int(input())
C=list(map(int,input().split()))
import sys
S=sys.stdin.readlines()
A=[0]*26
B=[0]*D
k=0
for i in range(26):
  if C[i]!=0:
    k+=C[i]
for i in range(26):
  if i<25:
    A[i]=int(C[i]/k*D)
  else:
    A[i]=D-sum(A[:25])

for i in range(25):
  for j in range(A[i]):
    B[D//A[i]*j]=i+1

for i in range(D):
  if B[i]==0:
    B[i]=26


for i in range(D):
  print(B[i])
while True:
    num = int(raw_input())
    if num == 0:
        break
    else:
        numbers.append(num)

for case, num in enumerate(numbers):
    print "Case %s: %s" %(case + 1, num)

### FIXED CODE ###

numbers = []

while True:
    num = int(raw_input())
    if num == 0:
        break
    else:
        numbers.append(num)

for case, num in enumerate(numbers):
    print "Case %s: %s" %(case + 1, num)
a = int(input())
b = int(input())
c = int(input())
  
print(a,b,c)

a = a + b + c    
b = a - (b+c)    
c = a - (b+c) 
a = a - (b+c) 
print(a,b,c)

### FIXED CODE ###

a,b,c = map(int, input().split())
print(c,a,b)
n,m = map(int,input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]
for i in range(m):
  for j in range(m):
    if a[i][j] == b[i][j]:
      pass
    else:
      a = []
if a == []:
  print('No')
else:
  print('Yes')

### FIXED CODE ###

n,m = map(int,input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]
for i in range(n-m+1):
  for j in range(n-m+1):
    count = 0
    for x in range(m):
      for y in range(m):
        if b[x][y]!=a[i+x][j+y]:
          break
        else:
          count += 1
    if count == m**2:
      print('Yes')
      exit()
print('No')
A,B,X=map(int,input().split())
X=min(10**9,((X-B)//A)+1)
for  i in range(X):
  d=len(str(X-i))
  if A*(X-i)+B*d<=X:
    ans=X-i
    break
  if i==X-1:
    ans=0
print(ans)


### FIXED CODE ###

S=str(input())
list=["SUN","MON","TUE","WED","THU","FRI","SAT"]
for i in range(7):
  if S==list[i]:
    print(7-i)
N = int(input())
 
count = 0
for a in range(1, N):
    ans, mod = divmod(N, a)
    if mod == 0:
        count += ans - 1
    else:
        count += ans
 
print(count)

### FIXED CODE ###

a = input()

if a[-1] == "s":
    print(a + "es")
else:
    print(a + "s")
n=int(input())
x=[0 for i in range(10)]
while True:
  if n==0:
    break
  for i in range(n):
    a=int(input())
    if a==0:
      x[0]+=1
    elif a==1:
      x[1]+=1
    elif a==2:
      x[2]+=1
    elif a==3:
      x[3]+=1
    elif a==4:
      x[4]+=1
    elif a==5:
      x[5]+=1 
    elif a==6:
      x[6]+=1
    elif a==7:
      x[7]+=1
    elif a==8:
      x[8]+=1
    else:
      x[9]+=1
  for i in range(10):
    if x[i]==0:
      print('{}'.format('-')) 
    else:
      print('{}'.format(x[i]*'*'))


### FIXED CODE ###

while 1:
  n = int(input())
  if n == 0:
    break
  x = [0 for i in range(10)] 
  for i in range(n):
    c = int(input())
    x[c] += 1

  for i in range(10):
    count = '*' * x[i] 
    if len(count) == 0:
      print("-")
    else:
      print(count)
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

S = sys.stdin.buffer.readline().decode().rstrip()
X, Y = list(map(int, sys.stdin.buffer.readline().split()))

# X 軸と Y 軸は独立に考えられる。
d = 0
cnt = 0
xy = [[], []]
for c in S:
    if c == 'F':
        cnt += 1
    else:
        xy[d].append(cnt)
        cnt = 0
        d = d + 1 & 1
xy[d].append(cnt)
X -= xy[0].pop(0)


def can_make(moves, obj):
    obj = 1 << (8000 + obj)
    dp = 1 << 8000
    for mv in moves:
        if mv == 0:
            continue
        dp = (dp << mv) | (dp >> mv)
    return (dp & obj) > 0


ok = can_make(xy[0], X) and can_make(xy[1], Y)
if ok:
    print('Yes')
else:
    print('No')


### FIXED CODE ###

import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

S = sys.stdin.buffer.readline().decode().rstrip()
X, Y = list(map(int, sys.stdin.buffer.readline().split()))

# X 軸と Y 軸は独立に考えられる。
d = 0
cnt = 0
xy = [[], []]
for c in S:
    if c == 'F':
        cnt += 1
    else:
        xy[d].append(cnt)
        cnt = 0
        d = d + 1 & 1
xy[d].append(cnt)
X -= xy[0].pop(0)


def can_make(moves, obj):
    if obj < -8000:
        return False
    obj = 1 << (8000 + obj)
    dp = 1 << 8000
    for mv in moves:
        if mv == 0:
            continue
        dp = (dp << mv) | (dp >> mv)
    return (dp & obj) > 0


ok = can_make(xy[0], X) and can_make(xy[1], Y)
if ok:
    print('Yes')
else:
    print('No')
n,k=map(int, input().split())
print (n-(k-1))

### FIXED CODE ###

n,k=map(int, input().split())
print (n-(k-1))
import sys
sys.setrecursionlimit=10**12

def modinv(a,m=10**9+7):
    if a==0: return 1
    else:
        b=m
        (x, lastx) = (0, 1)
        (y, lasty) = (1, 0)
        while b != 0:
            q = a // b
            (a, b) = (b, a % b)
            (x, lastx) = (lastx - q * x, x)
            (y, lasty) = (lasty - q * y, y)
        return lastx % m

def cur(p):
        for x in neighbor[p]:
            if x==par[p]: continue
            par[x]=p
            descend[p]+=cur(x)
        try:
            return descend[p]
        except: print(0);sys.exit()


def cur2(p):
    for x in neighbor[p]:
        if x==par[p]: continue
        ans[x]=ans[p]*descend[x]*modinv(n-descend[x])
        ans[x]%=mod
        cur2(x)

mod=10**9+7
n=int(input())
neighbor=[[]  for _ in range(n+1)]
descend=[1]*(n+1)
par=[1]+[0]*(n)

for _ in range(n-1):
    a,b=map(int,input().split())
    neighbor[a].append(b)
    neighbor[b].append(a)
cur(1)

ans=[1]*(n+1)
ans1=1
for i in range(1,n+1):
    ans1=ans1*i*modinv(descend[i])
    ans1%=mod
ans[1]=ans1

cur2(1)

for i in range(1,n+1):
    print(ans[i])

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)

def modinv(a,m=10**9+7):
    if a==0: return 1
    else:
        b=m
        (x, lastx) = (0, 1)
        (y, lasty) = (1, 0)
        while b != 0:
            q = a // b
            (a, b) = (b, a % b)
            (x, lastx) = (lastx - q * x, x)
            (y, lasty) = (lasty - q * y, y)
        return lastx % m

def cur(p):
    if neighbor[p]==[]: return
    for x in neighbor[p]:
        par[x]=p
        neighbor[x].remove(p)
        cur(x)
    descend[par[p]]+=descend[p]

def cur2(p):
    for x in neighbor[p]:
        ans[x]=ans[p]*descend[x]*modinv(n-descend[x])
        ans[x]%=mod
        cur2(x)

mod=10**9+7
n=int(input())
neighbor=[set()  for _ in range(n+2)]
descend=[1 for i in range(n+1)]
par=[0]+[0]*(n+1)

for _ in range(n-1):
    a,b=map(int,input().split())
    neighbor[a].add(b)
    neighbor[b].add(a)

cur(1)


ans=[1]*(n+1)
ans1=1
for i in range(1,n+1):
    ans1=ans1*i*modinv(descend[i])
    ans1%=mod
ans[1]=ans1

cur2(1)

for i in range(1,n+1):
    print(ans[i])
S = str(input())
if S=="ABC":
    print("ARC")
elif
    print("ABC")

### FIXED CODE ###

S = str(input())
if S=="ABC":
    print("ARC")
else:
    print("ABC")
import math
n = int(input())
count = 0
lst = []
while n != 0:
  max_value = 1
  for i in range(1, n):
    if i in max_value:
      continue
    if math.log(i, 6) == int(math.log(i, 6)) or math.log(i, 9) == int(math.log(i, 9)):
    	max_value = max(max_value, i)
  n = n - max_value
  lst.add(max_value)
  count += 1
print(count)

### FIXED CODE ###

N=int(input())
ans=N
for i in range(N+1):
    cnt=0
    t=i
    while t>0:
        cnt+=t%6
        t//=6
    j=N-i
    while j>0:
        cnt+=j%9
        j//=9
    ans = min(ans,cnt)
print(ans)
inp = input()
a = [input() for i in range(int(inp))]
a.sort()
a.reverse()
print(a[0])
print(a[1])
print(a[2])

### FIXED CODE ###

import sys

a = []
for line in sys.stdin:
    a.append(int(line))
a.sort()
a.reverse()
print(a[0])
print(a[1])
print(a[2])
n = int(input())
a = []
b = []
for i in range(n):
    a[i],b[i] = map(int, input().split())
a.sort()
b.sort()
if n%2 == 1:
    	print(b[(n+1)//2]-a[(n+1)//2]+1)
else:
	print(b[n//2]-a[n//2]+b[n//2+1]-a[n//2+1]+1)

### FIXED CODE ###

n = int(input())
a = []
b = []
for i in range(n):
    a1,b1 = map(int, input().split())
    a.append(a1)
    b.append(b1)
a.sort()
b.sort()
if n%2 == 1:
    print(b[(n+1)//2-1]-a[(n+1)//2-1]+1)
else:
	print(b[n//2-1]-a[n//2-1]+b[n//2]-a[n//2]+1)
import sys
sys.setrecursionlimit(10000000)

f_inf = float("inf") # sys.maxsize

N, M, P = map(int, input().split())
ABC_d = {}
for m in range(M):
    A, B, C = map(int, input().split())
    if A in ABC_d:
        ABC_d[A].append([B, C - P])
    else:
        ABC_d[A] = [[B, C - P]]

cost = [-f_inf] * N
cost[0] = 0

max_num_sum = (N * (N + 1)) // 2
max_even = N // 2
max_odd = N - max_even

# def solve(pos, cnt, num_sum):
#     global cost

#     if not(pos in ABC_d): return
#     if cnt > N or num_sum > max_num_sum:
#         cost[pos-1] = f_inf;

#     for B, C in ABC_d[pos]:
#         if cost[B - 1] == f_inf or cost[B - 1] >= cost[pos - 1] + C:
#             pass
#         elif cost[B - 1] < cost[pos - 1] + C:
#             cost[B - 1] = cost[pos - 1] + C
#             solve(B, cnt + 1, num_sum + B)

def solve(pos, odd_cnt, even_cnt, num_sum):
    global cost

    # if not(pos in ABC_d): return

    if odd_cnt + even_cnt > N or num_sum > max_num_sum:#  odd_cnt > max_odd or even_cnt > max_even or num_sum > max_num_sum:
        cost[pos-1] = f_inf;

    for B, C in ABC_d[pos]:
        if cost[B - 1] == f_inf or cost[B - 1] >= cost[pos - 1] + C:
            pass
        elif cost[B - 1] < cost[pos - 1] + C:
            if B%2: odd_cnt += 1
            else: even_cnt += 1
            cost[B - 1] = cost[pos - 1] + C
            solve(B, odd_cnt, even_cnt, num_sum + B)


# solve(1, 1, 1)
solve(1, 1, 0, 1)

if (cost[-1] == f_inf):
    print (-1)
else:
    print (max(0, int(cost[-1])))


### FIXED CODE ###

import sys
sys.setrecursionlimit(10000000)

f_inf = sys.maxsize

N, M, P = map(int, input().split())
ABC_d = {}
for m in range(M):
    A, B, C = map(int, input().split())
    if A in ABC_d:
        ABC_d[A].append([B, C - P])
    else:
        ABC_d[A] = [[B, C - P]]

cost = [-f_inf] * N
cost[0] = 0

def solve(pos, cnt):
    global cost

    if not(pos in ABC_d): return
    if cnt > N: cost[pos-1] = f_inf;

    for B, C in ABC_d[pos]:
        if cost[B - 1] == f_inf or cost[B - 1] >= cost[pos - 1] + C:
            pass
        elif cost[pos-1] == f_inf:
            cost[B-1] = f_inf
            solve(B, cnt + 1)
        elif cost[B - 1] < cost[pos - 1] + C:
            cost[B - 1] = cost[pos - 1] + C
            solve(B, cnt + 1)

solve(1, 1)

if (cost[-1] == sys.maxsize):
    print (-1)
else:
    print (max(0, int(cost[-1])))
import math
N = int(input())
X = list(map(int, input().split()))

def sutamina(P, X):
    return (X-P)**2
  
sutamina_min = math.inf
for i in range(100):
    sutamina_souwa = 0
    for k in X:
        sutamina_souwa += sutamina(i, k)
    if sutamina_souwa < sutamina_min:
        sutamina_min = sutamina_souwa

print(sutamina_min)

### FIXED CODE ###

import math
N = int(input())
X = list(map(int, input().split()))
 
def sutamina(P, X):
    return (X-P)**2
  
sutamina_min = float('inf')
for i in range(100):
    sutamina_souwa = 0
    for k in X:
        sutamina_souwa += sutamina(i, k)
    if sutamina_souwa < sutamina_min:
        sutamina_min = sutamina_souwa

print(sutamina_min)
n = str(input())
ans = 1
for i in range(1,n):
    if i ** 2 > n:
        break
    else:
        ans = i ** 2
print(ans)

### FIXED CODE ###

n = int(input())
ans = 1
for i in range(1,n):
    if 2 ** i > n:
        break
    else:
        ans = 2 ** i
print(ans)
from fractions import Fractions as fa

n = int(input())
arr= [int(x) for x in input().split()]
ans = 0
for i in arr:
  ans += fa(1,i)
  
ans = str(ans).split('/')

print(ans[1]/ans[0])

### FIXED CODE ###

n = int(input())
arr= [1/int(x) for x in input().split()]
print(1/sum(arr))
----:---F1  *scratch*      All L1     (Fundamental)------------------------------------------------------------------------------------
Loading subst-jis...done
import math

r = 999999
sqrt = int(math.sqrt(r))
p = [1 for i in range(r)]
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        for j in range(2*(i+1)-1,r,i+1):
            p[j] = 0

while True:
    try:
        n = int(raw_input())
        print sum(p[:n])
    except:
        break

### FIXED CODE ###

import math
n = []
while True:
    try:
        n.append(int(raw_input()))
    except:
        break
  
r = max(n)+1
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
p[3::2] = [0 for x in range(3,r,2)]
for i in range(2,sqrt,2):
    if p[i]:
        p[2*i+1::i+1] = [0 for x in range(2*i+1,r,i+1)] 
  
for i in n:
     print sum(p[:i])
from collections import deque
import sys

stdin = sys.stdin
def li(): return map(int, stdin.readline().split())

N, M = tuple(li())
stack = []
for i in range(M):
    stack.append( tuple(li()) )

p_map = {}
for i in range(1, N + 1):
    # key: val
    # node_id: parent_id, union_size
    p_map[i] = [i, 1]

combs = deque()
def parent(i):
    if p_map[i][0] == i:
        return i
    else:
        return parent(p_map[i][0])
while stack:
    l, r = stack.pop()
    # parent should be greater
    if parent(l) < parent(r):
        l, r = r, l
    if parent(l) == parent(r):
        if combs:
            combs.appendleft(combs[0])
    else:
        p_map[r][0] = l
        incr = p_map[parent(l)][1] * p_map[parent(r)][1]
        p_map[l][1] += p_map[r][1]
        if combs:
            combs.appendleft(combs[0] + incr)
        else:
            combs.appendleft(incr)

cnt = 0
combs.append(0)
while combs:
    cur = combs.popleft()
    if combs:
        cnt += cur - combs[0]
        print(cnt)


### FIXED CODE ###

from collections import deque
import sys

stdin = sys.stdin
def li(): return map(int, stdin.readline().split())

N, M = tuple(li())
stack = []
for i in range(M):
    stack.append( tuple(li()) )

p_map = {}
for i in range(1, N + 1):
    # key: val
    # node_id: parent_id, union_size
    p_map[i] = [i, 1]

combs = deque()
def parent(i):
    if p_map[i][0] == i:
        return i
    else:
        return parent(p_map[i][0])
while stack:

    l, r = stack.pop()
    p_l = parent(l)
    p_r = parent(r)
    # parent should be greater
    if p_l == p_r:
        if combs:
            combs.appendleft(combs[0])
    else:
        if p_l < p_r:
            p_l, p_r = p_r, p_l
        p_map[p_r][0] = p_l
        incr = p_map[p_l][1] * p_map[p_r][1]
        p_map[p_l][1] += p_map[p_r][1]
        if combs:
            combs.appendleft(combs[0] + incr)
        else:
            combs.appendleft(incr)
cnt = 0
combs.append(0)
while combs:
    cur = combs.popleft()
    if combs:
        cnt += cur - combs[0]
        print(cnt)
N,M = map(str,inport().split())
if N == M:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

N,M = map(int,input().split())
if N == M:
  print("Yes")
else:
  print("No")
N,M = map(int,input().split())
edge = { i:[] for i in range(1,N+1)}
for _ in range(M):
    x,y = map(int,input().split())
    edge[x] += [y]

dp = [-1]*(N+1)
def distance(start):
    if dp[start] > 0:
        return dp[start]
    elif len(edge[start]) == 0:
        dp[start] = 0
        return 0
    else:
        temp = [distance(e) + 1 for e in edge[start]]
        dp[start] =  max(temp)
        return dp[start]

for i in range(1,N+1):
    go = distance(i)
print(max(dp))

### FIXED CODE ###

N,M = map(int,input().split())
edge = { i:[] for i in range(1,N+1)}
for _ in range(M):
    x,y = map(int,input().split())
    edge[x] += [y]
import sys 

sys.setrecursionlimit(10**5+1)
dp = [-1]*(N+1)
def distance(start):
    if dp[start] > 0:
        return dp[start]
    elif len(edge[start]) == 0:
        dp[start] = 0
        return 0
    else:
        temp = [distance(e) + 1 for e in edge[start]]
        dp[start] =  max(temp)
        return dp[start]

for i in range(1,N+1):
    go = distance(i)
print(max(dp))
def d170(n,a):
    count=0
    sa=sorted(list(set(a)))
    if sa[0]==1:
        if 1 in t:
            return 0
        else:
            return 1
    else:
        for i in range(len(sa)) :
            if i>=len(sa):
                break
            else:
                p=sa[i]
                k=[]
                for j in range(i+1,len(sa)):
                     if sa[j]%p==0:
                        k.append(sa[j])
                sa=sorted(list(set(sa)-set(k)))
        return len(set(sa))
    
n=int(input())
a= list(map(int, input().split()))    
print(d170(n,a))
            
  

### FIXED CODE ###

def d170(n,a):
    k=max(a)+1
    count=0
    dp=[0 for i in range(k)]
    for x in a:
        if dp[x]!=0:
                dp[x]=2
                
        else:
            for j in range(x,k,x):
                     dp[j]+=1
    for x in a:
        if dp[x]==1:
            count+=1
    return count
    
n=int(input())
a=list(map(int, input().split()))    
print(d170(n,a))
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(0,n,2):
	if a[i]&1:
	ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(0,n,2):
  if a[i]&1:
    ans+=1
print(ans)
N,K=map(int,input().split())
S=input()
print(S[0:K]+S[K].lower()+S[-K:])

### FIXED CODE ###

N,K=map(int,input().split())
S=input()
K=K-1
print(S[0:K]+S[K].lower()+S[K+1:])
K=int(input())
S=list(input())

LS=len(S)

if (LS+1) <= K:
    print(S)
elif (LS+1) > K:
    print(S[0:(SL-1):1],"...")


### FIXED CODE ###

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

if len(s) <= K:
    print(S)
else:
    print(S[0:K:]+"...")
def main():
	N, M = map(int, input().split())
	points = [[] for _ in range(N+1)]
	for i in range(1, M+1):
		a, b, c = map(int, input().split())
		points[a].append([b, c, i])
		points[b].append([a, c, i])
	use = set()
	def dijksta(start):
		is_visited = [False]*(N+1)
		is_visited[0] = True
		is_visited[start] = True
		stack = list(points[start])
		edge = 0
		while stack:
			edge += 1
			stack.sort(key=lambda x: x[1])
			use_edge = stack.pop()
			cur = use_edge[0]
			dist = use_edge[1]
			use.add(use_edge[2])
			is_visited[cur] = True
			if all(is_visited):
				return edge
			add_stack = list(points[cur])
			removes = []
			for i, pair in enumerate(add_stack):
				if is_visited[pair[0]]:
					removes.append(i)
					continue
				add_stack[i][1] += dist
			removes.reverse()
			for i in removes:
				add_stack.pop(i)
			stack.extend(add_stack)
	for i in range(1, M+1):
		dijksta(i)
	ans = M - len(use)
	print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
	INF = 10**9+7
	N, M = map(int, input().split())
	dist = [[INF for _ in range(N+1)] for _ in range(N+1)]
	for i in range(1, N+1):
		for j in range(1, N+1):
			if i == j:
				dist[i][j] = 0
	a, b, c = [0]*M, [0]*M, [0]*M
	for i in range(M):
		a[i], b[i], c[i] = map(int, input().split())
		dist[a[i]][b[i]] = min(dist[a[i]][b[i]], c[i])
		dist[b[i]][a[i]] = min(dist[b[i]][a[i]], c[i])
	for k in range(1, N+1):
		for i in range(1, N+1):
			for j in range(1, N+1):
				dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j])
	ans = M
	for i in range(M):
		shrotest = False
		for j in range(1, N+1):
			if dist[j][a[i]]+c[i] == dist[j][b[i]]:
				shrotest = True
		if shrotest:
			ans -= 1
	print(ans)

if __name__ == '__main__':
    main()
from math import pi as p

a = int(input())
s = round(p * (a ** 2), 11)
l = round(2 * p * a, 11)
print(s, l)

### FIXED CODE ###

from math import pi

a = float(input())
s = round(pi * (a ** 2), 11)
l = round(2 * pi * a, 11)
print(s, l)
n, x = [int(i) i in input().split()]

3 <= n <= 100

if n == x == 0:
    break

for a in range(n+1):
    for b in range(a+1):
        for c in range(b+1):
             a + b + c == x
             return
print()

### FIXED CODE ###

while True:
    n, x = [int(i) for i in input().split()]

    if n == x == 0:
        break

    count = 0
    for s in range(1, n+1):
        for m in range(s+1, n):
            for e in range(m+1, n+1):
                if x == sum([s, m, e]):
                    count += 1

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

# n番目の要素でソートsort
BC = sorted(BC, reverse=True, key=lambda x: x[1])

m = A[0]
D = []
for b, c in BC:
    if c > m:
        _ = [D.append(c) for i in range(b)]
    else:
        continue
    if len(D) > N:
        break

D.append(0)

for i, d in enumerate(D):
    if i > N:
        break
    if A[i] < d:
        A[i] = d
    else:
        break

print(sum(A))


### 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)]

# n番目の要素でソートsort
BC = sorted(BC, reverse=True, key=lambda x: x[1])

m = A[0]
D = []
for b, c in BC:
    if c > m:
        _ = [D.append(c) for i in range(b)]
    else:
        continue
    if len(D) > N:
        break

D.append(0)

for i, d in enumerate(D):
    if i >= N:
        break
    if A[i] < d:
        A[i] = d
    else:
        break

print(sum(A))
N, A, B = map(int, input().split())
ans = 0
for i in (1, N+1):
  sum = 0
  k = n
  while k > 0:
    sum = sum + k % 10
    k = k // 10
  if A =< sum =< B:
    ans = ans + n
print(ans)
  

### FIXED CODE ###

N, A, B = map(int, input().split())
ans = 0
for i in range(1, N+1):
  sum = 0
  k = i
  while k > 0:
    sum = sum + k % 10
    k = k // 10
  if A <= sum <= B:
    ans = ans + i
print(ans)
s=input()
n=0
for x in s: n += int(x)
print('Yes' if s%n==0 else 'No')

### FIXED CODE ###

s=input()
n=0
for x in s: n += int(x)
print('Yes' if int(s)%n==0 else 'No')
import sys

stdin = sys.stdin
ns = lambda: stdin.readline().rstrip()
na = lambda: list(map(int, stdin.readline().split()))
ni = lambda: int(ns())

(n,u,v)=na()
u -= 1
v -= 1

g = [[] for _ in range(n)]

for i in range(0, n-1):
    (a, b) = na()
    g[a-1].append(b-1)
    g[b-1].append(a-1)


dep1 = [0] * n
dep2 = [0] * n
def dfs(now, pre, d, dep):
    dep[now] = d
    for nex in g[now]:
        if pre == nex:
            continue
        dfs(nex,now,d+1,dep)


dfs(u, -1, 0, dep1)
dfs(v, -1, 0, dep2)

ret = 0
for i in range(n):
    if dep1[i] < dep2[i]:
        ret = max(ret, dep2[i]-1)
print(ret)


### FIXED CODE ###

import sys

stdin = sys.stdin
ns = lambda: stdin.readline().rstrip()
na = lambda: list(map(int, stdin.readline().split()))
ni = lambda: int(ns())
sys.setrecursionlimit(200000)

(n,u,v)=na()
u -= 1
v -= 1

g = [[] for _ in range(n)]

for i in range(0, n-1):
    (a, b) = na()
    g[a-1].append(b-1)
    g[b-1].append(a-1)


dep1 = [0] * n
dep2 = [0] * n
def dfs(now, pre, d, dep):
    dep[now] = d
    for nex in g[now]:
        if pre == nex:
            continue
        dfs(nex,now,d+1,dep)


dfs(u, -1, 0, dep1)
dfs(v, -1, 0, dep2)

ret = 0
for i in range(n):
    if dep1[i] < dep2[i]:
        ret = max(ret, dep2[i]-1)
print(ret)
import math
n=int(input())
print((2*n)//math.gcd(2,n))

### FIXED CODE ###

import fractions
n=int(input())
print((2*n)//fractions.gcd(2,n))
s=input()
 
ds=list(s)
 
 
c1=0
while ds[c1]!='A'
  c1+=1
 
c2=-1
while ds[c2]!='Z':
  c2-=1
 
print(len(s[c1:c2]))

### FIXED CODE ###

from collections import deque
s=input()

ds=deque(s)
flag=True

while ds[0]!='A' or ds[-1]!='Z':
  if ds[0]!='A':
    ds.popleft()
  if ds[-1]!='Z':
    ds.pop()
print(len(ds))
import sys

def main(arg):

    if arg[0] in ['hi'*i for i in range(1,6)]:
        print('Yes')
    else:
        print('No')

if __name__=='__main__':
    main(sys.argv[1:])


### FIXED CODE ###

#!/usr/bin/python
# coding: UTF-8

def main():
    arg = input()
    if arg in ['hi'*i for i in range(1,6)]:
        print('Yes')
    else:
        print('No')

if __name__=='__main__':
    main()
if len(set(map(int, inputs[0].split()))) == 2:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

if len(set(map(int, input().split()))) == 2:
    print('Yes')
else:
    print('No')