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

balls_in_box = [0] + [1 for _ in range(1,N+1)]
red_ball_containable_box = set()
red_ball_containable_box.add(y)

for i in range(M):
    x,y = map(int, input().split())
    if x in red_ball_containable_box:
        balls_in_box[x] -= 1
        balls_in_box[y] += 1
        red_ball_containable_box.add(y)
        if balls_in_box[x] == 0: #赤玉が入っている可能性が100％の箱を全部空にすれば確実に移る
            red_ball_containable_box.remove(x)
    else:
        balls_in_box[x] -= 1
        balls_in_box[y] += 1

print(len(red_ball_containable_box))

### FIXED CODE ###

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

balls_in_box = [0] + [1 for _ in range(1,N+1)]
red_ball_containable_box = set()
red_ball_containable_box.add(1)

for i in range(M):
    x,y = map(int, input().split())
    if x in red_ball_containable_box:
        balls_in_box[x] -= 1
        balls_in_box[y] += 1
        red_ball_containable_box.add(y)
        if balls_in_box[x] == 0: #赤玉が入っている可能性が100％の箱を全部空にすれば確実に移る
            red_ball_containable_box.remove(x)
    else:
        balls_in_box[x] -= 1
        balls_in_box[y] += 1

print(len(red_ball_containable_box))
s=input()
if s.isdecimal() == true:
	x = int(s)
	if x >=1 and x <=100:
		print(x ** 3)


### FIXED CODE ###

number = int(input())
print(number**3)
from fractions import gcd

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

d = gcd(N, M)
n = N // d
m = M // d
f = True

for i in range(d):
    if S[n*i] != T[m*i]:
        f = false
        break

print(N * M // d if f else -1)

### FIXED CODE ###

from fractions import gcd
 
 
def solve(n, m, s, t):
    g = gcd(n, m)
    ng = n // g
    mg = m // g
 
    for h in range(g):
        if s[ng * h] != t[mg * h]:
            return -1
    return ng * mg * g
 
 
n, m = list(map(int, input().split()))
s = input()
t = input()
print(solve(n, m, s, t))
print("Aa"[ord(open(0))>95])


### FIXED CODE ###

print("Aa"[ord(input())>95])
number = int(input())
 
if number % 4 == 0:
  print("YES")
else:
  print("NO")

### FIXED CODE ###

r, g, b = map(int, input().split())
 
number = r * 100 + g * 10 + b
 
if number % 4 == 0:
  print("YES")
else:
  print("NO")
s = input()

s = s.split(" ")

x1 = int(s[0])
y1 = int(s[1])

x2 = int(s[2])
y2 = int(s[3])

 # X1 - X2 の増加量
zouka_x = abs(int(x1) - int(x2))

 # Y1 - Y2 の増加量
zouka_y = abs(int(y1) - int(y2))



if (x1 <= x2 and y1 <= y2):
    x3 = x2 - zouka_y
    y3 = y2 + zouka_x

    x4 = x1 - zouka_y
    y4 = y1 + zouka_x
elif (x1 > x2 and y1 < y2):
    x3 = x2 - zouka_y
    y3 = y2 - zouka_x

    x4 = x1 - zouka_y
    y4 = y1 - zouka_x
elif (x1 < x2 and y1 < y2):
    x3 = x2 + zouka_y
    y3 = y2 - zouka_x

    x4 = x1 + zouka_y
    y4 = y1 - zouka_x
elif (x1 < x2 and y1 > y2):
    x3 = x2 + zouka_y
    y3 = y2 + zouka_x

    x4 = x1 + zouka_y
    y4 = y1 + zouka_x

print(str(x3) + " " + str(y3) + " " + str(x4) + " " + str(y4))


### FIXED CODE ###

x1, y1, x2, y2 = map(int, input().split())
 
vector_x, vector_y = x2 - x1, y2 - y1
print(x2 - vector_y, y2 + vector_x, x1 - vector_y, y1 + vector_x)
N=int(input())

X=[]
Y=[]
for _ in range(N):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)
A="NO"
for n in range(N-2):
    if X[n]==Y[n] and X[n+1]==Y[n+1] and X[n+2]==Y[n+2]:
        A="YES"
        break
print(A)

### FIXED CODE ###

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

lstx=[a,b]
lsty=[c,d]
result=[]
for i in lstx:
    for n in lsty:
        result.append(i*n)
print(max(result))
N,K = map(int, input().split())
h = list(map(int, input().split()))
dp = [0,abs(h[1]-h[0])]

for i in range(2,N):
    dp_i = 1000000000000000000000
    for j in range(1,K+1):
        if i-j >= 0:
            step_j = dp[i-j] + abs(h[i]-h[i-j])
            dp_i = min(step_j,dp_i)
        else:
            dp.append(dp_i)
            break
    dp.append(dp_i)
print(dp[-1])


### FIXED CODE ###

N = int(input())
h_list = list(map(int, input().split()))
dp = [0,abs(h_list[1]-h_list[0])]
for i in range(1,N-1):
    step_1 = dp[i]+abs(h_list[i+1]-h_list[i])
    step_2 = dp[i-1]+abs(h_list[i+1]-h_list[i-1])
    dp_ans = min(step_1,step_2)
    dp.append(dp_ans)
print(dp[-1])
import numpy as np
N=input()
a=list(map(int,input().split(",")))
a=np.asarray(a)
b=0
while True:
    if all(a%2==0):
        a=a/2
        b+=1
    else:
        break
print(b)


### FIXED CODE ###

n = input()
a = list(map(int, input().split()))
cnt = 0
while all(i%2==0 for i in a):
    a = [i/2 for i in a]
    cnt += 1
print(cnt)
N,K=map(int,input().split())
P=list(map(int,input().split()))
P=sorted(P)
ans=0
for i in range(K):
    ans+=P(i)
print(ans)

### FIXED CODE ###

N,K=map(int,input().split())
P=list(map(int,input().split()))
P=sorted(P)
ans=0
for i in range(K):
    ans+=P[i]
print(ans)
s=input()
K=int(input())
s=list(s)
#a-z 97-122
for i, s_ in enumerate(s):
    if s_!='a':
        if ord(s_)-K <= 97:
            s[i]='a'
            K -= (123-ord(s_))
if K>0:
    asc=ord(s[-1])+K%26
    s[-1]=chr(asc)
print ("".join(s))

### FIXED CODE ###

# -*- coding: utf-8 -*-
raw = raw_input()

ans =  raw[:4]+' '+raw[4:]

print ans
a = int(input())
b = int(input())
if a < b:
  swap(a,b)
if a == b:
  print(a*2)
else:
  print(a*2-1)


### FIXED CODE ###

a,b = map(int,input().split())
if a < b:
  a,b = b,a
if a == b:
  print(a*2)
else:
  print(a*2-1)
def change(after,index,li):
    before = li[index]
    for i in range(len(li)):
        if li[i]==before:
            li[i]=after


def main():
    n,k,l = map(int,input().split())
    road=[0 for _ in range(n)]
    train=[0 for _ in range(n)]
    r=t=1
    for _ in range(k):
        p,q = map(int,input().split())
        if road[p-1]==0 and road[q-1]==0:
            road[p-1]=road[q-1]=r
            r+=1
        elif road[p-1]!=0 and road[q-1]==0:
            change(r,p-1,road)
            road[q-1]=r
            r+=1
        elif road[p-1]==0 and road[q-1]!=0:
            change(r,q-1,road)
            road[p-1]=r
            r+=1
        else:
            change(r,p-1,*road)
            change(r,q-1,*road)
            r+=1
    for _ in range(l):
        p,q = map(int,input().split())
        if train[p-1]==0 and train[q-1]==0:
            train[p-1]=train[q-1]=t
            t+=1
        elif train[p-1]!=0 and train[q-1]==0:
            change(t,p-1,train)
            train[q-1]=t
            t+=1
        elif train[p-1]==0 and train[q-1]!=0:
            change(t,q-1,train)
            train[p-1]=t
            t+=1
        else:
            change(t,p-1,train)
            change(t,q-1,train)
            t+=1
    for i in range(n):
        ans=1
        for j in range(n):
            if i!=j and train[i]!=0 and train[i]==train[j] and road[i]!=0 and  road[i]==road[j]:
                ans+=1
        print(ans)
main()


### FIXED CODE ###

from collections import Counter,defaultdict,deque
import sys,bisect,math,itertools,string,queue,copy
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7

def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inpln(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return sorted([list(map(int, input().split())) for _ in range(n)])
def sortx(x,n,k):
    if k == 0:x.sort(key=lambda y:y[1,n])
    else:x.sort(reversed=True, key=lambda y:y[1,n])

def find(x): # 木の根を求める
    if par[x]==x:
        return x
    else:
        return find(par[x])

def unite(x,y): # xとyの属する集合を併合
    x=find(x)
    y=find(y)
    if x==y:return
    if rank[x]<rank[y]:
        par[x]=y
    else:
        par[y]=x
        if rank[x]==rank[y]:
            rank[x]+=1

def same(x,y): # xとyが同じ集合に属するか判定
    return find(x)==find(y)
 
def main():
    n,k,l = inpm()
 
    global par,rank
    par  = [i for i in range(2*n)]
    rank = [-1 for _ in range(2*n)] 
    for _ in range(k):
        p,q = inpm()
        p-=1
        q-=1
        unite(p,q)
    for _ in range(l):
        r,s = inpm()
        r-=1
        s-=1
        unite(r+n,s+n)

    root_s=defaultdict(int)
    root=[]
    for i in range(n):
        root.append(str(find(i))+' '+str(find(i+n)))
        root_s[root[i]]+=1
    
    ans=[0 for _ in range(n)]
    for i in range(n):
        ans[i] = root_s[root[i]]
    print(*ans) 


if __name__ == "__main__":
    main()
import sys
from heapq import*
def g(s,g):
 F=[1e7]*-~n;F[s]=0
 H=[(0,s)]
 while H:
  c,u=heappop(H)
  if u==g:return c
  for f,v in E[u]:
   t=c+f
   if t<F[v]:
    F[v]=t
    heappush(H,(t,v))
 return-1
for e in iter(input,'0 0'):
 n,k=map(int,e.split())
 E=[[]for _ in[0]*-~n]
 for _ in[0]*k:
  f=input()
  if f[0]:
   c,d,e=map(int,f[2:].split())
   E[c]+=[(e,d)];E[d]+=[(e,c)]
  else:print(g(*map(int,f[2:].split())))


### FIXED CODE ###

def s():
 import sys
 r=sys.stdin.readline
 I=float('inf')
 for e in iter(r,'0 0\n'):
  n,k=map(int,e.split())
  F=[[I]*-~n for _ in[0]*-~n]
  for i in range(1,n+1):F[i][i]=0
  for _ in[0]*k:
   f=r();g=map(int,f[2:].split())
   if'0'==f[0]:a,b=g;A=F[a][b];print([A,-1][A==I])
   else:
    c,d,e=g
    if e<F[c][d]:
     for i in range(2,n+1):
      for j in range(1,i):
       F[i][j]=F[j][i]=min(F[i][j],F[i][c]+e+F[d][j],F[i][d]+e+F[c][j])
s()
N, K, Q = map(int, input().split())
points = [K] * N
for _ in range(Q):
    a = int(input())
    points[a] +=1

for point in points:
    if point > Q:
        print('Yes')
    else:
        print('No')

### FIXED CODE ###

N, K, Q = map(int, input().split())
points = [K] * N
for _ in range(Q):
    a = int(input())
    points[a-1] +=1

for point in points:
    if point > Q:
        print('Yes')
    else:
        print('No')
A=list(map(int, input().split()))
if N==1:
  print(abs(A[-1]-W))
else:
  a=abs(A[-1]-W)
  b=abs(A[-2]-A[-1])
  print(max(a,b))

### FIXED CODE ###

N,Z,W=map(int,input().split())
A=list(map(int, input().split()))
if N==1:
  print(abs(A[-1]-W))
else:
  a=abs(A[-1]-W)
  b=abs(A[-2]-A[-1])
  print(max(a,b))
N = int(input())
A = list(map(int, input().split()))

colors = [0]*9
for a in A:
    colors[a//400] += 1
ansmin = 0
for c in colors[:-1]:
    if c:
        ansmin += 1
print("{} {}".format(ansmin, ansmin+colors[-1]))

### FIXED CODE ###

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

colors = [0]*9
for a in A:
    colors[min(8, a//400)] += 1
ansmin = 0
for c in colors[:-1]:
    if c:
        ansmin += 1
x = 0
if ansmin < colors[-1]:
    x = 1
print("{} {}".format(max(ansmin, x), ansmin+colors[-1]))
N = int(input())
L = [] * (N+1)
L[0] = 2
L[1] = 1
for i in range(2,N+1):
    L[i] = L[i-1] + L[i-2]
print(L[N])


### FIXED CODE ###

N = int(input())
L = [0] * (N+1)
L[0] = 2
L[1] = 1
for i in range(2,N+1):
    L[i] = L[i-1] + L[i-2]
print(L[N])
n = input()
print(n*n*n/27)

### FIXED CODE ###

n = int(input())
print(n*n*n/27)
import sys

input = map(lambda x:x[:-1], sys.stdin.readlines())


n = int(input[0])

input = input[1:]

input = map(lambda x:x.split(' '), input)

for i in range(len(input)):
    input[i] = map(lambda x:int(x), input[i])

#print input
A = []
B = []

def a_can_add(e):
    if ((len(A) != 0) and (A[-1] < e)) or len(A) == 0:
        return True    

def b_can_add(e):
    if ((len(B) != 0) and (B[-1] < e)) or len(B) == 0:
        return True

def a_add(e):
    if (len(A) != 0) and (A[-1] < e):
        A.append(e)
    elif len(A) == 0:
        A.append(e)
    else: return False

def b_add(e):
    if len(B) != 0 and (B[-1] < e):
        B.append(e)
    elif len(B) == 0:
        B.append(e)
    else: return False


for i in range(len(input)):
    for j in range(10):
        if a_can_add(input[i][j]):
            a_add(input[i][j])
        elif b_can_add(input[i][j]):
            b_add(input[i][j])
            
    if len(A) + len(B) == 10:
        print "YES"
    else:
        print "NO"

### FIXED CODE ###

N = int(raw_input())

def dfs(depth, l, r):
    if depth == 10:
        return True

    if l < A[depth] and dfs(depth+1, A[depth], r):
        return True
    if r < A[depth] and dfs(depth+1, l, A[depth]):
        return True

    return False

for c in range(N):
    A = map(int, raw_input().split(" "))
    if dfs(0, 0, 0):
        print "YES"
    else:
        print "NO"
L = int(input())

print((l/3)**(3))

### FIXED CODE ###

L = int(input())

print((L/3)**(3))
h, w = map(int, input().split())
s = [0] * w
for _ in range(h):
    s[_] = [c for c in input()]

# print(s)
# print(s[1][1])

ok = True
for hi in range(h):
    for wi in range(w):
        if s[hi][wi] == '#':
            drawable = False
            # check
            if hi > 0:
                drawable = (s[hi-1][wi] == '#') | drawable
            
            if hi < h-1:
                drawable = (s[hi+1][wi] == '#') | drawable
            
            if wi > 0:
                drawable = (s[hi][wi-1] == '#') | drawable
            
            if wi < w-1:
                drawable = (s[hi][wi+1] == '#') | drawable

            if not drawable:
                ok = False

print("Yes" if ok else "No")


### FIXED CODE ###

h, w = map(int, input().split())
s = [0] * h
for _ in range(h):
    s[_] = input()

# print(s)
# print(s[1][1])

ok = True
for hi in range(h):
    for wi in range(w):
        if s[hi][wi] == '#':
            drawable = False
            # check
            if hi >= 1:
                drawable = (s[hi-1][wi] == '#') | drawable
            
            if hi <= h-2:
                drawable = (s[hi+1][wi] == '#') | drawable
            
            if wi >= 1:
                drawable = (s[hi][wi-1] == '#') | drawable
            
            if wi <= w-2:
                drawable = (s[hi][wi+1] == '#') | drawable

            # if hi >= 1:
            #     if s[hi-1][wi] == 

            if not drawable:
                ok = False

print("Yes" if ok else "No")
n,m=int(input())
li=[int(k) for k in input().split()]
dp=[0]*n
dp[0]=0
dp[1]=li[1]-li[0]
for i in range(2,n):
  ans=10**9
  for j in range(1,m+1):
    ans=min(ans,abs(li[i]-li[i-j])+dp[i-j])
  dp[i]=ans
print(dp[n-1])  


### FIXED CODE ###

n,m=input().split()
n=int(n)
m=int(m)
li=[int(k) for k in input().split()]
dp=[0]*n
dp[0]=0
dp[1]=abs(li[1]-li[0])
for i in range(2,n):
  ans=10**9
  for j in range(1,m+1):
    if i-j<0:
      break
    ans=min(ans,abs(li[i]-li[i-j])+dp[i-j])
  dp[i]=ans
#print(dp)  
print(dp[n-1])
a,b=map(int,input(),split())
print(a*b-a-b+1)

### FIXED CODE ###

a,b=map(int,input().split())
print((a-1)*(b-1))
int C
A, B = [int(i) for i in input().split()]

if A == 2 or B == 2:
  print("No")
  
elif C == 1 or C ==3:
  print("Yes")

### FIXED CODE ###

A, B = map(int, input().split())

if (A == 2) or (B == 2):
  print("No")
  
else:
  print("Yes")
import numpy as np
n, k, q = input().split(' ')
n, k, q = int(n),int(k), int(q)
hum = [0]*n
for i in range(q):
    ind = input()
    hum[int(ind)] += 1
hum_last = np.array(hum)-1
for i in range(len(list(hum_last))):
    if hum_last[i] <= 0:
        print('No')
    else:
        print('Yes')

### FIXED CODE ###

import numpy as np
n, k, q = input().split(' ')
n, k, q = int(n),int(k), int(q)
hum = [k]*n
for i in range(q):
    ind = input()
    hum[int(ind)-1] += 1
hum_last = np.array(hum)-q
for i in range(len(hum_last)):
    if hum_last[i] <= 0:
        print('No')
    else:
        print('Yes')
S = input()
if S == abc or S == acb or S == bac or S ==bca or S == cab or S == cba:
	print('Yes')
else:
	print('No')
	

### FIXED CODE ###

S = input()
if S == 'abc' or S == 'acb' or S == 'bac' or S =='bca' or S == 'cab' or S == 'cba':
	print('Yes')
else:
	print('No')
from collections import deque

H, W = map(int, input().split())
grid = [list(input()) for i in range(H)]

# 初期が黒('#')の位置からの距離
dist = [[-1]*H for _ in range(W)]

# '#'の位置をキューに追加（＝今回はこれが複数あるので、複数スタートとなる）
black_cells = deque()
for h in range(H):
    for w in range(W):
        if grid[h][w] == '#':
            black_cells.append([h, w])
            dist[h][w] = 0

d = 0
while len(black_cells) > 0:
    # キューとして使うのでpop()ではなくpopleft()
    h, w = black_cells.popleft()  # 黒いセルの座標
    d = dist[h][w]
    for dy, dx in [[1, 0], [0, 1], [-1, 0], [0, -1]]:
        new_h = h + dy
        new_w = w + dx
        if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w:
            continue
        if dist[new_h][new_w] == -1:  # セルが白('.')であるのと同義
            dist[new_h][new_w] = d+1
            black_cells.append([new_h, new_w])

print(d)

### FIXED CODE ###

from collections import deque

H, W = map(int, input().split())
grid = [list(input()) for i in range(H)]

# '#'の位置をキューに追加（＝今回はこれが複数あるので、複数スタートとなる）
black_cells = deque()
for h in range(H):
    for w in range(W):
        if grid[h][w] == '#':
            black_cells.append([h, w, 0])

ans = 0
while len(black_cells) > 0:
    one_black_cell = black_cells.popleft()  # キューとして使うのでpop()ではなくpopleft()
    for dy, dx in [[1, 0], [0, 1], [-1, 0], [0, -1]]:
        nh = one_black_cell[0] + dy
        nw = one_black_cell[1] + dx
        d = one_black_cell[2]
        if nh < 0 or H <= nh or nw < 0 or W <= nw:
            continue
        if grid[nh][nw] == '.':
            grid[nh][nw] = '#'
            black_cells.append([nh, nw, d + 1])
        ans = d

print(ans)
from bisect import bisect,bisect_left
from fractions import gcd
MAXN = 1000002
T = 2**20*3**14*5**9
H = filter(lambda i:gcd(T,i)==i,xrange(MAXN))
while True:
    line = raw_input()
    if line == "0":
        break
    m,n = map(int,line.split())
    print bisect(H,n)-bisect_left(H,m)

### FIXED CODE ###

from bisect import bisect_left
S = [60,80,100,120,140,160]
W = [2,5,10,15,20,25]
F = [600,800,1000,1200,1400,1600,0]
def func(x,y,h,w):
    return F[max(bisect_left(S,x+y+h),bisect_left(W,w))]
while True:
    n = input()
    if n == 0:
        break
    print sum(func(*map(int,raw_input().split())) for _ in xrange(n))
#A
N, K = map(int, input().split())
S = input()
print(S.replace(S[K],S[K].lower()))

### FIXED CODE ###

N, K = map(int, input().split())
S = input()
print(S[:K-1] + S[K-1].lower() + S[K:N])
s= int(input())
print(0,0,v=10**9,1,-s%v,(s+(-s%v))//v)

### FIXED CODE ###

#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys, math, bisect, random, itertools
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A(s):
    def pri(n, x):
        if n == 0:
            return [0, 0]
        if n == 1:
            return [1, 1]
        if n == 2:
            return [2, 1]
        for i in range(2, int(math.sqrt(n))):
            if n % i == 0 and n // i <= x:
                return [i, n // i]
        return [1, n]
    x = int(math.sqrt(s))
    if s < 10 ** 9:
        print(0, 0, 0, s, 1, 0)
        return
    while 1:
        X = x ** 2
        if X - s < 0:
            x += 1
            continue
        b = pri(X - s, x)
        if b:
            print(0, 0, x, int(b[0]), int(b[1]), x)
            if x > 10 ** 9 or b[0] > 10 ** 9 or b[1] > 10 ** 9:
                print(s)
                quit()
            return
        x += 1
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return



#Solve
if __name__ == '__main__':
    A(II())
N,M=map(int,input().split())
import collections
e =[]
for i in range(N):
    ta,tb =map(int,input().split())
    e.extend([ta,tb])
c = collections.Counter(e)
print(c)
ans = "YES"
for i in c:
    if c[i]%2 != 0:
        ans = "NO"
print(ans)


### FIXED CODE ###

N,M=map(int,input().split())
import collections
e =[]
for i in range(M):
    ta,tb =map(int,input().split())
    e.extend([ta,tb])
c = collections.Counter(e)
#print(c)
ans = "YES"
for i in c:
    if c[i]%2 != 0:
        ans = "NO"
print(ans)
import bisect
from collections import deque

n,m = map(int,input().split())
a = list(map(int,input().split()))
bc = []
for _ in range(m):
    tmp = list(map(int,input().split()))
    bc.append(tmp[::-1])

a.sort()
a = deque(a)
bc.sort(reverse=True)

ans = 0
num = 0
for i in range(m):
    index = bisect.bisect_left(a,bc[i][0])
    if index == 0:
        break
    if bc[i][1] > index:
        ans += bc[i][0] * index
        num += index
    else:
        ans += bc[i][0] * bc[i][1]
        num += bc[i][1]
    for i in range(num):
        a.popleft()

print(ans + sum(a))


### FIXED CODE ###

import sys

def main():
    input = sys.stdin.readline

    n,m = map(int,input().split())
    a = list(map(int,input().split()))
    bc = []
    for _ in range(m):
        bc.append(list(map(int,input().split())))

    a.sort()
    a = tuple(a)

    bc.sort(key=lambda x: x[1], reverse=True)

    num = 0
    ans = 0

    for i in range(m):
        b = bc[i][0]
        c = bc[i][1]
        for j in range(num,min(num+b,n)):
            if c > a[j]:
                ans += c
            else:
                ans += a[j]

        num += b
        if num >= n:
            break

    if num < n:
        print(ans + sum(a[num:]))
    else:
        print(ans)
if __name__ == '__main__':
    main()
n = input()
l = len(n)
if n[l] == "2" or '4' or '5' or '7' or '9':
  print("hon")
elif n[l] == '0' or '1' or '6' or '8':
  print('pon')
else:
  print('bon')

### FIXED CODE ###

N = input()
n = N[len(N)-1]
if n == "2" or n== '4' or n=='5' or n=='7' or n=='9':
  print("hon")
elif n == '0' or n=='1' or n=='6' or n=='8':
  print('pon')
else:
  print('bon')
a = int(input())
b*b*b

### FIXED CODE ###

a = int(input())
print (a**3)
get = list(map(int, input().split()))

N = get[0]
K = get[1]
Q = get[2]

point = [K]*N

for i in range(Q):
  A = input()
  A = int(A)
  for j in range(Q):
    if (A - 1) != j:
      point[j] += -1

for i in range(Q):
  if point[i] > 0:
    print("Yes")
  else:
    print("No")

### FIXED CODE ###

get = list(map(int, input().split()))

N = get[0]
K = get[1]
Q = get[2]

list = [0]*N

for i in range(Q):
  list[int(input()) - 1] += 1 

for i in range(N):
  if K - (Q - list[i]) > 0:
    print("Yes")
  else:
    print("No")