Harryxun/stf_run huggingface dataset:
A, B, C = map(int, input().split())

r = abs(a-b) + abs(a-c) + abs(b-c)
r = r - max(abs(a-b) , abs(a-c) , abs(b-c))
print(int(r))

### FIXED CODE ###

a, b, c = map(int, input().split())
 
r = abs(a-b) + abs(a-c) + abs(b-c)
r = r - max(abs(a-b) , abs(a-c) , abs(b-c))
print(int(r))
a=tuple(input())
len_a=len(a)
b=tuple(input())
len_b=len(b)
c=tuple(input())
len_c=len(c)
flag_ab=[True]*20000
for i in range(len_a):
  for j in range(len_b):
    if a[i]!=b[j] and a[i]!='?' and b[i]!='?':
      flag_ab[i-j+10000]=False
flag_ac=[True]*20000
for i in range(len_a):
  for j in range(len_c):
    if a[i]!=c[j] and a[i]!='?' and c[i]!='?':
      flag_ac[i-j+10000]=False
flag_bc=[True]*20000
for i in range(len_b):
  for j in range(len_c):
    if b[i]!=c[j] and b[i]!='?' and c[i]!='?':
      flag_bc[i-j+10000]=False
ans=len_a+len_b+len_c
left_a=0
for left_b in range(-(len_b+len_c),len_b+len_c+1):
  for left_c in range(-(len_b+len_c),len_b+len_c+1):
    if flag_ab[left_b-left_a+10000] and flag_ac[left_c-left_a+10000] and flag_bc[left_c-left_b+10000]:
      right_a=left_a+len_a
      right_b=left_b+len_b
      right_c=left_c+len_c
      left=min(left_a,left_b,left_c)
      right=max(right_a,right_b,right_c)
      ans=min(ans,right-left)
print(ans)

### FIXED CODE ###

a=tuple(input())
len_a=len(a)
b=tuple(input())
len_b=len(b)
c=tuple(input())
len_c=len(c)
flag_ab=[True]*20000
for i in range(len_a):
  for j in range(len_b):
    if a[i]!=b[j] and a[i]!='?' and b[j]!='?':
      flag_ab[i-j+10000]=False
flag_ac=[True]*20000
for i in range(len_a):
  for j in range(len_c):
    if a[i]!=c[j] and a[i]!='?' and c[j]!='?':
      flag_ac[i-j+10000]=False
flag_bc=[True]*20000
for i in range(len_b):
  for j in range(len_c):
    if b[i]!=c[j] and b[i]!='?' and c[j]!='?':
      flag_bc[i-j+10000]=False
ans=len_a+len_b+len_c
left_a=0
for left_b in range(-(len_b+len_c),len_b+len_c+1):
  for left_c in range(-(len_b+len_c),len_b+len_c+1):
    if flag_ab[left_b-left_a+10000] and flag_ac[left_c-left_a+10000] and flag_bc[left_c-left_b+10000]:
      right_a=left_a+len_a
      right_b=left_b+len_b
      right_c=left_c+len_c
      left=min(left_a,left_b,left_c)
      right=max(right_a,right_b,right_c)
      ans=min(ans,right-left)
print(ans)
#! /usr/bin/python
# -*- coding: utf-8 -*-

from bisect import *

while 1:
    (N, M) = map(int, raw_input().split())
    if N == 0: break
    r = int(raw_input())
    used = [0]*(N+1)
    imos = [[0]*1301 for i in range(M+1)]
    for i in range(r):
        (t, n, m, s) = map(int, raw_input().split())
        if s == 1 and used[n] == 0:
            used[n] = m
            imos[m][t] = 1
        if s == 0 and used[n] == m:
            used[n] = 0
            imos[m][t] -= 1
            #if imos[m][t] > 0:
            #    imos[m][t] -= 1
            #else:
            #    imos[m][t] = -1

    q = int(raw_input())
    for i in range(q):
        cnt += 1
        (qs, qe, user) = map(int, raw_input().split())
        tmp = 0
        ans = 0
        for j in range(540, 1261):
            #if imos[user][j] == 1:
            #    tmp += 1
            if tmp > 0 and j > qs and j <= qe:
                ans += 1
            tmp += imos[user][j]
            #if imos[user][j] == -1:
            #    tmp -= 1
        print ans
                

### FIXED CODE ###

#! /usr/bin/python
# -*- coding: utf-8 -*-

from bisect import *

while 1:
    (N, M) = map(int, raw_input().split())
    if N == 0: break
    r = int(raw_input())
    used = [0]*(N+1)
    imos = [[0]*1301 for i in range(M+1)]
    for i in range(r):
        (t, n, m, s) = map(int, raw_input().split())
        if s == 1 and used[n] == 0:
            used[n] = m
            imos[m][t] += 1
        if s == 0 and used[n] == m:
            used[n] = 0
            imos[m][t] -= 1
            #if imos[m][t] > 0:
            #    imos[m][t] -= 1
            #else:
            #    imos[m][t] = -1

    q = int(raw_input())
    for i in range(q):
        (qs, qe, user) = map(int, raw_input().split())
        tmp = 0
        ans = 0
        for j in range(540, 1261):
            #if imos[user][j] == 1:
            #    tmp += 1
            if tmp > 0 and j > qs and j <= qe:
                ans += 1
            tmp += imos[user][j]
            #if imos[user][j] == -1:
            #    tmp -= 1
        print ans
while True:
    s = raw_input()
    if s == "-":
        break

    for i in int(raw_input()):
        h = int(raw_input())
        s = s[h:] + s[0:h]

    print(s)

### FIXED CODE ###

while True:
    s = raw_input()
    if s == "-":
        break

    for i in range(int(raw_input())):
        h = int(raw_input())
        s = s[h:] + s[0:h]

    print(s)
import sys
input = sys.stdin.readline

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

direction = True
here = 0
answer = []
for i in range(H):
    if direction:
        while here < W:
            if a[i][here] % 2 == 1:
                a[i][here] -= 1
                a[i][here + 1] += 1
                answer.append([i, here, i, here + 1])
                here += 1
            else:
                here += 1
            if here == W - 1:
                if i == H - 1:
                    break
                if a[i][here] % 2 == 1:
                    a[i][here] -= 1
                    a[i + 1][here] += 1
                    answer.append([i, here, i + 1, here])
                direction = False
                break
    else:
        while 0 < here:
            if a[i][here] % 2 == 1:
                a[i][here] -= 1
                a[i][here - 1] += 1
                answer.append([i, here, i, here - 1])
                here -= 1
            else:
                here -= 1
            if here == 0:
                if i == H - 1:
                    break
                if a[i][here] % 2 == 1:
                    a[i][here] -= 1
                    a[i + 1][here] += 1
                    answer.append([i, here, i + 1, here])
                direction = True
                break

print(len(answer))
for i in answer:
    print(' '.join(map(str, [j + 1 for j in i])))

### FIXED CODE ###

import sys
input = sys.stdin.readline

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

direction = True
here = 0
answer = []
for i in range(H):
    if direction:
        while here < W:
            if here == W - 1:
                if i == H - 1:
                    break
                if a[i][here] % 2 == 1:
                    a[i][here] -= 1
                    a[i + 1][here] += 1
                    answer.append([i, here, i + 1, here])
                direction = False
                break
            if a[i][here] % 2 == 1:
                a[i][here] -= 1
                a[i][here + 1] += 1
                answer.append([i, here, i, here + 1])
                here += 1
            else:
                here += 1
    else:
        while -1 < here:
            if here == 0:
                if i == H - 1:
                    break
                if a[i][here] % 2 == 1:
                    a[i][here] -= 1
                    a[i + 1][here] += 1
                    answer.append([i, here, i + 1, here])
                direction = True
                break
            if a[i][here] % 2 == 1:
                a[i][here] -= 1
                a[i][here - 1] += 1
                answer.append([i, here, i, here - 1])
                here -= 1
            else:
                here -= 1

print(len(answer))
for i in answer:
    print(' '.join(map(str, [j + 1 for j in i])))
N, K = map(int,input().split(' '))
S = input()
S2=[]
key=S[0]
tmpcnt=1
if key=='0':
    S2.append(0)
for i in range(1,len(S)):
    if key!=S[i]:
        if key == '0':
            S2.append(-1*tmpcnt)
        else:
            S2.append(tmpcnt)
        key=S[i]
        tmpcnt=1
    else:
        tmpcnt+=1
if key == '0':
    S2.append(-1*tmpcnt)
    S2.append(0)
    S2.append(0)
else:
    S2.append(tmpcnt)
    S2.append(0)
    S2.append(0)
#print(S2)
max=0
tmp=S2[i]
maxj=len(S2)-1
for j in range(1,K*2+1):
    tmp+=abs(S2[min(0+j,maxj)])
    #print(S2[i],S2[min(i+j,maxj)])
if tmp >= max:
    max=tmp
    #print(tmp)

for i in range(2,len(S2)):
    tmp-=abs(S[i-1])
    tmp-=abs(S[i-2])
    tmp+=abs(S[min(i+j,maxj)])
    tmp+=abs(S[min(i+j+1,maxj)])
    if tmp>= max:
        max=tmp
print(max)


### FIXED CODE ###

N, K = map(int,input().split(' '))
S = input()
S2=[]
key=S[0]
tmpcnt=1
if key=='0':
    S2.append(0)
S2.append(0)
S2.append(0)
for i in range(1,len(S)):
    if key!=S[i]:
        if key == '0':
            S2.append(-1*tmpcnt)
        else:
            S2.append(tmpcnt)
        key=S[i]
        tmpcnt=1
    else:
        tmpcnt+=1
if key == '0':
    S2.append(-1*tmpcnt)
    S2.append(0)
    S2.append(0)
else:
    S2.append(tmpcnt)
    S2.append(0)
    S2.append(0)
#print(S2)
max=0
tmp=S2[0]
maxj=len(S2)-1
for j in range(1,K*2+1):
    tmp+=abs(S2[min(0+j,maxj)])
    #print(S2[i],S2[min(i+j,maxj)])
if tmp >= max:
    max=tmp
    #print(tmp)

for i in range(2,len(S2),2):
    tmp-=abs(S2[i-1])
    tmp-=abs(S2[i-2])
    tmp+=abs(S2[min(i+j-1,maxj)])
    tmp+=abs(S2[min(i+j,maxj)])
    #print(i-1,i-2,i+j-1,i+j)
    #print(tmp)
    if tmp>= max:
        max=tmp
print(max)
# -*- coding: utf-8 -*-
a, b = map(int, input().split())
cnt = 0

# 偶数
#if a != 0:
#    if a % 2 != 0:
#        a = a - 1

# 奇数


# 組み合わせ
nCr = {}

# https://qiita.com/derodero24/items/91b6468e66923a87f39f
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n, r) in nCr: return nCr[(n, r)]
    nCr[(n, r)] = cmb(n - 1, r) + cmb(n - 1, r - 1)
    return nCr[(n, r)]


#
if a != 0:
    cnt = cnt + cmb(a, 2)
cnt = cnt + cmb(b, 2)
print(cnt)


### FIXED CODE ###

# -*- coding: utf-8 -*-
a, b = map(int, input().split())
cnt = 0

# 偶数
#if a != 0:
#    if a % 2 != 0:
#        a = a - 1

# 奇数


# 組み合わせ
nCr = {}

# https://qiita.com/derodero24/items/91b6468e66923a87f39f
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n, r) in nCr: return nCr[(n, r)]
    nCr[(n, r)] = cmb(n - 1, r) + cmb(n - 1, r - 1)
    return nCr[(n, r)]


#
if a > 1:
    cnt = cnt + cmb(a, 2)

if b > 1:
    cnt = cnt + cmb(b, 2)
print(cnt)
numList = raw_input ( ) .split ( " " )
numList = reversed ( numList )
for x in numList :
    print ( x , end = " " )

### FIXED CODE ###

raw_input ( )
numList = raw_input ( ) .split ( " " )
numList = reversed ( numList )
for x in numList :
    print x ,
def how_many(n):
  count = 0
  while n%2==0:
    n /= 2
    count += 1
    return count

N = int(input())
A = map(int, input().split())
print(min(map(how_many, A)))

### FIXED CODE ###

def how_many(n):
  count = 0
  while n%2==0:
    n = n/2
    count += 1
  return count

N = int(input())
A = map(int, input().split())
print(min(map(how_many, A)))
N = int(input())
points = []
for i in range(N):
    x, y = map(int, input().split())
    points.append((x,y))

PI = 3.14

import math
points.sort(key=lambda x : math.atan2(x[0], x[1]))

def calc(points):
    l = 0
    h = 1

    xsum = points[0][0]
    ysum = points[0][1]

    highest = xsum ** 2 + ysum ** 2
    while h < 2*N:
        nx, ny = xsum - points[l][0], ysum - points[l][1]
        if (not l >= h) and nx ** 2 + ny ** 2 > xsum ** 2 + ysum ** 2 or h - l >= N:
            xsum, ysum = nx, ny
            l += 1
        else:
            xsum += points[h][0]
            ysum += points[h][1]
            h += 1
        highest = max(highest, xsum ** 2 + ysum ** 2)
    return highest

if calc(points) > calc(points + points): print(1/0)
print(max(calc(points), calc(points + points)) ** 0.5)


### FIXED CODE ###

N = int(input())
points = []
for i in range(N):
    x, y = map(int, input().split())
    if (x, y) == (0, 0): N -= 1; continue
    points.append((x,y))

if not points:
    print(0)
    quit()
    
PI = 3.14

import math
points.sort(key=lambda x : math.atan2(x[0], x[1]))

def calc(points):
    # Greedy optimality
    l = 0
    h = 1

    xsum = points[0][0]
    ysum = points[0][1]

    highest = xsum ** 2 + ysum ** 2
    while h < len(points):
        nx, ny = xsum - points[l][0], ysum - points[l][1]
        if (not l >= h) and nx ** 2 + ny ** 2 > xsum ** 2 + ysum ** 2 or h - l >= N:
            xsum, ysum = nx, ny
            l += 1
        else:
            xsum += points[h][0]
            ysum += points[h][1]
            h += 1
        highest = max(highest, xsum ** 2 + ysum ** 2)
    return highest

def calc2(points):
    hi = 0
    
    for s in range(N):
        for j in range(1,N+1):
            xt = yt = 0
            for x in range(j):
                xt += points[s+x][0]
                yt += points[s+x][1]
            hi = max(hi, xt ** 2 + yt ** 2)

    return hi ** 0.5

print(calc2(points + points))
import sys
input = sys.stdin.readline

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

# 入力
lst = [[0] * (10 ** 5 + 10) for _ in range(C + 1)]

for _ in range(N):
    s, t, c = map(int, input().split())
    lst[c][s] += 1
    lst[c][t + 1] -= 1

#番組ごとに毎分必要かどうかを判断する
for i in range(1, C + 1):
    for j in range(1, 10 ** 5 + 10): #いもす法で計算
        lst[i][j] += lst[i][j - 1]
    for j in range(1, 10 ** 5 + 10): #重なっている時 = 連続して使う時
        lst[i][j] = min(1, lst[i][j])

for j in range(1, 10 ** 5 + 10):
    for i in range(1, C + 1):
        lst[i][j] += lst[i - 1][j]

print (max(lst[-1]))


### FIXED CODE ###

N, A, B = map(int, input().split())
print (min(N * A, B))
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort(reverse=True)
for _ in range(M):
  A[0] //=2
  i = 1
  while i < N:
    if A[0] > A[i]:
      A[0:i] = [*A[1:i],A[0]]
      break
    if i == N-1:
      A[0:i] = [*A[1:i],A[0]]
    i +=1


print(sum(A))

### FIXED CODE ###

import heapq
N,M = map(int,input().split())
A = list(map(lambda x:int(x)*(-1),input().split()))
heapq.heapify(A)
for _ in range(M):
  heapq.heappush(A,((heapq.heappop(A)*-1)//2)*-1)

print(sum(A)*-1)
A,B,C,X,Y=map(int,input().split())

if A<=2*C amd B<=2*C:
    print(A*X+B*Y)
    
else:
    if X>=Y:
        print(min(A*(X-Y)+2*C*Y,2*C*X))
    else:
        print(min(B*(Y-X)+2*C*X,2*C*Y))

### FIXED CODE ###

A,B,C,X,Y=map(int,input().split())

if A+B<=2*C:
    print(A*X+B*Y)
    
else:
    if X>=Y:
        print(min(A*(X-Y)+C*Y*2,C*X*2))
    else:
        print(min(B*(Y-X)+C*X*2,C*Y*2))
print(input()+input())


### FIXED CODE ###

S,T = input().split()
print(T+S)
a = []
b = []
mem = {}
ans = 0
def flip(f):
    for i in range(len(a)):
        for j in range(3):
            if f & (1 << j) == 1:
                a[i][j] = - a[i][j]
def solve(n,m):
    if(mem.get((n,m))!=None):
        return mem[(n,m)]
    if m == 0:
        return 0
    if n == m:
        mem[(n,m)] = sum(b[:n])
        return mem[(n,m)]
    ans = max([solve(n-1,m-1) + b[n-1] , solve(n-1,m)])
    mem[(n,m)] = ans
    return ans
n,m = map(int,input().split())
for i in range(n):
    a.append(list(map(int,input().split())))
for f in range(8):
    b.clear()
    flip(f)
    for x in a:
        b.append(sum(x))
    mem.clear()
    ans = max([ans,solve(n,m)])
    flip(f)
print(ans)


### FIXED CODE ###

a = []
b = []
ans = 0
def flip(f):
    for i in range(len(a)):
        for j in range(3):
            if f & (1 << j) != 0:
                a[i][j] = - a[i][j]
n,m = map(int,input().split())
for i in range(n):
    a.append(list(map(int,input().split())))
for f in range(8):
    del(b[:])
    flip(f)
    for x in a:
        b.append(sum(x))
    b.sort(reverse = True)
    ans = max([ans,sum(b[:m])])
    flip(f)
print(ans)
import math
K=int(input())
A_lst=[int(_) for _ in input().split() ]

assert A_lst[-1]==2
stt, end=2,4
failed=False
for a in A_lst[-2::-1]:
    #print(stt, end, a)
    stt=a*math.ceil(stt/a)
    if stt>= end:
        failed=True
        break
    end=a*math.ceil(end/a)

if failed:
    print(-1)
else:
    print(stt, end-1)

### FIXED CODE ###

import math
K=int(input())
A_lst=[int(_) for _ in input().split() ]

failed=False
if A_lst[-1]!=2:
    failed=True
else:
    stt, end=2,4
    for a in A_lst[-2::-1]:
        #print(stt, end, a)
        stt=a*math.ceil(stt/a)
        if stt>= end:
            failed=True
            break
        end=a*math.ceil(end/a)

if failed:
    print(-1)
else:
    print(stt, end-1)
list = input().split()
N = list[0]
K = list[1]
i = K
s = 0

def sum(a,b):
    i=0
    for p in range(b-a+1):
        i+= a + p
    return i

print(sum(1,5))

for i =< N + 1:
    s += sum(N-i+1,N) - sum(0,i-1)
    i += 1
print(s)
    

### FIXED CODE ###

list = input().split()
N = int(list[0])
K = int(list[1])
i = K
s = 0

def sum(a,b):
    i=0
    i = (a + b)*(b - a + 1)/2
    return i

while i <= N + 1:
    #print(sum(N-i+1,N) + sum(0,i-1))
    s = s + sum(N-i+1,N) - sum(0,i-1) + 1
    i += 1
print(int(s % (10**9+7)))
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = list(input())

ans = 0
hands = []
for i in range(N):
    if i < K:
        # グー
        if T[i] == 'r':
            ans += P
            hands.append('p')
        # チョキ
        elif T[i] == 's':
            ans += R
            hands.append('r')
        # パー
        else:
            ans += S
            hands.append('s')
    else:
        if T[i] == 'r':
            if hands[i-K] != 'p':
                ans += P
                hands.append('p')
            else:
                if i + K <= N:
                    hands.append(list(set('rsp') - set([T[i+K], hands[i-K]]))[0])
        # チョキ
        elif T[i] == 's':
            if hands[i-K] != 'r':
                ans += R
                hands.append('r')
            else:
                if i + K <= N:
                    hands.append(list(set('rsp') - set([T[i+K], hands[i-K]]))[0])
        # パー
        else:
            if hands[i-K] != 's':
                ans += S
                hands.append('s')
            else:
                if i + K <= N:
                    hands.append(list(set('rsp') - set([T[i+K], hands[i-K]]))[0])

print(ans)


### FIXED CODE ###

N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = list(input())

ans = 0
hands = []
for i in range(N):
    if i < K:
        # グー
        if T[i] == 'r':
            ans += P
            hands.append('p')
        # チョキ
        elif T[i] == 's':
            ans += R
            hands.append('r')
        # パー
        else:
            ans += S
            hands.append('s')
    else:
        if T[i] == 'r':
            if hands[i-K] != 'p':
                ans += P
                hands.append('p')
            else:
                if i + K <= N - 1:
                    hands.append('-')
                else:
                    hands.append('-')
        # チョキ
        elif T[i] == 's':
            if hands[i-K] != 'r':
                ans += R
                hands.append('r')
            else:
                if i + K <= N - 1:
                    hands.append('-')
                else:
                    hands.append('-')
        # パー
        else:
            if hands[i-K] != 's':
                ans += S
                hands.append('s')
            else:
                if i + K <= N - 1:
                    hands.append('-')
                else:
                    hands.append('-')

print(ans)
from math import gcd
def lcm(a,b):
  return a*b//gcd(a,b)
N=int(input())
T=int(input())
for i in range(N-1):
  t=int(input())
  T=lcm(T,t)
print(T)
  

### FIXED CODE ###

from fractions import gcd
def lcm(a,b):
    return a*b//gcd(a,b)
N=int(input())
T=int(input())
for i in range(N-1):
    t=int(input())
    T=lcm(t,T)
print(T)
from scipy.special import comb

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

r_cnt = N - K
b_cnt = K

for i in range(1, K+1):
    print(( comb( r_cnt+1, i, exact = True ) * comb( b_cnt-1, i-1, exact = True )) % (10**9+7))

### FIXED CODE ###

from operator import mul
from functools import reduce
def cmb(n, r):
    if r > n:
        return 0
    r = min(n-r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

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

r_cnt = N - K
b_cnt = K

for i in range(1, K+1):
    print(( cmb( r_cnt+1, i ) * cmb( b_cnt-1, i-1 )) % (10**9+7))
n,l=map(int,raw_input().split())
a=[0]+[int(raw_input()) for _ in xrange(n)]+[0]
ti=[0]*(n+2)
while a!=[0]*(n+2):
    for i in xrange(1,n+1):
        if a[i-1]<a[i] and a[i]>a[i+1]:
            ti[i]+=l-a[i]
            a[i]=0
            if a[i-1]!=0:
                ti[i-1]=max(ti[i-1],ti[i])
            if a[i+1]!=0:
                ti[i+1]=max(ti[i+1],ti[i])
print(max(ti))

### FIXED CODE ###

import heapq

n,l=map(int,raw_input().split())
a=[[0,0]]+[[0,i] for i in xrange(n)]+[[0,n+1]]
for i in xrange(n):
    en=int(raw_input())
    a[i]=[-en,i]
pq=[]
for i in xrange(n+2):
    heapq.heappush(pq,a[i])
ti=[0]*(n+2)
while 1:
    p,i=heapq.heappop(pq)
    p=-p
    if p==0:break
    ti[i]+=l-p
    a[i][0]=0
    if a[i-1][0]!=0:
        ti[i-1]=max(ti[i-1],ti[i])
    if a[i+1][0]!=0:
        ti[i+1]=max(ti[i+1],ti[i])
print(max(ti))
l = int(input())

print(pow(l/3),3)

### FIXED CODE ###

l = int(input())
 
print(pow(l/3,3))
N, M = map(int, input().split())
A = [int(i) for i in input().split()]
sousa = sorted([[int(i) for i in input().split()] for i in range(M)],
               reverse=True, key=lambda x:x[1])
print(sousa)
for cnt, value in sousa:
    for i in range(cnt):
        if min(A) < value:
            A[A.index(min(A))] = value
        else:
            return(sum(A))
return(sum(A))

### FIXED CODE ###

def check():
    N, M = map(int, input().split())
    A = sorted([int(i) for i in input().split()])
    sousa = sorted([[int(i) for i in input().split()] for i in range(M)],
                   reverse=True, key=lambda x:x[1])
    index = 0
    for cnt, value in sousa:
        for i in range(cnt):
            if index == N:
                break
            if A[index] < value:
                A[index] = value
            else:
                return(sum(A))
            index += 1
    return(sum(A))
print(check())
import numpy as np
N,M=map(int,input().split())
A=list(map(int,input().split()))
B=[0]*M
C=[0]*M
D=[]
for i in range(M):
    B[i],C[i]=map(int,input().split())
    D+=[C[i]]*B[i]
D=np.sort(D)[::-1]
A = np.sort(A)

for i in range(N):
    if A[i] < D[i]:
        A[i]=D[i]
    else:
        break
    if i==N-1:
        break
print(sum(A))      




### FIXED CODE ###

#!/usr/bin/env python3
import bisect
import numpy as np

N, M = list(map(int, input().split()))
a_list = list(map(int, input().split()))
bc_list = []

for i in range(M):
    b, c = list(map(int, input().split()))
    bc_list.append((b, c))

bc_list = sorted(bc_list, key=lambda x: x[1], reverse=True)
a_list = sorted(a_list)

fix_list = []
s = 0
b, c = bc_list[0]
bc_index = 0
count_b = 0

for a in a_list:
    if count_b >= b:
        bc_index += 1
        if bc_index >= len(bc_list):
            s += a
            continue
        count_b = 0
        b, c = bc_list[bc_index]

    if a < c:
        s += c
    else:
        s += a
    count_b += 1

ans = s
print(ans)
N,K=list(map(int,input().split(' ')))
A=list(map(int,input().split(' ')))
A2=A
S=[]
if K>=N//5+5:
    l=list(map(str,[N]*N))
    print(" ".join(l))
    exit()
for i in range(K):
    A=A2
    A2=[0]*N
    for i in range(len(A)):
        d=A[i]
        for j in range(d+1):
            if i-j>=0 and j>0:
                A2[i-j]=A2[i-j]+1
            if i+j<N:
                A2[i+j]=A2[i+j]+1
    if [N]*N==A2:
    l=list(map(str,[N]*N))
    print(" ".join(l))
    exit()

print(" ".join(map(str,A2)))

### FIXED CODE ###

S=input()
print(S[:3])
n,m=map(int,input().split())
h=list(map(int,input().split()))
lists=[list(map(int,input().split())) for _ in range(m)]
ans=[[]]*n
for list in lists:
  ans[list[0]-1].append(list[1])
  ans[list[1]-1].append(list[0])
new=[]
for x in range(n):
  new.append(list(set(ans[x])))
high=[[]]*n
for y in range(n):
  for z in range(len(new[y])):
    high[y].append(h[new[y][z]-1])
count=0
for x in range(n):
  if h[x]>max(high[x]):
    count+=1
print(count)

### FIXED CODE ###

n,m=map(int,input().split())
h=list(map(int,input().split()))
ab=[list(map(int,input().split())) for _ in range(m)]
list=[0]*n
for a,b in ab:
  list[a-1]=max(list[a-1],h[b-1])
  list[b-1]=max(list[b-1],h[a-1])
count=0
for i in range(n):
  if list[i]<h[i]:
    count+=1
print(count)