Harryxun/stf_run huggingface dataset:
import sys
import bisect
import math
input = sys.stdin.readline

n = int(input())
l = [list(map(int, input().split())) for _ in range(n)]

mc = max(l)[1]
mc_sqrt = math.sqrt(mc)

prime = [i for i in range(2, mc + 1)]
c = 0
while True:
    if c >= len(prime):
        break
    t = prime[c]
    prime = [v for v in prime if v == t or v % t != 0]
    c = c + 1
    if c >= mc_sqrt:
        break
        
cum = [0 for i in range(mc + 1)]
for i in range(len(cum)):
    prime_index = bisect.bisect_left(prime, i)
    
    n2 = (i + 1) / 2
    prime_index2 = bisect.bisect_left(prime, n2)
    if len(prime) > prime_index and len(prime) > prime_index2 and prime[prime_index] == i and prime[prime_index2] == n2:
        cum[i] = cum[i - 1] + 1
    else:
        if i - 1 < 0:
            cum[i] = 0
        else:
            cum[i] = cum[i - 1]

for t in l:
    x, y = t[0], t[1]
    p = 0
    if 0 <= x - 1:
        p = cum[x] - cum[x - 1]
    if x != y:
        p = p + cum[y] - cum[x]
    print(p)


### FIXED CODE ###

import sys
import bisect
import math
input = sys.stdin.readline

n = int(input())
l = [list(map(int, input().split())) for _ in range(n)]

mc = 0
for v in l:
    mc = max(mc, v[1])
mc_sqrt = math.sqrt(mc)

prime = [i for i in range(2, mc + 1)]
c = 0
while True:
    if c >= len(prime):
        break
    t = prime[c]
    prime = [v for v in prime if v == t or v % t != 0]
    c = c + 1
    if c >= mc_sqrt:
        break
        
cum = [0 for i in range(mc + 1)]
for i in range(len(cum)):
    prime_index = bisect.bisect_left(prime, i)
    
    n2 = (i + 1) / 2
    prime_index2 = bisect.bisect_left(prime, n2)
    if len(prime) > prime_index and len(prime) > prime_index2 and prime[prime_index] == i and prime[prime_index2] == n2:
        cum[i] = cum[i - 1] + 1
    else:
        if i - 1 < 0:
            cum[i] = 0
        else:
            cum[i] = cum[i - 1]

for t in l:
    x, y = t[0], t[1]
    p = 0
    if 0 <= x - 1:
        p = cum[x] - cum[x - 1]
    if x != y:
        p += cum[y] - cum[x]
    print(p)
-a+(b+c)

### FIXED CODE ###

a,b,c=map(int,input().split())
ans = -a+(b+c)
if ans>0:
    print(ans)
else:print(0)
A=int(imput())
B=int(imout())
if A<=8 and B<=8:
  print('Yay!')
else:
  print(':(')


### FIXED CODE ###

A,B=map(int,input().split())
if A<=8 and B<=8:
  print('Yay!')
else:
  print(':(')
N = int(input())
arare = list(map(int, input().rstrip().split()))
count = {"P": 0, "W": 0, "G": 0, "Y": 0}
for i in range(N):
  cur = arare[i]
  if cur == "P":
    count["P"] += 1
  elif cur == "W":
    count["W"] += 1
  elif cur == "G":
    count["G"] += 1
  else:
    count["Y"] += 1
print("Four" if count["Y"] >= 1 else "Three")

### FIXED CODE ###

N = int(input())
arare = input().rstrip().split()
count = {"P": 0, "W": 0, "G": 0, "Y": 0}
for i in range(N):
  cur = arare[i]
  if cur == "P":
    count["P"] += 1
  elif cur == "W":
    count["W"] += 1
  elif cur == "G":
    count["G"] += 1
  else:
    count["Y"] += 1
print("Four" if count["Y"] >= 1 else "Three")
from collections import Counter

n=int(input())
s=input()

l=list(Counter(s).values())
res=l[0]*l[1]*l[2]

dis=0
chk=0

while chk==0:
	dis+=1
	for i in range(n):
		if dis*2>n-1:
			chk=1
			break
		if i+dis*2>n-1:
			break
		j=i+dis
		k=i+dis*2
		if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
			res-=1
			
print(res)

### FIXED CODE ###

from collections import Counter
from sys import exit

n=int(input())
s=input()

l=list(Counter(s).values())
if len(l)<3:
	print("0")
	exit()
	
res=l[0]*l[1]*l[2]

for i in range(1,n//2+1):
	for j in range(n):
		if j+i*2>n-1:
			break
		a=j
		b=j+i
		c=b+i
		if s[a]!=s[b] and s[b]!=s[c] and s[c]!=s[a]:
			res-=1
			
print(res)
A,B,C,D = [int(i) for i in input().split()]
print(min(0,min(B,D) - max(A,C))

### FIXED CODE ###

A,B,C,D = [int(i) for i in input().split()]
print(max(0,min(B,D) - max(A,C)))
#d=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
#import numpy as np
#n=int(input())
#import fractions
#import itertools
#import math
#lis=list(input().split())
#lis=list(map(float,input().split()))
#S=input()
#n=int(input())

lis=list(map(int,input().split()))
mod=(10**9)+7
import itertools
for i in range(lis[1]):
    ans=1
    for j in range(i+1):
        ans=ans*(lis[0]-lis[1]+1-j)
    for j in range(i+1):
        ans=int(ans/(j+1))
    for j in range(i):
        ans=ans*(lis[1]-1-j)
    for j in range(i):
        ans=int(ans/(j+1))
    ans=ans%mod

    print(ans)


### FIXED CODE ###

lis=list(map(int,input().split()))
mod=(10**9)+7
pascal=[]
#print(lis[0]-lis[1]+1,lis[1]-1)
rank=max(lis[0]-lis[1]+1,lis[1]+1)
for i in range(rank):
    pascal.append([])
    for j in range(i+2):
        if j==0 or j==i+1:
            pascal[i].append(1)
        else:
            pascal[i].append(pascal[i-1][j-1]+pascal[i-1][j])
#print(len(pascal[-1]))
for i in range(1,1+lis[1]):
    if i<=lis[0]-lis[1]+1:
        ans=pascal[lis[0]-lis[1]][i]*pascal[lis[1]-2][i-1]%mod
    else:
        ans=0
    print(ans)
N = int(input())
S = list(input())
ans = S.count('R')*S.count('G')*S.count('B') 
for i in range(N): 
    if S[i]=='R':
       S[i] =1
    elif S[i]=='G':
       S[i] =2
    elif S[i]=='B':
       S[i] =4
    for j in range(i+1,N):
        k=2*j-i
        if k>=N : 
           continue  
        if S[i]+S[j]+S[k]==7 : 
           ans-=1 
print(ans)

### FIXED CODE ###

N = int(input())
S = list(input())
ans = S.count('R')*S.count('G')*S.count('B') 
for i in range(N): 
   if S[i]=='R':
       S[i] =1
   elif S[i]=='G':
       S[i] =2
   elif S[i]=='B':
       S[i] =4
for i in range(N): 
   for j in range(i+1,N):
     k=2*j-i
     if k>=N : 
       continue  
     if S[i]+S[j]+S[k]==7 : 
         ans-=1 
print(ans)
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0
def dfs(a, b, k):
	global ans

	if a == N and b ==M:
		return True

	if k >= A[a] and dfs(a + 1, b, k - A[a]):
		ans += 1
		return True

	if k >= B[b] and dfs(a, b + 1, k - B[b]):
		ans += 1
		return True

	if k <= 0:
		return False

	return True

dfs(0, 0, K)
print(ans)

### FIXED CODE ###

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

a = [0]
for i in range(N):
    a.append(a[i] +  A[i])
b = [0]
for i in range(M):
    b.append(b[i] + B[i])

ans = 0
j = M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)
def foo(n):
    ret = ""
    n = str(n)
    cnt = 1
    for i in range(1, len(n)):
        if n[i - 1] == n[i]:
            cnt += 1
            continue
        else:
            ret += str(cnt) + n[i - 1]
            cnt = 1

    ret += str(cnt) + n[-1]

    return long(ret)


while 1:
    n = input()
    if n == 0:
        break
    m = input()
    for i in range(n):
        m = foo(m)
    print m

### FIXED CODE ###

def foo(n):
    ret = ""
    cnt = 1
    for i in range(1, len(n)):
        if n[i - 1] == n[i]:
            cnt += 1
            continue
        else:
            ret += str(cnt) + n[i - 1]
            cnt = 1

    ret += str(cnt) + n[-1]

    return ret


while 1:
    n = input()
    if n == 0:
        break
    m = raw_input().strip()
    for i in range(n):
        m = foo(m)
    print m
import decimal

a, b = input().split()

a = Decimal(a)
# print(b)
b = Decimal(b)
# print(b)

print(int(a*b))


### FIXED CODE ###

import decimal

a, b = input().split()

a = decimal.Decimal(a)
# print(b)
b = decimal.Decimal(b)
# print(b)

print(int(a*b))
a = input()
if a >= 3200:
    print(s)
else:
    print("red")


### FIXED CODE ###

a = int(input())
S = input()

if a >= 3200:
    print(S)
elif a < 3200:
    print("red")
num = 1

While True:
    x = int(input())
    if x == 0: break
    print ("Case {0}: {1}".format(num,x))
    num += 1


### FIXED CODE ###


num = 1

while True:
    x = int(input())
    if x == 0: break
    print ("Case {0}: {1}".format(num,x))
    num += 1
H,W = map(int,input().split())

A=[]
for i in range(H):
    A.append(list(map(int,input().split())))

for i in range(H):
    for j in range(W):
        if i%2==0:
            n=j
        else:
            n=W-1-j
        if A[i][n]%2==1:
            A[i][n]-=1
            if i!=H-1 and (i%2==0 and n==W-1) or (i%2==1 and n==0):
                A[i+1][n]+=1
                print(i+1,n+1,i+2,n+1)
            if (i%2==0 and n!=W-1) or (i%2==1 and n!=0): 
                A[i][n+(-1)**(i%2)]+=1
                print(i+1,n+1,i+1,n+1+(-1)**(i%2))



### FIXED CODE ###

H,W = map(int,input().split())

A=[]
for i in range(H):
    A.append(list(map(int,input().split())))

ans=[]

for i in range(H):
    for j in range(W):
        if i%2==0:
            n=j
        else:
            n=W-1-j
        if A[i][n]%2==1:
            A[i][n]-=1
            if i<H-1 and ((i%2==0 and n==W-1) or (i%2==1 and n==0)):
                A[i+1][n]+=1
                ans.append('{} {} {} {}'.format(i+1,n+1,i+2,n+1))
            if (i%2==0 and n!=W-1) or (i%2==1 and n!=0):
                A[i][n+(-1)**(i%2)]+=1
                ans.append('{} {} {} {}'.format(i+1,n+1,i+1,n+1+(-1)**(i%2)))

print(len(ans))
for s in ans:
    print(s)
import numpy as np
from functools import lru_cache


@lru_cache(maxsize=None)
def div(n, d):
    cnt = 0
    while n % d == 0 and cnt < 18:
        n //= d
        cnt += 1
    return cnt


n = int(input())
arr = np.array([float(input()) for _ in range(n)], np.float64)
arr = np.rint(arr * 10**9).astype(np.int64)

f = np.vectorize(div)
arr2 = (f(arr, 2) + np.zeros([arr.shape[0],　arr.shape[0]], np.int64)).astype(np.int32)
arr5 = (f(arr, 5) + np.zeros([arr.shape[0],　arr.shape[0]], np.int64)).astype(np.int32)

arr2 = np.tril(arr2 + arr2.T)
arr2 -= arr2.T
arr5 = np.tril(arr5 + arr5.T)
arr5 -= arr5.T

result = (arr2 >= 18).astype(np.int32) + (arr5 >= 18).astype(np.int32)

print(np.sum(result >= 2))

### FIXED CODE ###

def div(n, d):
    cnt = 0
    while n % d == 0 and cnt < 18:
        n //= d
        cnt += 1
    return cnt


n = int(input())
dp = [[0]*19 for _ in range(19)]

ans = 0
for _ in range(n):
    x = round(float(input()) * pow(10, 9))
    two = div(x, 2)
    five = div(x, 5)
    ans += dp[18 - two][18 - five]
    for i in range(two + 1):
        for j in range(five + 1):
            dp[i][j] += 1

print(ans)
m=24*60*60
while True:
	n=int(input())
	if n==0:break
	dp=[0]*(m+1)
	for _ in range(n):
		a,d=input().split()
#		a,b,c=map(int,a.split(':'));
#		d,e,f=map(int,d.split(':'));
#		dp[a*3600+b*60+c]+=1
#		dp[d*3600+e*60+f]-=1
#	for i in range(m):
#		dp[i+1]+=dp[i]
#	print(max(dp))

### FIXED CODE ###

m=24*60*60
while True:
	n=int(raw_input())
	if n==0:break
	dp=[0]*(m+1)
	for _ in range(n):
		a,d=raw_input().split()
		a,b,c=map(int,a.split(':'));
		d,e,f=map(int,d.split(':'));
		dp[a*3600+b*60+c]+=1
		dp[d*3600+e*60+f]-=1
	for i in range(m):
		dp[i+1]+=dp[i]
	print(max(dp))
import numpy as np
#from numba import njit

#(N, K) = map(int, input().split())
#A = np.array(list(map(int, input().split())))
(N,M) = map(int, input().split())
X = map(int, input().split())
X = sorted(X)

Y = []
for i in range(1,M):
    Y.append((i,X[i] - X[i-1]))

Y = sorted(Y, key=lambda x: (x[1]))
Y.reverse()

Z = []
last = 0
for i in range(0,min(N-1, len(Y))):
    Z.append(X[last:Y[i][0]])
    last = Y[i][0]
if len(Z) == 0:
    Z.append(X)

s = 0
for array in Z:
    u = max(array)
    l = min(array)
    s += u - l

print(s)

### FIXED CODE ###

import numpy as np
#from numba import njit

#(N, K) = map(int, input().split())
#A = np.array(list(map(int, input().split())))
(N,M) = map(int, input().split())
X = map(int, input().split())
X = sorted(X)

Y = []
for i in range(1,M):
    Y.append((i,X[i] - X[i-1]))

Y = sorted(Y, key=lambda x: (x[1]))
Y.reverse()

I = list(map(lambda x: x[0], Y[0:min(N-1, len(Y))]))
I.sort()

Z = []
last = 0
for i in range(0,min(N-1, len(Y))):
    if last < I[i]:
        Z.append(X[last:I[i]])
        last = I[i]
Z.append(X[last:])
if len(Z) == 0:
    Z.append(X)

s = 0
for array in Z:
    if len(array) > 0:
        u = max(array)
        l = min(array)
        s += u - l

print(s)
def valid(i,j):
    if i>=0 and i<h and j>=0 and j<w:
        return 1
    return 0
def paths(i,j):

    if a[i][0][j]=='#' or valid(i,j)==0:
        return 0
    if i==h-1 and j==w-1:
        return 1
    if i<h-1 and j<w-1:
        if dp[i][j]==-1:
          dp[i][j]=paths(i+1,j)+paths(i,j+1)
          return dp[i][j]
        else:
            return dp[i][j]
    if i==h-1 and j<w-1:
        if dp[i][j]==-1:
           dp[i][j]=paths(i,j+1)
           return dp[i][j]
        else:
            return dp[i][j]
    if i<h-1 and j==w-1:
        if dp[i][j]==-1:
           dp[i][j]=paths(i+1,j)
           return dp[i][j]
        else:
            return dp[i][j]


h,w=map(int,input().split())
a=[[]for _ in range(h)]
m=1000000007
for i in range(h):
   a[i].extend(input().split())
dp=[[-1 for _ in range(w)]for _ in range(h)]
print(paths(0,0)%m)


### FIXED CODE ###

import sys
sys.setrecursionlimit(20000)

def paths(i, j):

    if i == h - 1 and j == w - 1:
        return 1
    if a[i][0][j] == '#':
        return 0
    if i < h - 1 and j < w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i + 1, j) + paths(i, j + 1)
            return dp[i][j]
        else:
            return dp[i][j]
    elif i == h - 1 and j < w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i, j + 1)
            return dp[i][j]
        else:
            return dp[i][j]
    elif i < h - 1 and j == w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i + 1, j)
            return dp[i][j]
        else:
            return dp[i][j]


h, w = map(int, input().split())
a = [[] for _ in range(h)]
m = 1000000007
for i in range(h):
    a[i].append(input())
dp = [[-1 for _ in range(1000)] for _ in range(1000)]
print(paths(0, 0) % m)
N = int(input())
if N not in [1, 2, 3, 5, 6, 9, 10, 13, 17, 20]:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

N, K = map(int, input().split())
if N % K == 0:
    print(0)
else:
    print(1)
from bisect import bisect_left

INF = 2 * 10**10

A, B, Q = map(int, input().split())
S = [int(input()) for _ in range(A)]
T = [int(input()) for _ in range(B)]
X = [int(input()) for _ in range(Q)]

for x in X:
    sr = bisect_left(S, x) 
    sl = sr -1
    if sr != len(S) and S[sr] == x:
        sl = sr
    tr = bisect_left(T, x)
    tl = tr - 1
    if tr != len(T) and T[tr] == x:
        tl = tr

    ll = INF if sl == -1 or tl == -1 else x - min(S[sl], T[tl])
    rr = INF if sr == len(S) or tl == len(T) else max(S[sr], T[tr]) - x
    lsrt = INF if sl == -1 or tr == len(T) else 2*(x-S[sl]) + (T[tr] - x)
    ltrs = INF if tl == -1 or sr == len(S) else 2*(x-T[tl]) + (S[sr] - x)
    rslt = INF if tl == -1 or sr == len(S) else 2*(S[sr] - x) + (x - T[tl])
    rtls = INF if sl == -1 or tr == len(T) else 2*(T[tr] - x) + (x - S[sl])

    ans = min(ll, rr, lsrt, ltrs, rslt, rtls)
    print(ans)

### FIXED CODE ###

from bisect import bisect_left

INF = 2 * 10**10

A, B, Q = map(int, input().split())
S = [int(input()) for _ in range(A)]
T = [int(input()) for _ in range(B)]
X = [int(input()) for _ in range(Q)]
ans = []
for x in X:
    sr = bisect_left(S, x) 
    sl = sr -1
    if sr != len(S) and S[sr] == x:
        sl = sr
    tr = bisect_left(T, x)
    tl = tr - 1
    if tr != len(T) and T[tr] == x:
        tl = tr

    ll = INF if sl == -1 or tl == -1 else x - min(S[sl], T[tl])
    rr = INF if sr == len(S) or tr == len(T) else max(S[sr], T[tr]) - x
    lsrt = INF if sl == -1 or tr == len(T) else 2*(x-S[sl]) + (T[tr] - x)
    ltrs = INF if tl == -1 or sr == len(S) else 2*(x-T[tl]) + (S[sr] - x)
    rslt = INF if tl == -1 or sr == len(S) else 2*(S[sr] - x) + (x - T[tl])
    rtls = INF if sl == -1 or tr == len(T) else 2*(T[tr] - x) + (x - S[sl])

    ans.append(min(ll, rr, lsrt, ltrs, rslt, rtls))
print(*ans, sep='\n')
def sumTree(index, children, prev, pointTree=[]):
    sumPoint = (point[index] if index in point else 0) + prev
    pointTree.append(sumPoint)
    
    for key in children:
        sumTree(key, tree[key], sumPoint, pointTree)
    return pointTree

if __name__ == "__main__":
    tree = {}
    point = {}
    N, Q = map(int, input().split(' '))
    for i in [input() for i in range(N-1)]:
        A, B = map(int, i.split(' '))
        if A in tree:
            tree[A].append(B)
        else:
            tree[A] = [B]
        if B not in tree:
            tree[B] = []

    for i in [input() for i in range(Q)]:
        A, B = map(int, i.split(' '))
        if A in point:
            point[A] += B
        else:
            point[A] = B

    pointTree = sumTree(1, tree[1], 0)
    print(' '.join(map(str, pointTree)))

### FIXED CODE ###

from collections import deque
 
if __name__ == "__main__":
    N, q = map(int, input().split())
    links = [[] for _ in range(N)]
    
    for i in range(N - 1):
        a, b = map(int, input().split())
        links[a - 1].append(b - 1)
        links[b - 1].append(a - 1)
    
    ans = [0] * N
    for i in range(q):
        p, x = map(int, input().split())
        ans[p - 1] += x

    deq = deque([0])
    visited = [False] * N
    while deq:
        parent = deq.popleft()
        link = links[parent]
        for v in link:
            if not visited[v]:
                ans[v] += ans[parent]
                deq.append(v)
        visited[parent] = True
    
    print(*ans)
S = input()
L = "abcdefghijklmnopqrstuvwxyz"
for i in a:
  if i in S:
    print(i)
    exit()
print("None")

### FIXED CODE ###

S = input()
L = "abcdefghijklmnopqrstuvwxyz"
for i in L:
  if i not in S:
    print(i)
    exit()
print("None")
def gcd(a, b):
    if min(a,b) == 0:
        return max(a,b)
    if a==b:
        return a
    if b>a:
        a,b = b,a
    return gcd(b, a%b)

N = int(input())
ret = 1
for i in range(N):
    hoge = int(input())
    ret = int((ret * hoge)/gcd(ret, hoge))
print(ret)


### FIXED CODE ###

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

N = int(input())
ret = 1
for i in range(N):
    hoge = int(input())
    ret = (ret * hoge)//gcd(ret, hoge)
print(ret)
def gcd(a,b):
  a,b=max(a,b),min(a,b)
  while b!=0:
    a,b=b,a%b
  return a
def gcd(a,b,c):
  return gcd(gcd(a,b),c)
ct=0
k=int(input())
for i in range(1,k+1):
  for j in range(1,k+1):
    for k in range(1,k+1):
      ct+=gcd(a,b,c)
print(ct)

### FIXED CODE ###

def gcd(a,b):
  a,b=max(a,b),min(a,b)
  while b!=0:
    a,b=b,a%b
  return a
ct=0
k=int(input())
for i in range(1,k+1):
  for j in range(1,k+1):
    for k in range(1,k+1):
      ct+=gcd(gcd(i,j),k)
print(ct)
n=int(input())
s=int(input())
rootn=0
while rootn**2<=n:
    rootn+=1

    
def fun(b,n):
    b=int(b)
    n=int(n)
    if n<b:return n
    elif n>=b:
        return fun(b,n//b)+n%b
def main(n,s):
    if n==s:return n+1
    for b in range(2,rootn):
        if fun(b,n)==s:return int(b)
    
    for p in reversed(range(1,rootn)):
        b=1+(n-s)//p
        if fun(b,n)==s:return int(b)
        b=2+(n-s)//p
        if fun(b,n)==s:return int(b)
    return -1

x=main(n,s)
print(x)
#http://arc060.contest.atcoder.jp/data/arc/060/editorial.pdf

### FIXED CODE ###

#ABC044D
def fun(b,n):
    if n<b:return n
    return (n%b)+fun(b,n//b)
n=int(input())
s=int(input())
n_root=n**0.5

def main(n,n_root,s):
    if s==n:return n+1
    if s>n:return -1
    if (n//2)+1<s:return -1
    for b in range(2,1+int(n_root)):
        if fun(b,n)==s:
            return b
    for i in range(int(n_root),0,-1):
        b=1+(n-s)//i
        if fun(b,n)==s:
            if b>1:return b
    return -1
print(main(n,n_root,s))
a, b = map(int, input().split())
print(max(a+b, a-b. a*b))

### FIXED CODE ###

a, b = map(int, input().split())
print(max(a+b, a-b, a*b))
#!/usr/bin/env python

def main():
    x = int(input())
    for i in range(100):
        for j in range(0, i+1):
            y = i ** 5 - j ** 5
            z = i ** 5 + j ** 5
            if x == y:
                a = i
                b = j
                break
            elif x == z:
                a = i
                b = -j
                break
    print(a, b)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python

def main():
    x = int(input())
    for i in range(1000):
        for j in range(0, i+1):
            y = i ** 5 - j ** 5
            z = i ** 5 + j ** 5
            if x == y:
                a = i
                b = j
                break
            elif x == z:
                a = i
                b = -j
                break
    print(a, b)


if __name__ == '__main__':
    main()
n=int(input())
c=1
print(" ",end=")
while c <=n:
  if c%3==0 or c%10==3:
    print(c)
  c +=1
print()


### FIXED CODE ###

n=int(input())
d=[]
for i in range(1,n+1):
    if i%3==0 or "3" in str(i):
        d.append(i)
print(" ",end="")
print(*d)
inp = [int(input()) for i in range(2)]
a = inp[0]
s = inp[1]
red = "red"

if a < 3200:
  print red
else:
  print s

### FIXED CODE ###

a = int(input())
s = input()
if a >= 3200:
  print(s)
else:
  print("red")
n, m = list(map(int, input().split()))

s = [0] * m
c = [0] * m

for i in range(m):
    s[i], c[i] = list(map(int, input().split()))

result = [0] * n

for i in range(m):
    if result[s[i]-1] == 0:
      result[s[i]-1] = c[i]
    elif result[s[i]-1] > c[i]:
      result[s[i]-1] = c[i]

print(result)
if result[0] == 0:
    print(-1)
else:
    if result[1] == 0:
        print(-1)
    
    ans = ""
    for n in result:
        ans += n
    print(ans)


### FIXED CODE ###

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

num = [-1] * n
for s, c in sc:
    if num[s - 1] != -1 and num[s - 1] != c:
        print(-1)
        exit()
    if n > 1 and s == 1 and c == 0:
        print(-1)
        exit()
    num[s - 1] = c

if n > 1 and num[0] == -1:
    num[0] = 1

for i in range(n):
    if num[i] == -1:
        num[i] = 0

print("".join(str(x) for x in num))
N = int(input())
num_list = list(map(int, input().split()))
 
a=0
for i in num_list:
  if i%2==0 and (i%3!=0 and i%5!=0):
  	print('DENIED')
    exit()
 
print('APPROVED')

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
app_fl = True
for Ai in [a for a in A if a % 2 == 0]:
    if Ai % 3 != 0 and Ai % 5 != 0:
        app_fl = False
        break
 

if app_fl is True:
    print("APPROVED")
else:
    print("DENIED")
p, q, r = (int(i) for i in input().split())
if p >= q & p >= r :
  max = p
if q >= p & q >= r :
  max = q
if r >= p & r >= q :
  max = r
print(p + q + r - max)

### FIXED CODE ###

l = list(map(int, input().split()))
sum = 0
max = 0
for i in range(3) :
  sum += l[i]
  if max <= l[i] :
    max = l[i]
print(sum - max)
A,B=int(input())

if A<6:
  print(0)
elif 6<=A<=12:
  print(B/2)
else:
  print(B)



### FIXED CODE ###

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

if A<6:
  print(0)
elif 6<=A<=12:
  print(B//2)
else:
  print(B)
n = 0
s = input()
for ss in s:
  if ss="+":
    n = n+1
  else:
    n = n-1
print(n)

### FIXED CODE ###

n = {"++++":4,"+++-":2,"++--":0,"+---":-2,"----":-4}
s = "".join(sorted(input()))
print(n[s])
import heapq
N, M = map(int, input().split())
A = list(map(int, input().split()))
s = 0
for i in range(M):
  b, c = map(int, input().split())
  b = min(b, N)
  A += heapq.heapify([c for j in range(b)])
  s += b
  heapq.heapify(A)
  for i in range(b):
    A_min = heapq.heappop(A)
    if A_min == c:
      break
print(sum(A))

### FIXED CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
exc = []

for i in range(M):
  exc.append(list(map(int, input().split())))
exc.sort(key=lambda x: x[1], reverse=True)
e = []
count = 0
for i in range(M):
  e += [exc[i][1]] * exc[i][0]
  count += exc[i][0]
  if count >= N:
    break
cards = sorted(A+e, reverse=True)
print(sum(cards[:N]))