Harryxun/stf_run huggingface dataset:
from collections import deque
n, m = map(int, input().split())
INF = 100000000

to = [[] for _ in range(10005)]
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)
print('Yes')
q = deque([])
dist = [INF] * n
pre = [-1] * n
dist[0] = 0
q.append(0)

while len(q) > 0:
    v = q.popleft()
    for i in to[v]:
        if dist[i] != INF:
            continue
        dist[i] = dist[v] + 1
        pre[i] = v
        q.append(i)

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


### FIXED CODE ###

from collections import deque
n, m = map(int, input().split())
INF = 100000000

to = [[] for _ in range(100005)]
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)
print('Yes')
q = deque([])
dist = [INF] * n
pre = [-1] * n
dist[0] = 0
q.append(0)

while len(q) > 0:
    v = q.popleft()
    for i in to[v]:
        if dist[i] != INF:
            continue
        dist[i] = dist[v] + 1
        pre[i] = v
        q.append(i)

for i in range(1, n):
    ans = pre[i]
    ans += 1
    print(ans)
n, m = map(int, input().split())
b = [False]*(n+1)
dp = [None]*(n+1)
M = 10**9+7
dp[0] = 1
dp[1] = 1

def up(x):
    if b[x] == True:
        return 0
    res = 0
    if dp[x-1] == None:
        dp[x-1] = up(x-1)
    res += dp[x-1]
    if dp[x-2] == None:
        dp[x-2] = up(x-2)
    res += dp[x-2]
    return (res%M)

for i in range(m):
    a = int(input())
    b[a] = True
if b[1] == True:
    dp[1] = 0
if n == 1:
    if b[1] == True:
        print(0)
    else:
        print(1)
    exit()
print(up(n))


### FIXED CODE ###

n, m = map(int, input().split())
b = [False]*(n+2)
for _ in range(m):
    i = int(input())
    b[i] = True
M = 10**9+7
dp = [0]*(n+1)
dp[0] = 1
for i in range(1, n+1):
    if b[i] == False:
        dp[i] = (dp[i-1] + dp[i-2])%M
print(dp[n])
a=int(input())
b=int(input())
c=int(input())
if(a+b>c): print("Yes")
else: print("No")

### FIXED CODE ###

a, b, c = map(int, input().split())
if(a+b>=c):
  print("Yes")
else:
  print("No")
n, m, l = [int(i) for i in input().split()]

A = [input(range(n))]
B = [input(range(m))]
C = [[0] * 1 for n in range(n)]


for ni in range(n):
    A.append([int(i) for i in input().split()])

for mi in range(m):
    B.append([int(i) for i in input().split()])

C[A][B] = sum([A[n][l] * B[l][m]])

print(" ".join([str(v) for v in C]))

### FIXED CODE ###

n, m, l = [int(i) for i in input().split()]

A = []
B = []
C = []

for ni in range(n):
    A.append([int(i) for i in input().split()])

for mi in range(m):
    B.append([int(i) for i in input().split()])

for i in range(n):
    C.append([])
    for j in range(l):
        C[i].append(0)
        for k in range(m):
            C[i][j] += A[i][k] * B[k][j]

for li in range(n):
    print(" ".join([str(s) for s in C[li]]))
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

def rev():
  global A
  for i in range(N):
    a, b = A[-(2+i)], A[-(1+i)]
    if a > b:
      A[-(2+i)] = b
      A[-(1+i)] = a
    else:
      break

for _ in range(M):
  A[-1] = A[-1]//2
  rev()

print(sum(A))

### FIXED CODE ###

from heapq import heappop, heappush

N, M = map(int, input().split())
A = list(map(lambda x: (-1)*int(x), input().split()))

H = []

for i in A:
  heappush(H, i)

for _ in range(M):
  m = (-1) * heappop(H)
  m //= 2
  heappush(H, (-1)*m)

print((-1)*sum(H))
S = input()
K = int(input())
cot = 0
before = ""
seq = []

if len(S) == 1:
    ans = len(K)//2
else:
    for i in range(len(S)):
        c = S[i]
        if cot == 0:
            cot += 1
            before =c
        else:
            if c == before:
                cot += 1
            else:
                before = c
                seq.append(cot)
                cot = 1

    seq.append(cot)
    ans = 0
    for temp in seq:
        ans +=temp//2
    ans *= K
    if S[0] == S[-1]:
        ans += (seq[0] + seq[-1]) * (K - 1) //2 - (seq[0] //2 + seq[-1]//2 )* (K - 1)
print(ans)

### FIXED CODE ###

S = input()
K = int(input())
cot = 0
before = ""
seq = []


for i in range(len(S)):
    c = S[i]
    if cot == 0:
        cot += 1
        before =c
    else:
        if c == before:
            cot += 1
        else:
            before = c
            seq.append(cot)
            cot = 1

seq.append(cot)
ans = 0
for temp in seq: #素の状態で連続してる文字列
    ans +=temp//2
ans *= K
if S[0] == S[-1]: #頭と尾で一緒→つなげたときに長い連続区間が発生
    ans += (seq[0] + seq[-1]) //2 * (K - 1) - (seq[0] //2 + seq[-1]//2 )* (K - 1)
if len(seq) == 1:
    ans = min(ans,seq[0] * K //2)
print(ans)
inf = input().split()
H = int(inf[0])
W = int(inf[1])
sheet = [[] for i in range(H+2)]
score = [[] for i in range(H+2)]
m = 0
 
for h in range(H+2):
  if h==0 or h==H+1:
    a = [False]*(W+2)
    b = [(0,0)]*(W+2)
    sheet[h]=a
    score[h]=b
  else:
    line = input()
    a = []
    b = []
    a += [False]
    b += [(0,0)]
    for w in range(W):
      b+=[(0,0)]
      if line[w]=='.':
        a += [True]
      else:
        a += [False]
    a += [False]
    b += [(0,0)]
    sheet[h]=a
    sheet[w]=b
      
for h in range(1,H+1):
  for w in range(1,W+1):
    if sheet[h][w]:
      s = 0
      hs = 0
      ws = 0
      if sheet[h-1][w]:
        hs += score[h-1][w][0]
      else:
        i = h+1
        while sheet[i][w]:
          hs+=1
          i+=1
      if sheet[h][w-1]:
        ws += score[h][w-1][1]
      else:
        j = w+1
        while sheet[h][j]:
          ws+=1
          j+=1
      s = 1 + hs + ws
      score[h][w]=(hs, ws)
      if m < s:
        m = s
print(m)


### FIXED CODE ###

inf = input().split()
H = int(inf[0])
W = int(inf[1])
sheet = [[] for i in range(H+2)]
score = [[] for i in range(H+2)]
m = 0
 
for h in range(H+2):
  if h==0 or h==H+1:
    a = [False]*(W+2)
    b = [(0,0)]*(W+2)
    sheet[h]=a
    score[h]=b
  else:
    line = input()
    a = []
    b = []
    a += [False]
    b += [(0,0)]
    for w in range(W):
      b+=[(0,0)]
      if line[w]=='.':
        a += [True]
      else:
        a += [False]
    a += [False]
    b += [(0,0)]
    sheet[h]=a
    score[h]=b
      
for h in range(1,H+1):
  for w in range(1,W+1):
    if sheet[h][w]:
      s = 0
      hs = 0
      ws = 0
      if sheet[h-1][w]:
        hs += score[h-1][w][0]
      else:
        i = h+1
        while sheet[i][w]:
          hs+=1
          i+=1
      if sheet[h][w-1]:
        ws += score[h][w-1][1]
      else:
        j = w+1
        while sheet[h][j]:
          ws+=1
          j+=1
      s = 1 + hs + ws
      score[h][w]=(hs, ws)
      if m < s:
        m = s
print(m)
s = input()
L = ["A","C","G","T"]

counter = 0
ans_L = []
for val in s:
    if val in L:
        counter += 1
    else:
        ans_L.append(counter)
        counter = 0

print(max(ans_L))

### FIXED CODE ###

s = input()
L = ["A","C","G","T"]

counter = 0
ans_L = []
for val in s:
    if val in L:
        counter += 1
    else:
        ans_L.append(counter)
        counter = 0
ans_L.append(counter)

print(max(ans_L))
import heapq
N=input()
#print N
a=[]
a=map(int,raw_input().split())
#print a

q1=[] #+
q2=[] #-
for ind,i in enumerate(a):
	if i>=0:
		heapq.heappush(q1, [-1*i,ind])
	else:
		heapq.heappush(q2, [i,ind])
#print "# q1"	
#print q1
#print "# q2"
#print q2

cnt=0
b=[]
for ind,i in enumerate(a):
	if ind==0:
		prev_i=i
		continue
	else:
		if prev_i<=i:
			prev_i=i
			continue
		else:
			#print ind,prev_i,i
			#while prev_i>i:
			if i<0 and prev_i<0:
				t_val=q2[0][0]
				#prev_i+=t_val
				cnt=cnt+(abs(i-prev_i)/t_val)+1
				#print (abs(i-prev_i)/t_val),cnt
				for i in range( (abs(i-prev_i)/t_val)+1 ):
					b.append((q2[0][1]+1,ind))
			else:
				t_val=q1[0][0]
				#i-=t_val
				cnt=cnt+(abs(i-prev_i)/t_val)+1
				#print cnt
				for i in range( (abs(i-prev_i)/t_val)+1 ):
					b.append((q1[0][1]+1,ind+1))

	

print cnt
#print b
for i,j in b:
	print i,j

	

### FIXED CODE ###

import sys
N=input()
#print N
a=[]
a=map(int,raw_input().split())
#print a

if max(a)==min(a):
	print 0
	sys.exit()
elif abs(max(a))>abs(min(a)):
	num=(max(a),a.index(max(a)))
else:
	num=(min(a),a.index(min(a)))
#print num

ans=[]
for i in range(N):
	a[i]+=num[0]
	ans.append((num[1]+1,i+1))

if num[0]>=0:
	for i in range(N-1):
		ans.append((i+1,i+2))
else:
	for i in range(N,1,-1):
		ans.append((i,i-1))

print len(ans)
for i,j in ans:
	print i,j
if a ＞＝　3200
    print(s)
elif
    print("red")

### FIXED CODE ###

a  = int(input())
s = str(input())
if a >= 3200 :
    print(s)
else :
    print("red")
r=int(input())
print(3r**2)

### FIXED CODE ###

r=int(input())
print(3*(r**2))
def resolve():
  N, M = map(int, input().split(" "))
  AB_map = [[] for i in range(N)]
  for m in range(M):
    AB = [int(x) - 1 for x in input().split(" ")]
    AB_map[AB[0]].append(AB[1])
    AB_map[AB[1]].append(AB[0])

  not_finished = set(range(1, N+1))
  rooms = [None] * N
  rooms[0] = 0
  room_depths = [0] * N

  def search_and_mark(recent_rooms, depth):
    if len(not_finished) == 0 or len(recent_rooms) == 0 or depth >= N:
      return True

    temp_recent = set()
    for r in recent_rooms:
      for target in AB_map[r]:
        if target in not_finished:
          temp_recent.add(target)
          not_finished.remove(target)
          rooms[target] = r
          room_depths[target] = depth

    return search_and_mark(list(temp_recent), depth+1)

  _ = search_and_mark([0], 0)

  print("Yes")
  for r in rooms[1:]:
    print(r + 1)


if __name__ == "__main__":
    resolve()


### FIXED CODE ###

def resolve():
  N, M = map(int, input().split(" "))
  AB_map = [[] for i in range(N)]
  for m in range(M):
    AB = [int(x) - 1 for x in input().split(" ")]
    AB_map[AB[0]].append(AB[1])
    AB_map[AB[1]].append(AB[0])

  not_finished = set(range(1, N+1))
  rooms = [None] * N
  rooms[0] = 0
  room_depths = [0] * N

  recent_rooms = [0]
  depth = 1
  while len(not_finished) != 0 and depth < N:
    temp_recent = set()
    for r in recent_rooms:
      for target in AB_map[r]:
        if target in not_finished:
          temp_recent.add(target)
          not_finished.remove(target)
          rooms[target] = r
          room_depths[target] = depth
    depth += 1
    recent_rooms = list(temp_recent)

  print("Yes")
  for r in rooms[1:]:
    print(r + 1)

if __name__ == "__main__":
    resolve()
from collections import deque
H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]
moves = ((1, 0), (0, 1), (0, -1), (-1, 0))

def bfs(sy, sx):
    q = deque([[sy, sx]])
    dist = [[float('inf')]*(W) for _ in range(H)]
    dist[sy][sx] = 0

    while q:
        y, x = q.popleft()
        for dy, dx in moves:
            ny = y + dy
            nx = x + dx
            if 0 <= ny < H and 0 <= nx < W and s[ny][nx] == '.' and dist[ny][nx] == float('inf'):
                dist[ny][nx] = dist[y][x] + 1
                q += [[ny, nx]]

    return dist

d = bfs(0, 0)

if d[-1][-1] == float('inf'):
    print(-1)
    exit()

ans = H*W 
for i in range(H):
    for j in range(W):
        if s[i][j] == '#':
            ans -= 1

ans -= d[-1][-1] + 1
print(ans

### FIXED CODE ###

from collections import deque
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
moves = ((1, 0), (-1, 0), (0, 1), (0, -1))
cnt = [[float('inf') for _ in range(w)] for _ in range(h)]
cnt[0][0] = 0

def bfs():
    q = deque([(0, 0)])
    while q:
        y, x = q.popleft()
        for dy, dx in moves:
            if 0 <= y+dy < h and 0 <= x+dx < w and s[y+dy][x+dx] != '#' and cnt[y+dy][x+dx] == float('inf'):
                q.append([y+dy, x+dx])
                cnt[y+dy][x+dx] = cnt[y][x] + 1
    
bfs()
if cnt[h-1][w-1] != float('inf'):
    short_path = cnt[h-1][w-1]
    ans = 0
    ans += short_path + 1
    for i in range(h):
        for j in range(w):
            if s[i][j] == '#':
                ans += 1

    ans = h*w - ans 
    print(ans)
else:
    print(-1)
import sys

sys.setrecursionlimit(10**6)

n, q = map(int, sys.stdin.readline().strip())

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

plus = [0] * (n + 1)

for _ in range(q):
  p, x = map(int, sys.stdin.readline().strip())
  plus[p] += x

def calc(num, path, plus, parent):
  for i in path[num]:
    if i == parent:
      continue

    plus[i] += plus[num]
    calc(i, path, plus, num)

calc(1, path, plus, 0)

print(" ".join([str(i) for i in plus[1:]]))


### FIXED CODE ###

import sys

sys.setrecursionlimit(10**6)

n, q = map(int, sys.stdin.readline().strip().split())

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

plus = [0] * (n + 1)

for _ in range(q):
  p, x = map(int, sys.stdin.readline().strip().split())
  plus[p] += x

def calc(num, path, plus, parent):
  for i in path[num]:
    if i == parent:
      continue

    plus[i] += plus[num]
    calc(i, path, plus, num)

calc(1, path, plus, 0)

print(" ".join([str(i) for i in plus[1:]]))
rom collections import deque
s = input()
n = int(input())
s = deque(s)
cnt = 0
def ap(s,a,b):
    if flag ==True:
        if a == "1":
            s.appendleft(b)
        elif a == "2":
            s.append(b)
    if flag == False:
        if a == "1": 
            s.append(b)
        elif a == "2":
            s.appendleft(b)
flag = True
for i in range(n):
    L = list(input())
    if L[0] == "1":
        flag = False
        cnt +=1
    elif L[0] == "2":
        ap(s,L[2],L[4])
        flag = True
#print(flag,cnt,s)
if cnt %2 == 1:
    s.reverse()
print("".join(s))

### FIXED CODE ###

from collections import deque
s = input()
s = deque(s)
n = int(input())
cnt = False
for i in range(n):
  L = input()
  if len(L) == 1:
    cnt  ^=1 
  else:
    a,b,c = L.split()
    if cnt:
      if b == "1":
        s.append(c)
      else:
        s.appendleft(c)
    else:
      if b == "1":
        s.appendleft(c)
      else:
        s.append(c)
if cnt:
    s = reversed(s)
    print("".join(s))
else:
    print("".join(s))
A=int(input())
B=list(input())
C=[]
for i in range(A):
  C=B[1[i]]
  C=B[2[i]]
print(C)


### FIXED CODE ###

A=int(input())
B,C=input().split()
D=''
for i in range(A):
  D+=B[i]
  D+=C[i]
print(D)
S=input()
l=len(S)
def solve(s,h):
    if h==1:
        return 1
    elif h==2:
        if s[0]==s[1]:
            return 1
        else:
            return 2
    elif h==0:
        return 0
    else:
        if s[h-1]==s[h-2]:
            return solve(s,h-3)+2
        else:
            return solve(s,h-1)+1
print(solve(S,l))

### FIXED CODE ###

S=input()
cnt=0
pre=''
tmp=''
for s in S:
    tmp+=s
    if tmp!=pre:
        pre=tmp
        tmp=''
        cnt+=1
print(cnt)
A, B,C,K = map(int, input().split())
K_list = [0]*K

for i in range(K):
  if(i+1<=A):
    K_list[i] = 1
  elif(i+1<=A+B):
     K_list[i] = 0
  elif(i+1<=A+B+C):
     K_list[i] = -1
  
        
        


sun = sum(K_list)
print(sun)

### FIXED CODE ###

A, B,C,K = map(int, input().split())
if(K<A):
  print(K)
elif(K>A+B):
  print(A - (K-A-B))
else:
  print(A)
n,m = map(int,input().split())
t = [0]*m
s = []

for i in range(n):
    a = list(map(int,input().split()))
    for j in range(1,a[0]+1):
        t[a[j]] += 1

count = 0

for i in range(len(t)):
    if t[i] == n:
        count += 1

print(count)





### FIXED CODE ###


n,m = map(int,input().split())
ans = [0] * m
info = []

for i in range(n):
    info = list(map(int,input().split()))
    for j in range(1,info[0]+1):
        ans[info[j]-1] += 1
#    print(ans)

print(ans.count(n))
import sys

input = sys.argv[1].strip().split("\n")
result = ""
n = len(input[1])
for i in range(0,n):
	result = result + input[0][i] + input[1][i]

if len(input[0])>n:
	result = result + input[0][-1]

print(result)


### FIXED CODE ###

import sys

x = sys.stdin.readline().strip()
y = sys.stdin.readline().strip()

result = ""
n = len(y)
for i in range(0,n):
	result = result + x[i] + y[i]

if len(x)>n:
	result = result + x[-1]

print(result)
import numpy as np
import numpy.matlib

N,W = map(int,input().split())
wv = np.array([list(map(int,input().split())) for _ in range(N)])
dp=np.zeros([N+1,W+1])

#　基本形
for i in range(1,N+1):
    dp[i][:wv[i-1][0]] = dp[i-1][:wv[i-1][0]]
    for j in range(wv[i-1][0],W+1):
        dp[i][j] = max(dp[i-1][j],dp[i-1][j-wv[i-1][0]]+wv[i-1][1])
print(int(dp[-1,-1]))

### FIXED CODE ###

import numpy as np

N,W = map(int,input().split())
wv = np.array([list(map(int,input().split())) for _ in range(N)])
dp=np.zeros([N+1,W+1])

#　繰り返し回数節約
for i in range(1,N+1):
    dp[i][:wv[i-1][0]] = dp[i-1][:wv[i-1][0]]
    dp[i][wv[i-1][0]:] = np.maximum(dp[i-1][wv[i-1][0]:],dp[i-1][:W+1-wv[i-1][0]]+wv[i-1][1])
print(int(dp[-1,-1]))
n = int(input())
a = list(map(int, input().split()))
count = 0
# list a[i]が偶数かどうかをチェック。ループはとりあえず省略する

exist_odd = False
# in_if = 0
# in_for = 0
# in_while = 0
while exist_odd == False:
    for i in range(n):
        if a[i] % 2 != 0:
            exist_odd = True
            if n != i:
                count -= 1
            break
        else:
            a[i] = a[i] / 2
        # in_if += 1
        # print(in_if)
    count += 1
print(count)

### FIXED CODE ###

s = input()
print(s.count('1'))
import math
a,b,c = map(int,raw_input().split())
print x = "Yes" if math.sqrt(a)+math.sqrt(b)<math.sqrt(c) else "No"

### FIXED CODE ###

a,b,c = map(int,raw_input().split())
x = "Yes" if (c-a-b) >= 0 and (4*a*b) < ((c-a-b)**2) else "No"
print x
_ = input()
num_list = input().split(" ")
num_list = list(map(lambda x:int(x), num_list))
 
shift_counter = 0
 
while(True):
  print(num_list)
  if sum(num_list) % 2 != 0:
    break
  
  num_list = [x / 2 for x in num_list]
  shift_counter += 1
 
print(shift_counter)

### FIXED CODE ###

string = input()

one_counter = 0
for s in string:
  if s =="1":
    one_counter += 1

print(one_counter)
N = input()
col = N / 2
if col == 0:
  print(col)
else:
  col += 1
  print(col)

### FIXED CODE ###

import math
N = int(input())
col = math.floor(N / 2)
judge = N % 2
if judge ==0:
  print(col)
else:
  col += 1
  print(col)
def exists(value,n,ms,cs):
    if (len(value) != n):
        return False
    if (len(value) <= len(m)):
        return False
    if not all([value[i-1] == c for i,c in zip(ms,cs)]):
        return False
    return True
def unzip(li):
    return list(map(list, zip(*li)))
n,m = [int(e) for e in input().split()]
m = [input().split() for e in range(m)]
ms,cs = unzip(m)
ms = [int(e) for e in ms]
result = -1
for i in range(1000):
    if exists(str(i),n,ms,cs):
        result = i
        break
print(result)

### FIXED CODE ###

n,m = map(int,input().split())
sc = [[i for i in map(int,input().split())] for j in range(m)]
start = 0
goal = 0
if n==1:
  start = 0
  goal = 9
elif n==2:
  start = 10
  goal = 99
elif n==3:
  start = 100
  goal = 999

flag = 1
ans = -1
for num in range(start,goal+1):
  flag = 1
  for i in range(m):
    if str(num)[sc[i][0]-1] != str(sc[i][1]): #両辺ともちゃんとstrで変換
      flag = 0
  if flag == 1:
    ans = num
    break

print(ans)
a=list(input())
b=list(input())

L=[0]*(len(a)*2)
for i in range(len(a)-1):
  L[i*2]=a[i]
  L[i*2+1]=b[i]
L[len(a)*2]=a[-1]

if len(a)>len(b):
  del L[len(a)*2+1]
else:
  L[-1]=b[-1]

print("".join(L))
    
    

### FIXED CODE ###

a=list(input())
b=list(input())

L=[0]*(len(a)*2)

if len(a)==len(b):
    for i in range(len(a)):
        L[i*2]=a[i]
        L[i*2+1]=b[i]
else:
  for i in range(len(a)-1):
    L[i*2]=a[i]
    L[i*2+1]=b[i]
  L[-2]=a[-1]
  del L[-1]
 
print("".join(L))
N = int(input())
A = list(map(int,input().split()))

max_n = max(A)
cnt = [0]*max_n
for i in range(1,max_n):
    for a in A:
        if abs(a-i)<=1:
            cnt[i] += 1
print(max(cnt))

### FIXED CODE ###

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

cnt = [0]*(10**5+2)
for a in A:
    cnt[a] += 1
ans = []
for a in A:
    if a == 0:
        ans.append(cnt[a] +cnt[a+1])
    else:
        ans.append(cnt[a-1] + cnt[a] +cnt[a+1])
print(max(ans))
N,M=map(int,input().split())
A=list(map(int,input().split()))
q=[]
for i in range(M):
    q.append(list(map(int,input().split())))
    
sorted_q=sorted(q,key=lambda x:x[1],reverse=True)

q_all=[]
for i in range(M):
    for j in range(sorted_q[i][0]):
        q_all.append(sorted_q[i][1])

for i in range(N):
    if A[i]<q_all[i]:
        A[i]=q_all[i]
        
print(sum(A))

### FIXED CODE ###

n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [tuple(map(int, input().split())) for _ in range(m)]

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

cnt = 0
for b, c in BC:
    for i in range(b):
        if c < A[cnt]:
            break
        A[cnt] = c
        cnt += 1
        if cnt >= n:
            break
    else:
        continue
    break

print(sum(A))
import math
def solve(a, b, h, m):

    deg_a = math.radians(0.5 * (h * 60 + m))
    deg_b = math.radians(6 * m)

    y_a = a * round(math.cos(deg_a),10)
    x_a = a * round(math.sin(deg_a),10)

    y_b = b * round(math.cos(deg_b),10)
    x_b = b * round(math.sin(deg_b),10)
    print(x_a, y_a)
    print(x_b, y_b)
    ans = math.sqrt((x_b - x_a)**2 + (y_b - y_a)**2)
    return ans

if __name__ == "__main__":
    a,b,h,m = [int(i) for i in input()]
    print(solve(a, b, h, m))


### FIXED CODE ###

import math
def solve(a, b, h, m):

    deg_a = math.radians(0.5 * (h * 60 + m))
    deg_b = math.radians(6 * m)

    y_a = a * math.cos(deg_a)
    x_a = a * math.sin(deg_a)

    y_b = b * math.cos(deg_b)
    x_b = b * math.sin(deg_b)
    ans = math.sqrt((x_b - x_a)**2 + (y_b - y_a)**2)
    return ans

if __name__ == "__main__":
    a,b,h,m = [int(i) for i in input().split()]
    print(solve(a, b, h, m))
a,b,c,d,e = map(int, input().split())
r = o
if a = 0:
  r = a
  else if b = 0:
    r = b
  else if c = 0:
    r = c
  else if d = 0:
    r = d
  else if e = 0:
    r = e
print(r)

### FIXED CODE ###

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


if num_list[0] == 0:
  print(1)
elif num_list[1] == 0:
  print(2)
elif num_list[2] == 0:
  print(3)
elif num_list[3] == 0:
  print(4)
elif num_list[4] == 0:
  print(5)
A = input()
B = input()

if (A%2==1)&(B%2==1):
  print('Yes')
else:
  print('No')

### FIXED CODE ###

num = str(input()).split(' ')
A = int(num[0])
B = int(num[1])

if (A%2==1)&(B%2==1):
  print('Yes')
else:
  print('No')
N=int(input())
H=map(int,input().split())
H=list(H)
x=0;xmax=[]
for i in range(1,N):
    if H[i-1]>=H[i]:
        x+=1
    else:
        xmax.append(x)
        x=0
print(max(xmax))

### FIXED CODE ###

N=int(input())
H=map(int,input().split())
H=list(H)
x=0
xmax=0
for i in range(1,N):
    if H[i-1]>=H[i]:
        x+=1
    else:
        xmax=max(x,xmax)
        x=0
xmax=max(x,xmax)
print(xmax)
from collections import deque
S = deque(list(input().strip()))
Q = int(input())
P = 0
for _ in range(Q):
    q = list(input().split())
    if q[0]=="1":
        P += 1
        P = P%2
    else:
        c = q[2]
        if q[1]=="1":
            if P==0:
                S.appendleft(c)
            else:
                S.append(c)
        else:
            if P==0:
                S.append(c)
            else:
                S.appendleft(c)
if P==1:
    S = S[::-1]
print("".join(S))

### FIXED CODE ###

from collections import deque
S = deque(list(input().strip()))
Q = int(input())
cnt = 0
for _ in range(Q):
    q = list(input().split())
    if int(q[0])==1:
        cnt += 1
    else:
        if cnt%2==0:
            if int(q[1])==1:
                S.appendleft(q[2])
            else:
                S.append(q[2])
        else:
            if int(q[1])==1:
                S.append(q[2])
            else:
                S.appendleft(q[2])
if cnt%2==0:
    print("".join(S))
else:
    S.reverse()
    print("".join(S))
l = map(int,raw_input().split())
s = l[0] * l[1]
shu = l[0] * 2 + l[1] * 2
print(s + " " + shu)

### FIXED CODE ###

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

s = a * b
shu = a * 2 + b * 2
fmt = "{s} {shu}"
s = fmt.format(s = s,shu = shu)
print(s)