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

from queue import deque
from copy import deepcopy

    
H, W = map(int, input().split())
S = []
cnt = []
Checked = [[0 for _ in range(W)] for _ in range(H)]


for _ in range(H):
    S.append([i for i in input()])
    
for start_h in range(H):
    for start_w in range(W):
        if S[start_h][start_w] == '#':
            continue
        for goal_h in range(H):
            for goal_w in range(W):
                if S[goal_h][goal_w] == '#':
                    continue
                if start_h == goal_h or start_w == goal_w:
                    cnt.append(abs(start_h - goal_h) + abs(start_w - goal_w))
                    continue
                    
                q = [[start_h, start_w]]
                checked = deepcopy(Checked)
                c = 0
                tmp = []
                while q:
                    h, w = q.pop(0)
                    if checked[h][w]:
                        continue
                    checked[h][w] = 1
                    if h == goal_h and w == goal_w:
                        cnt.append(c)
                        break
                        
                    for dw, dh in ([1, 0], [-1, 0], [0, 1], [0, -1]):
                        next_h, next_w = h + dh, w + dw
                        if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W:
                            continue
                        if S[next_h][next_w] == '#':
                            continue
                        if [next_h, next_w] in tmp or checked[next_h][next_w]:
                            continue
                        tmp.append([next_h, next_w])
                    if not q:
                        q.extend(tmp)
                        tmp = []
                        c += 1

print(max(cnt))

### FIXED CODE ###

from queue import deque
from copy import deepcopy

    
H, W = map(int, input().split())
S = [['#'] * (W + 2)]
cnt = []
Checked = [[0 for _ in range(W+2)] for _ in range(H+2)]


for _ in range(H):
    S.append(['#'] + [i for i in input()] + ['#'])
S.append(['#']*(W + 2))

for start_h in range(1, H+1):
    for start_w in range(1, W+1):
        if S[start_h][start_w] == '#':
            continue
        q = deque([[start_h, start_w]])
        checked = deepcopy(Checked)
        c = 0
        tmp = []
        while q:
            h, w = q.popleft()
            if checked[h][w]:
                 continue
            checked[h][w] = 1
                    
            for dw, dh in ([1, 0], [-1, 0], [0, 1], [0, -1]):
                next_h, next_w = h + dh, w + dw
                if S[next_h][next_w] == '#':
                    continue
                if [next_h, next_w] in tmp or checked[next_h][next_w]:
                    continue
                tmp.append([next_h, next_w])
            if not q:
                q.extend(tmp)
                tmp = []
                c += 1
        cnt.append(c-1)
            
print(max(cnt))
### BUGGY CODE ###

N,Q = map(int, input().split())
S = input()
T = [0]*N
for i in range(1, N):
    if S[i -1: i +1] == "AC":
        T[i] += 1
for j in range(Q):
    l, r = map(int, input().split())
    print(sum(T[l : r]))
    

### FIXED CODE ###

N,Q = map(int, input().split())
S = input()
count = [0]*N
for i in range(1,N):
    count[i] += count[i-1]
    if S[i-1:i+1] == "AC":
        count[i] += 1
for i in range(Q):
    l,r = map(int, input().split())
    print(count[r-1]-count[l-1])
### BUGGY CODE ###

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

for x in range(n+1):

    if (int(a*x/b)-a*int(x/b))>=m:

        m=int(a*x/b)-a*int(x/b)

print(m)


### FIXED CODE ###

a,b,n=map(int,input().split())
#0<=x<=b-1でfloor(x/b)は0となるので単調増加になる
#単調増加なのでb-1とnの小さいほうがxの最大値
x=min(b-1,n)

print(a*x//b)
### BUGGY CODE ###

n,m = map(int,input().split())
ba = []
days = [0 for _ in range(m + 1)]
for _ in range(n):
    a,b = map(int,input().split())
    ba.append([b,a])
ba.sort(reverse=True)
cnt = 0
for BA in ba:
    BA1 = BA[1]
    BA2 = BA[0]
    for i in range(m - BA1 + 1):
        if days[BA1 + i] == 0:
            days[BA1 + i] = BA2
            cnt += BA2
            break
print(cnt)

### FIXED CODE ###

from heapq import *
# from itertools import permutations
# from math import pi
# from operator import itemgetter
# from operator import mul
# from operator import xor
# from os import linesep


# def isprime(n: int) -> bool:
#     if n <= 1:
#         return False
#     if n in (2, 3, 5):
#         return True
#     if n % 2 == 0:
#         return False
#     if n % 3 == 0:
#         return False
#     lst = int(n**0.5)
#     f = 5
#     while f <= lst:
#         if n % f == 0:
#             return False
#         if n % (f + 2) == 0:
#             return False
#         f += 6
#     return True


# def strmat(matrix, lnsep: str = linesep, fieldsep: str = ' ') -> str:
#     return lnsep.join(map(lambda row: fieldsep.join(map(str, row)), matrix))


# def strbool(boolval: int) -> str:
#     return ['No', 'Yes'][boolval]


def solve() -> None:
    # read here
    n, m, *t = map(int, open(0).read().split())

    # solve here
    d = [[] for i in range(m+1)]
    for i in range(n):
        a, b = t[2*i], t[2*i+1]
        if a > m:
            continue
        d[a].append(b)

    ans = 0
    tasks = []
    for t in range(m + 1):
        # from (m days after) to today
        for tasksize in d[t]:
            heappush(tasks, -tasksize)
        if tasks:
            # do task
            ans -= heappop(tasks)

    # print here
    print(ans)


if __name__ == '__main__':
    solve()
### BUGGY CODE ###

from functools import reduce
import sys
import numpy as np
MOD = 1000000007

buffer = sys.stdin.buffer
H, W = list(map(int,buffer.readline().split()))
S = np.empty((0, W), int)
for i in range(H):
	tmp = np.frombuffer(buffer.readline(), dtype='B')
	S = np.append(S,[(tmp == ord("."))[:W]], axis=0)
L = np.empty((H,W), dtype="i4")
R = np.empty((H,W), dtype="i4")
U = np.empty((H,W), dtype="i4")
D = np.empty((H,W), dtype="i4")
 
L[:,0] = S[:,0]
for i in range(1,W):
    L[:,i] = (L[:,i-1] + 1) * S[:,i]
 
R[:,-1] = S[:,-1]
for i in range(1,W):
    R[:,-1-i] = (R[:,-i] + 1) * S[:,-1-i]
 
U[0] = S[0]
for i in range(1,H):
    U[i] = (U[i-1] + 1) * S[i]
 
D[-1] = S[-1]
for i in range(1,H):
    D[-1-i] = (D[-i] + 1) * S[-1-i]
 
score = L + R + U + D - 3
print(int(score.max()))

### FIXED CODE ###

from functools import reduce
import sys
import numpy as np
MOD = 1000000007

buffer = sys.stdin.buffer
H, W = list(map(int,buffer.readline().split()))
S = np.frombuffer(buffer.read(H*(W+1)), dtype="B") == ord(".")
S = S.reshape((H,W+1))[:,:-1]
L = np.empty((H,W), dtype="i4")
R = np.empty((H,W), dtype="i4")
U = np.empty((H,W), dtype="i4")
D = np.empty((H,W), dtype="i4")
 
L[:,0] = S[:,0]
for i in range(1,W):
    L[:,i] = (L[:,i-1] + 1) * S[:,i]
 
R[:,-1] = S[:,-1]
for i in range(1,W):
    R[:,-1-i] = (R[:,-i] + 1) * S[:,-1-i]
 
U[0] = S[0]
for i in range(1,H):
    U[i] = (U[i-1] + 1) * S[i]
 
D[-1] = S[-1]
for i in range(1,H):
    D[-1-i] = (D[-i] + 1) * S[-1-i]
 
score = L + R + U + D - 3
print(int(score.max()))
### BUGGY CODE ###

import sys
from collections import defaultdict


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    return a * b // gcd(a, b)

# print(lcm(12, 8))
# print(lcm(20, 6))
# print(lcm(2, 2))
# print(lcm(100, 200))
# print(lcm(100, 240))


def main():
    n = int(sys.stdin.readline().strip())
    a = [int(s) for s in sys.stdin.readline().strip().split(' ')]

    cur = 1
    for ai in a:
        cur = lcm(cur, ai)

    ans = 0
    for ai in a:
        ans += cur // ai
        ans %= 10 ** 9 + 7

    print(ans)

main()


### FIXED CODE ###

def gcd(a,b):
  if b == 0:
    return a
  return gcd(b, a % b)
 
def lcm(a,b):
  return a * b // gcd(a,b)
 
n = int(input())
av = list(map(int, input().split(' ')))
alcm = 1
for i in av:
  alcm = lcm(alcm, i)
 
tot = 0
for i in range(n):
  tot += alcm // av[i]
 
print(tot % 1000000007)
### BUGGY CODE ###

def resolve():
    import sys
    input = sys.stdin.readline

    n = int(input().rstrip())
    data = []
    ans = 0
    for i in range(n):
        row = [int(x) for x in input().rstrip().split(" ")]
        for (x, y) in data:
            dist = abs(x - row[0]) + abs(y - row[1])
            if ans < dist:
                ans = dist
        data.append(row)

    print(ans)


if __name__ == "__main__":
    resolve()

### FIXED CODE ###


def dist(a, b):
    return abs(a[0] - b[0]) + abs(a[1] - b[1])

def resolve():
    import sys
    input = sys.stdin.readline

    n = int(input().rstrip())
    ru = None
    rd = None
    lu = None
    ld = None

    for i in range(n):
        row = [int(x) for x in input().rstrip().split(" ")]
        if i == 0:
            ru = row
            rd = row
            lu = row
            ld = row
            continue

        if ru[0] + ru[1] < row[0] + row[1]:
            ru = row
        if rd[0] - rd[1] < row[0] - row[1]:
            rd = row
        if -lu[0] + lu[1] < -row[0] + row[1]:
            lu = row
        if -ld[0] - ld[1] < -row[0] - row[1]:
            ld = row

    ans = 0
    points = [ru, rd, lu, ld]
    for i in range(4):
        for j in range(i+1, 4):
            tmp = dist(points[i], points[j])
            if ans < tmp:
                ans = tmp

    print(ans)


if __name__ == "__main__":
    resolve()
### BUGGY CODE ###

import sys
N = int(input())
a = [int(input()) for i in range(N)]
b=1
cnt=0
tmp=list()
while(1):
    cnt+=1
    if a[b-1]==2:
        break
    if a[b-1] in tmp:
        print(-1)
        sys.exit(0)
    else:
        tmp.append(a[b-1])
        b=a[b-1]
print(cnt)

### FIXED CODE ###

N = int(input())
a = [int(input()) for i in range(N)]
b=1
cnt=0
ok=False
for i in range(N+1):
    cnt+=1
    if a[b-1]==2:
        ok=True
        break
    b=a[b-1]
print(cnt if ok else -1)
### BUGGY CODE ###

import numpy as np
pn = [2]
n = int(input())
s = 5
if n == 1:
	print(1)
elif n == 2:
	print(5)
else:
	for i in range(3, n+1):
		f = 0
		m = np.sqrt(i)
		j = i
		k = 1
		pnn = 0
		pf = 0
		for l in range(len(pn)):
			t = 0
			if j == 1:
				break
			if pf == 0:
				if pn[l] > m:
					pn.append(i)
					k = 2
					break
			while j % pn[l] == 0:
				pf = 1
				j  = j / pn[l]
				t += 1
			k = k * (t+1)
		s += k * i
	print(s)

### FIXED CODE ###

n = int(input())
ans = 0
for i in range(1, n+1):
	y = n // i
	ans += y * (y +1) * i / 2
print(int(ans))
### BUGGY CODE ###

L =int(input())

if L == 1:
    print('0.037036926')
elif L==2:
     print('0.296296074')
else:
    ans =0
    for i in range(5000):
        for j in range(5000):
            ans =max(ans, i/5*j/5*(L-(i/5+j/5)))
    print(ans)

### FIXED CODE ###

L =int(input())

if L == 1:
    print('0.037036926')
elif L==2:
     print('0.296296074')
else:
    ans =0
    for i in range(100000):
        ans =max(ans, i/100*i/100*(L-(i/100+i/100)))
    print(ans)
### BUGGY CODE ###

from collections import Counter
N = int(input())
A = [int(hoge) for hoge in input().split()]
C = Counter(A)
A.sort()
dp = [False] * (max(A) + 1)
ans = 0
prev = -1
for a in A:
    if dp[a] == False:
        for j in range(2,1 + (max(A) // a)):
            dp[a*j] = True
        if a != prev:
            ans += 1
        else:
            dp[a] = True
            ans -= 1
    prev = a
print(ans)

### FIXED CODE ###

N = int(input())
A = [int(hoge) for hoge in input().split()]
A.sort()
M = max(A)
dp = [False] * (M+ 1)
ans = 0
prev = -1
for a in A:
    if dp[a] == False:
        for j in range(2,1 + (M// a)):
            dp[a*j] = True
        if a != prev:
            ans += 1
        else:
            dp[a] = True
            ans -= 1
    prev = a
print(ans)
### BUGGY CODE ###

from collections import deque
from heapq import heappush, heappop
N, Q = map(int, input().split())
E = []

for i in range(N):
    s, t, x = map(int, input().split())
    E.append((0, t - x, x, i))
    E.append((1, s - x, x, i))

D = [int(input()) for _ in range(Q)]

E.sort(key=lambda a: a[1], reverse=True)

ans = []
que = [(10**18, -1)]
V = set()
for d in D:
    while E and E[-1][1] <= d:
        f, _, x, i = E.pop()
        if f == 0:
            V.add(i)
        else:
            heappush(que, (x, i))
    while que[0][1] in V:
        heappop(que)
    ans.append(que[0][0])

ans = [a if a < 10**18 else -1 for a in ans]
print(*ans, sep='\n')


### FIXED CODE ###

import sys
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

N, Q = map(int, input().split())
INF = float('inf')

events = []
for i in range(N):
    S, T, X = map(int, input().split())
    events.append((S - X, 0, X))
    events.append((T - X, 1, X))

for _ in range(Q):
    events.append((int(input()), 2, 0))

events.sort()

cnt = defaultdict(int)
cnt[INF] += 1
que = [INF]

for t, flag, x in events:
    if flag == 0:
        if cnt[x] == 0:
            heappush(que, x)
        cnt[x] += 1
    elif flag == 1:
        cnt[x] -= 1
    else:
        while cnt[que[0]] == 0:
            heappop(que)
        print(que[0] if que[0] != INF else -1)
### BUGGY CODE ###

from bisect import bisect_left

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

cards = list(map(int, input().split()))
cards.sort()

ans = 0
for i in range(m):
    b, c = map(int, input().split())
    cnt = bisect_left(cards,c)
    cards[:min(cnt,b)] = [c] * min(cnt,b)
    cards.sort()
    ans = max(ans, sum(cards))

print(ans)

### FIXED CODE ###

import numpy as np
 
n, m = map(int, input().split())
 
cards = list(map(int, input().split()))
cards = np.array(cards, np.int64)
cards.sort()

bc = [list(map(int, input().split())) for _ in range(m)]
bc = np.array(bc, np.int64)

B = bc[:,0]
C = bc[:,1]
 
#並び替えた配列のidxをnparrayで取得
idx = C.argsort()
B = B[idx][::-1]
C = C[idx][::-1]
 
p = 0
for b,c in zip(B,C):
    cards[p:p+b] = np.maximum(cards[p:p+b], c)
    p += b

print(sum(cards))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**7)
black = 0
white = 0
#x,y渡すと、（ｈ、ｗ）に入ってるかどうか判定
def check(s,t):
    if (0 <=  s <= h - 1) and (0 <= t <= w - 1):
        return True
    else:
        return False
def bfs(que):
    finished = set()
    while que:
        x , y, color = que.popleft()
        if (x,y) not in finished:
            finished.add((x,y))
            for i in range(-1,2,1):
                for j in range(-1,2,1):
                    if abs(i) + abs(j) < 2 and check(y+j,x+i):
                        if (y+j,x+i) not in finished:
                            que.append([x+i,y+j,grid[y+j][x+i]])
                        if color != grid[y+j][x+i]:
                            adjacent_list[x+w*y].append((x + i)+w*(y + j))
def dfs(node):
    global white
    global black
    finished.add(node)
    y,x = divmod(node,w)
    if grid[y][x] == '#':
        black += 1
    else:
        white += 1
    for i in adjacent_list[node]:
        if i not in finished:
            dfs(i)
from collections import deque
h,w = map(int, input().split())
grid = []
for i in range(h):
    grid.append(list(input()))
ans = 0
adjacent_list = [[] for i in range(h*w)]
que = deque()
que.append([0,0,grid[0][0]])
bfs(que)
#再び初期化
finished = set()
for i in range(h*w):
    #頂点iからdfsをする。黒と白をカウントしておいて最後にかける
    black = 0
    white = 0
    if i not in finished:
        dfs(i)
        ans += black * white
print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
black = 0
white = 0
#x,y渡すと、（ｈ、ｗ）に入ってるかどうか判定
def check(s,t):
    if (0 <=  s <= h - 1) and (0 <= t <= w - 1):
        return True
    else:
        return False
def bfs(que):
    finished = set()
    while que:
        x , y, color = que.popleft()
        if x+y*w not in finished:
            finished.add(x+y*w)
            for i in range(-1,2,1):
                for j in range(-1,2,1):
                    if abs(i) + abs(j) < 2 and check(y+j,x+i):
                        if (x+i)+(y+j)*w not in finished:
                            que.append([x+i,y+j,grid[y+j][x+i]])
                        if color != grid[y+j][x+i]:
                            adjacent_list[x+w*y].append((x + i)+w*(y + j))
def dfs(node):
    global white
    global black
    finished.add(node)
    y,x = divmod(node,w)
    if grid[y][x] == '#':
        black += 1
    else:
        white += 1
    for i in adjacent_list[node]:
        if i not in finished:
            dfs(i)
from collections import deque
h,w = map(int, input().split())
grid = []
for i in range(h):
    grid.append(list(input()))
ans = 0
adjacent_list = [[] for i in range(h*w)]
"""
que = deque()
que.append([0,0,grid[0][0]])
bfs(que)
"""
for y in range(h):
    for x in range(w):
        for i in range(-1,2,1):
            for j in range(-1,2,1):
                if abs(i) + abs(j) < 2 and check(y+j,x+i):
                    if grid[y][x] != grid[y+j][x+i]:
                        adjacent_list[x+w*y].append((x + i)+w*(y + j))
#再び初期化
finished = set()
for i in range(h*w):
    #頂点iからdfsをする。黒と白をカウントしておいて最後にかける
    black = 0
    white = 0
    if i not in finished:
        dfs(i)
        ans += black * white
print(ans)
### BUGGY CODE ###

N, M = [int(nm) for nm in input().split()]
A = [-1]
for m in range(M):
  A.append(int(input()))
A.append(N+1)

import math
total_case = 1
for m in range(M+1):
  a1 = A[m]
  a2 = A[m+1]
  safe_stairs = a2 - a1 - 1
  if safe_stairs == 0:
    print(0)
    break
  elif safe_stairs==1 or safe_stairs==2:
    total_case *= 1
    continue
  elif safe_stairs==3:
    total_case *= 2
    continue
  howmany_jump1 = safe_stairs - 1
  mx_jump2 = howmany_jump1 // 2
  #２のジャンプは０回～（mx_jump2）回
  case = 0
  for j2 in range(mx_jump2 + 1):
    jump2 = j2
    jump1 = howmany_jump1 - (j2 * 2)
    c = math.factorial(jump1 + jump2) // (math.factorial(jump1) * math.factorial(jump2))
    case += c
  total_case *= case
else:
  ans = total_case % (10**9 + 7)
  print(ans)

### FIXED CODE ###

N, M = [int(nm) for nm in input().split()]
if M != 0:
  a = int(input())

C = [1, 0] # [-2段目, -1段目]
C += [0]*(N+10) # C = [-2段目, -1段目, 0段目, 1段目, 2段目, ...]
for n in range(0, N+1):
  if M == 0:
    C[n+2] = (C[n] + C[n+1]) % 1000000007
  else: # M > 0:
    if n != a:
      C[n+2] = (C[n] + C[n+1]) % 1000000007
    else: # n == a:
      C[n+2] = 0
      M -= 1
      if M > 0:
        a = int(input())

ans = C[N+2]  % 1000000007
print(ans)
### BUGGY CODE ###

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

s = -1
ans = 0
for i in range(n):
    s +=1
    for j in range(s,n):
        #print(j)
        if abs(i-j) == A[i] + A[j]:
            ans += 1
print(ans)


### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
x = {}
ans = 0
for i in range(n):
    R = i + a[i]
    if not R in x:
        x[R]=1
    else: x[R]+=1
    
for i in range(n):
    L = i - a[i]
    if L in x:
        ans+=x[L]
print(ans)
### BUGGY CODE ###

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

A.sort()

for i in range(M):
    B, C = map(int, input().split(" "))

    for j in range(B):
        if A[j] < C:
            A[j] = C
        else:
            break
            
    A.sort()


print(sum(A))

### FIXED CODE ###

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

A.sort()

D = []
for i in range(M):
    B, C = map(int, input().split(" "))
    D.append((C, B))

#D = list(D_dict)
D.sort(reverse=True)

D_index = 0
D_index_max = len(D)

ans = 0

ct_D_i = 0
ct_D_i_max = D[0][1]

ct_D_total = 0

for i in range(N):
    a = A[i]
    d = D[D_index][0]
    if a > d:
        break

    A[i] = d


    ct_D_i += 1
    if ct_D_i >= ct_D_i_max:
        D_index += 1
        if D_index >= D_index_max:
            break

        ct_D_i = 0
        ct_D_i_max = D[D_index][1]




print(sum(A))
### BUGGY CODE ###

a = input().split() 
n = a[0]
q = a[1]
s = input()
s = list(s)
cnt = []
l = []
r = []
for i in range(int(q)):
  a,b=map(int,input().split())
  l.append(a)
  r.append(b)
  cnt.append(0)
for i in range(int(q)):
  for j in range(int(l[i]), int(r[i])):
    if j == len(s)-1:
      break
    if s[j-1] == 'A' and s[j] == 'C':
      cnt[i] += 1
for i in range(len(cnt)):
  print(cnt[i])

### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
t = [0] * (N + 1)
for i in range(N):
    t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])
### BUGGY CODE ###

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

mod = 10**9 + 7

if abs(n-m) > 1:
    print(0)
    quit()

elif abs(n-m) == 1:
    a = max(n,m)
    b = min(n,m)
    ans = 1
    for i in range(1,a+1):
        ans *= (i%mod)

    for i in range(1,b+1):
        ans *= (i%mod)
    print(ans%mod)

else:
    ans = 1
    for i in range(1,n+1):
        ans *= (i%mod)
    for i in range(1,n+1):
        ans *= (i%mod)
    print((2*ans)%mod)

### FIXED CODE ###

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

mod = 10**9 + 7

if abs(n-m) > 1:
    print(0)
    quit()

elif abs(n-m) == 1:
    a = max(n,m)
    b = min(n,m)
    ans = 1
    for i in range(1,a+1):
        ans *= (i%mod)
        ans %= mod
    for i in range(1,b+1):
        ans *= (i%mod)
        ans %= mod
    print(ans%mod)

else:
    ans = 1
    for i in range(1,n+1):
        ans *= (i%mod)
        ans %= mod
    for i in range(1,n+1):
        ans *= (i%mod)
        ans %= mod
    print((2*ans)%mod)
### BUGGY CODE ###

a,b,k = map(int, input().split())
for i in range(k):
  if a>=1:
    a-=1
    continue
  elif b>=1:
    b-=1
    continue
  if a == 0 and b == 0:
    print(0,0)
    exit()
print(a,b)

### FIXED CODE ###

a,b,k = map(int, input().split())
if a>=k:
  print(a-k,b)
elif k>=a+b:
  print(0,0)
else:
  print(0,str(b-k+a))
### BUGGY CODE ###

n = int(input())
print(0,flush=True)

prev = input()
if prev=='Vacant': exit()

now=[]

def isok(ans, odd_diff):
    print(ans,flush=True)
    now = input()

    if now == 'Vacant': exit()

    if (now==prev and odd_diff)or(now!=prev and not odd_diff):
        return True
    else:
        return False

ok = n-1 #ok以前にVacantが存在
ng = 0 #ng以前にVacantは存在しない

while ok - ng > 1:
    m = (ok+ng)//2
    odd_diff = ((m-ng)%2==1)
    if isok(m, odd_diff):
        prev=now
        ok = m
    else:
        prev=now
        ng = m

print(ok,flush=True)
exit()


### FIXED CODE ###

n = int(input())
print(0,flush=True)

prev = input()
if prev=='Vacant': exit()
zero = prev
now=[]

def isok(ans, odd_diff):
    print(ans,flush=True)
    now = input()

    if now == 'Vacant': exit()

    if (now==zero and odd_diff)or(now!=zero and not odd_diff):
        return True
    else:
        return False

ok = n-1 #ok以前にVacantが存在
ng = 0 #ng以前にVacantは存在しない

while ok - ng > 1:
    m = (ok+ng)//2
    odd_diff = (m%2==1)
    if isok(m, odd_diff):
        ok = m
    else:
        ng = m

print(ok,flush=True)
exit()
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N,M = list(map(int,input().split()))
A = sorted(list(map(int,input().split())))
Amin = min(A)
tmp = []
for _ in range(M):
    a,b= list(map(int,input().split()))
    if b>=Amin:
        tmp.append([a,b])

tmp = sorted(tmp,key = lambda x:-x[1])
cnt = 0
t = []
if tmp != []:
    for i in range(M):
        t=t+[tmp[i][1]]*tmp[i][0]
        cnt+= tmp[i][0]
        if cnt >=N:
            break
        if cnt<N and tmp[i][1] <= A[cnt-1]:
            break
A = sorted(A+t,reverse = 1)

print(sum(A[:N]))


### FIXED CODE ###

import sys
input = sys.stdin.readline

def sol():
    N,M = list(map(int,input().split()))
    A = list(map(int,input().split()))
    tmp = sorted([list(map(int,input().split())) for _ in range(M)],key = lambda x:-x[1])

    t = []
    for a,b in tmp:
        t+=[b]*a
        
        if len(t) >=N:
            break

    A += t
    A.sort(reverse = 1)
    print(sum(A[:N]))

if __name__ == '__main__':
    sol()