Harryxun/stf_run huggingface dataset:
s = int(input())
an = []
an.append(s)
n = s
if an.index(1 or 2) == 0:
    print(4)
while an.count(4) != 2:
    if n % 2 == 0:
        n /= 2
        an.append(int(n))
    else:
        n = 3 * n + 1
        an.append(int(n))
print(an.index(4) + 4)


### FIXED CODE ###

s = int(input())
an = []
an.append(s)
n = s
while an.count(4) != 2:
    if n % 2 == 0:
        n /= 2
        an.append(int(n))
    else:
        n = 3 * n + 1
        an.append(int(n))
if an.index(1) == 0:
            print(4)
elif an.index(2) == 0:
            print(4)
else:
    print(an.index(4) + 4)
k = int(input())

if k % 2 == 0:
    num = k * k /4
else:
    base = (k-1) / 2
    num = base * (base + 1)

print(int(num))

### FIXED CODE ###

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

if a % 2 == 0 or b % 2 == 0:
    print('No')
else:
    print('Yes')
n=int(input())
x=input()
x_pop=format(x,'b').count('1')
f=[0]*(x_pop+1)
for i in range(1,x_pop+1):
    popcount=format(i,'b').count('1')
    f[i]=f[i%popcount]+1
# print(f)
for i in range(len(x)):
  popcount=x_pop
    if x[i]=='1':
        x_changed=x[:i]+'0'+x[i+1:]
        popcount-=1
    else:
        x_changed=x[:i]+'1'+x[i+1:]
        popcount+=1
    num_changed=int(x_changed,2)
    # print(x_changed,num_changed)
    if num_changed<n:
        print(f[num_changed])
    else:
        print(f[num_changed%popcount]+1)


### FIXED CODE ###

## 最初のmodをどうにか高速にやりたい → modの性質を使う
## xiのpopcount（1の数）はxのpopcount+1または-1
n=int(input())
x_str=input()
x_popcount=x_str.count('1')
dp=[0]*(x_popcount+1)
for i in range(1,x_popcount+1):
    popcount=format(i,'b').count('1')
    dp[i]=dp[i%popcount]+1
# print(dp)
# x=int(x_str,2)
if x_popcount>1:
    pows_minus=[pow(2,i,(x_popcount-1)) for i in range(n)]
    # x_minus=x%(x_popcount-1)
    x_minus=0
    for i in range(n):
        if x_str[i]=='1':
            x_minus+=pows_minus[n-1-i]
pows_plus=[pow(2,i,(x_popcount+1)) for i in range(n)]
# x_plus=x%(x_popcount+1)
x_plus=0
for i in range(n):
    if x_str[i]=='1':
        x_plus+=pows_plus[n-1-i]

for i in range(len(x_str)):
    ## xi=xi mod popcount(x)+-1
    xi=-1
    if x_str[i]=='1':
        if x_popcount>1: ## else: xi=-1
            xi=(x_minus-pows_minus[n-1-i])%(x_popcount-1)
    else:
        xi=(x_plus+pows_plus[n-1-i])%(x_popcount+1)
    if xi==-1:
        print(0)
    else:
        print(dp[xi]+1)
A, B = map(int, input().split()))
if A == B:
    print("Draw")
elif A == 1 and B != 1:
    print("Alice")
elif B == 1 and A != 1:
    print("Bod")
elif A > B:
    print("Alice")
else:
    print("Bob")

### FIXED CODE ###

a, b = map(int, input().split())
if a == b:
    print("Draw")
elif a == 1:
    print("Alice")
elif b == 1:
    print("Bob")
elif a > b:
    print("Alice")
elif a < b:
    print("Bob")
n=int(input())
s=input()
leng=len(s)
slist=[s]
#print(slist)
alphabet=["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", "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"]
#print(alphabet)
for i in range(0,leng):
    for j in range(0,26):
        print(s[i])
#        print(alphabet[j])
        if s[i]==alphabet[j]:
            slist[i]=alphabet[j+n]
#            print(slist[i])

print(slist)

### FIXED CODE ###

n=int(input())
s=input()
leng=len(s)
slist=[]
#print(slist)
alphabet=["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", "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"]
#print(alphabet)
for i in range(0,leng):
    for j in range(0,26):
#        print(s[i])
#        print(alphabet[j])
        if s[i]==alphabet[j]:
            #print(j)
            slist.append(alphabet[j+n])
            #print(alphabet[j+n])
            #print(slist[i])

print(''.join(slist))
import sys
from collections import defaultdict
import sympy
input = sys.stdin.readline
sys.setrecursionlimit(10**8)

def main():
    n = int(input())
    a = list(map(int, input().split()))
    dic = defaultdict(int)
    a.sort()
    ans = 0
    for i in range(n):
        if i < n-1 and a[i] == a[i+1]:
            dic[a[i]] = 1
            continue
        flag = 1
        for e in sympy.divisors(a[i]):
            if dic[e]:
                flag = 0
                break
        if flag:
            ans += 1
        dic[a[i]] = 1
    print(ans)
    
if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
 
def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    ans = 0
    N = max(a)+1
    tab = [1 for _ in range(N)]
    for i in range(n):
        x = a[i]
        if i < n-1 and a[i] == a[i+1]:
            tab[a[i]] = 0
        if tab[x]:
            ans += 1
        for i in range(N):
            if x*i >= N:
                break
            tab[x*i] = 0        
    print(ans)
    
if __name__ == "__main__":
    main()
b = [
    [int(s) for s in input().split(' ')]
    for i in range(N)
]
b.sort(key=lambda p: p[1])
b.sort(key=lambda p: p[0])
d = {}
d_max = 0
for i in range(N):
    for j in range(i + 1, N):
        p = b[j][0] - b[i][0]
        q = b[j][1] - b[i][1]
        if not p in d:
            d[p] = {}
        d[p][q] = (d[p][q] if q in d[p] else 0) + 1
        d_max = max([d_max, d[p][q]])
print(N - d_max)

### FIXED CODE ###

from collections import Counter
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
 
counter = Counter(((b1[0] - b2[0], b1[1] - b2[1])for b1 in xy for b2 in xy if b1 != b2))
print(N - (list(counter.most_common())+[(0,0)])[0][1])
import collections
N = int(input())
a = []
b = []
for i in range(int(N/2)):
    a.append(input().split())
    b.append(input().split())

ac = collections.Counter(a)
bc = collections.Counter(b)

a_1 = ac.most_common()[0]
b_1 = ac.most_common()[0]

a1_ans = N/2 - a_1[1]
b1_ans = N/2 - b_1[1]
if len(ac.most_common()) == 1:
    a2_ans = N/2
else:
    a2_ans = N/2 - ac.most_common()[1][1]
if len(bc.most_common()) == 1:
    b2_ans = N/2
else:
    b2_ans = N/2 - bc.most_common()[1][1]

if a_1[0] != b_1[0]:
    print(int(a1_ans + b1_ans))
else:
    print(int(max(a1_ans+b2_ans,b1_ans+a2_ans)))

### FIXED CODE ###

import collections

N = int(input())
a = list(int(i) for i in input().split())

b = a[::2]
c = a[1::2]

b_ =collections.Counter(b)
c_ =collections.Counter(c)

baa = b_.most_common()
caa = c_.most_common()

baa.append([0,0])
caa.append([0,0])

if baa[0][0] != caa[0][0]:
    print(N - baa[0][1] - caa[0][1])
else:
    print(min(N - baa[0][1] - caa[1][1],N - caa[0][1] - baa[1][1]))
#!/usr/bin/python3
# -*- coding: utf-8 -*-
def check(node_hash_list, edge_color_hash, next_node, node, color):
    edge_color_hash[str(node) + " " + str(next_node)] = color
    edge_color_hash[str(next_node) + " " + str(node)] = color
    new_color = 1
    max_color = color
    for new_next_node in node_hash_list[next_node]:
        if new_next_node == node:
            continue
        if color == new_color:
            new_color += 1
        if max_color < new_color:
            max_color = new_color
        temp_color = check(node_hash_list, edge_color_hash, new_next_node, next_node, new_color)
        new_color += 1
        if max_color < temp_color:
            max_color = temp_color
    return max_color
n = int(input())
node_hash_list = {}
print_list = []
for i in range(1, n):
    input_string = input()
    print_list.append(input_string)
    a, b = map(int, input_string.split())
    if a not in node_hash_list:
        node_hash_list[a] = []
    if b not in node_hash_list:
        node_hash_list[b] = []
    node_hash_list[a].append(b)
    node_hash_list[b].append(a)
edge_color_hash = {}
node = 1
color = 0
max_color = 1
for next_node in node_hash_list[node]:
    color += 1
    if max_color < color:
        max_color = color
    temp_color = check(node_hash_list, edge_color_hash, next_node, node, color)
    if max_color < temp_color:
        max_color = temp_color

print(max_color)

### FIXED CODE ###

#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
def check(node_hash_list, edge_color_hash, next_node, node, color):
    edge_color_hash[str(node) + " " + str(next_node)] = color
    edge_color_hash[str(next_node) + " " + str(node)] = color
    new_color = 1
    max_color = color
    for new_next_node in node_hash_list[next_node]:
        if new_next_node == node:
            continue
        if color == new_color:
            new_color += 1
        if max_color < new_color:
            max_color = new_color
        temp_color = check(node_hash_list, edge_color_hash, new_next_node, next_node, new_color)
        new_color += 1
        if max_color < temp_color:
            max_color = temp_color
    return max_color
n = int(input())
sys.setrecursionlimit(n * 10)
node_hash_list = {}
print_list = []
for i in range(1, n):
    input_string = input()
    print_list.append(input_string)
    a, b = map(int, input_string.split())
    if a not in node_hash_list:
        node_hash_list[a] = []
    if b not in node_hash_list:
        node_hash_list[b] = []
    node_hash_list[a].append(b)
    node_hash_list[b].append(a)
edge_color_hash = {}
node = 1
color = 0
max_color = 1
for next_node in node_hash_list[node]:
    color += 1
    if max_color < color:
        max_color = color
    temp_color = check(node_hash_list, edge_color_hash, next_node, node, color)
    if max_color < temp_color:
        max_color = temp_color

print(max_color)
for key in print_list:
    print(edge_color_hash[key])
a=list(input())
if a[1]==a[2]==a[3]:
  print('No')
else:
  print('Yes')


### FIXED CODE ###

a=list(input())
if a[0]==a[1]==a[2]:
  print('No')
else:
  print('Yes')
scores=[]
def depth(now,score,d):
    global scores
    if d[now]:
        for i in d[now]:
            depth(i,score+1,d)
    else:
        scores.append(score)


N,M=map(int,input().split())
d=[[] for i in range(N)]
for i in range(M):
    x,y=map(int,input().split())
    d[x-1].append(y-1)

Max=0
for i in range(N):
    depth(i,0,d)
    if scores and max(scores)>Max:
        Max=max(scores)
    scores=[]
print(Max)

### FIXED CODE ###

import numpy as np
import sys
sys.setrecursionlimit(100000)
N,M=map(int,input().split())
d=[[] for i in range(N)]
for i in range(M):
    x,y=map(int,input().split())
    d[x-1].append(y-1)
dp=[0 for i in range(N)]

def depth(now,score,d):
    global dp
    if dp[now]==0 or not(dp[now]):
        if d[now]:
            _score=[]
            for i in d[now]:
                _score.append(depth(i,score+1,d)-score)
            dp[now]=max(_score)
        else:
            return score

        return dp[now]+score

    else:
        return dp[now]+score



Max=0
for i in range(N):
    m=depth(i,0,d)
    if  m>Max:            
        Max=m
print(Max)
x, n = map(int, input(). split())
m = [0]*200
ans = 0
if n > 0:
  p = list(map(int, input(). split()))
else:
  print(x)
  quit()
for i in range(n):
  l = abs(x-p[i])
  m[l[i]] += 1
if m[0] == 0:
  print(x)
else:
  for j in range(1, 200):
    if m[j] < 2:
      a = x-j
      A = x+j
      b = p.count(a)
      if b == 0:
        ans = a
      else:
        ans = A
      break
print(ans)


### FIXED CODE ###

#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    x = LI()
    for i in range(5):
        if x[i] == 0:
            print(i+1)
            return
    return

#Solve
if __name__ == "__main__":
    solve()
import sys
from collections import defaultdict
sys.sys.setrecursionlimit(10**18)
finput=lambda:sys.stdin.readline().strip()

class Unionfind():
    def __init__(self,n):
        self.parents=[-1]*n
        self.ranks=[0]*n
    
    def find(self,x):
        if self.parents[x]<0:
            return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]
    
    def union(self,x,y):
        x=self.find(x)
        y=self.find(y)
        if x==y:
            return 
        if self.ranks[x]<self.ranks[y]:
            x,y=y,x
        self.parents[x]+=self.parents[y]
        self.parents[y]=x
        if self.ranks[x]==self.ranks[y]:
            self.ranks[x]+=1
    
    def size(self,x):
        return -self.parents[self.find(x)]
    
    def issametree(self,x,y):
        return self.find(x)==self.find(y)

def main():
    n=int(finput())
    xy=dict((tuple(map(int,finput().split())),i) for i in range(n))
    coor=sorted(list(iter(xy)),key=lambda e:e[0])
    cost = lambda e,f:min(abs(e[0]-f[0]),abs(e[1]-f[1]))
    ew=dict(((xy[coor[i]],xy[coor[i+1]]),cost(coor[i],coor[i+1]))for i in range(n-1))
    coor.sort(key=lambda e:e[1])
    ew.update(dict(((xy[coor[i]],xy[coor[i+1]]),cost(coor[i],coor[i+1]))for i in range(n-1)))
    edges=sorted(list(iter(ew)),key=lambda e:ew[e])
    v=Unionfind(n)
    totcost=0
    # print(ew)
    # print(edges)
    for edge in edges:
        if not v.issametree(edge[0],edge[1]):
            v.union(edge[0],edge[1])
            totcost+=ew[edge]
    print(totcost)
    
if __name__=='__main__':
    main()


### FIXED CODE ###

import sys
from collections import defaultdict
finput=lambda:sys.stdin.readline().strip()

class Unionfind():
    def __init__(self,n):
        self.parents=[-1]*n
        self.ranks=[0]*n
    
    def find(self,x):
        if self.parents[x]<0:
            return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]
    
    def union(self,x,y):
        x=self.find(x)
        y=self.find(y)
        if x==y:
            return 
        if self.ranks[x]<self.ranks[y]:
            x,y=y,x
        self.parents[x]+=self.parents[y]
        self.parents[y]=x
        if self.ranks[x]==self.ranks[y]:
            self.ranks[x]+=1
    
    def size(self,x):
        return -self.parents[self.find(x)]
    
    def issametree(self,x,y):
        return self.find(x)==self.find(y)

def main():
    n=int(finput())
    coor=[list(map(int,finput().split()))+[i] for i in range(n)]
    coor.sort(key=lambda e:e[0])
    cost = lambda e,f:min(abs(e[0]-f[0]),abs(e[1]-f[1]))
    ew=dict(((coor[i][2],coor[i+1][2]),cost(coor[i][:2],coor[i+1][:2])) for i in range(n-1))
    coor.sort(key=lambda e:e[1])
    ew.update(dict(((coor[i][2],coor[i+1][2]),cost(coor[i][:2],coor[i+1][:2])) for i in range(n-1)))
    edges=sorted(list(iter(ew)),key=lambda e:ew[e])
    v=Unionfind(n)
    totcost=0
    # print(ew)
    # print(edges)
    for edge in edges:
        if not v.issametree(edge[0],edge[1]):
            v.union(edge[0],edge[1])
            totcost+=ew[edge]
    print(totcost)
    
if __name__=='__main__':
    main()
a=int(input())
b=str(input())
sum=0
c=b
d=b
i=0
for s in b:
    for n in range(i,a):
        if c[n]!=c[i]:
            j=n-i
            if a>=n:
                for m in range(n,a):
                    if c[m]!=c[i] and c[m]!=c[n]:
                        k=m-n
                        if k!=j:
                            sum+=1



    i+=1
print(sum)

### FIXED CODE ###

a=str(input())
if "7"in a:
    print("Yes")
else:
    print("No")
from statistics import mean
def main():
    N = int(input())
    X = list(map(int, input().split()))
    P = int(mean(X) + 0.5)
    d = 0
    for n in range(N):
        d += (X[n] - P)**2
    print(d)

main()

### FIXED CODE ###

from statistics import mean
def main():
    N = int(input())
    X = list(map(int, input().split()))
    P = int(mean(X) + 0.5)
    d = 0
    for n in range(N):
        d += (X[n] - P)**2
    print(d)
 
main()
food = [int(input()) for _ in range(5)]

total = 0
compare = 0
largest = 0

for x in food:
    if (10 - (x % 10) > compare) and ((x % 10) != 0):
        largest = x
        compare = 10 - (x % 10)

food.remove(largest)

for i in range(len(food)):
    if food[i] % 10 != 0:
        total += round(food[i] + 5.1, -1)
    else:
        total += food[i]

print(int(total+largest))


### FIXED CODE ###

food = [int(input()) for _ in range(5)]

total = 0
compare = 0
largest = 0

if sum(food)%10 == 0:
    print(sum(food))

else:
    for x in food:
        if (10 - (x % 10) > compare) and ((x % 10) != 0):
            largest = x
            compare = 10 - (x % 10)

    food.remove(largest)

    for i in range(len(food)):
        if food[i] % 10 != 0:
            total += round(food[i] + 5.1, -1)
        else:
            total += food[i]

    print(int(total+largest))
s = list(input())
t = list(input())

def f(s, t):
  s.sort()
  t.sort(reverse=True)

  for i in range(len(s)):
    if s[i] < t[i]:
      return 'Yes'
    elif s[i] > t[i]:
      return 'No'
    elif i + 1 >= len(s) and not i + 1 >= len(t):
      return 'Yes'

  return 'No'

print(f(s, t))

### FIXED CODE ###

s = list(input())
t = list(input())
 
def f(s, t):
  s.sort()
  t.sort(reverse=True)
  s_sum = 0
  t_sum = 0
  for i in range(len(s)):
    s[i] = ord(s[i])
  
  for i in range(len(t)):
    t[i] = ord(t[i])
  
  for i in range(len(s)):
    if not i + 1 >= len(t):
      s_sum += s[i]
      t_sum += t[i]

      if s_sum < t_sum:
        return 'Yes'
      elif s_sum > t_sum:
        return 'No'
    else:
      break

  if len(s) < len(t):
    return 'Yes'
  else:
    return 'No'

print(f(s, t))
#!/usr/bin/python3
# -*- coding:utf-8 -*-

import heapq
import numpy

def main():
  na, nb, nc, K = map(int, input().split())
  As = sorted(list(map(int, input().split())), reverse=True)
  Bs = sorted(list(map(int, input().split())), reverse=True)
  Cs = sorted(list(map(int, input().split())), reverse=True)
  
  scores = [(-(As[0]+Bs[0]+Cs[0]), 0, 0, 0)]
  used = numpy.zeros((na, nb, nc), dtype=numpy.int)
  used[0, 0, 0] = 1
  for _ in range(K):
    (score, i, j, k) = heapq.heappop(scores)
    print(-score)
    if i + 1 < na and not used[i+1][j][k]:
      heapq.heappush(scores, (-(As[i+1]+Bs[j]+Cs[k]),   i+1, j,   k))
      used[i+1, j, k] = 1
    if j + 1 < nb and not used[i][j+1][k]:
      heapq.heappush(scores, (-(As[i]+Bs[j+1]+Cs[k]),   i,   j+1, k))
      used[i, j+1, k] = 1
    if k + 1 < nc and not used[i][j][k+1]:
      heapq.heappush(scores, (-(As[i]+Bs[j]+Cs[k+1]),   i,   j,   k+1))
      used[i, j, k+1] = 1

if __name__=='__main__':
  main()



### FIXED CODE ###

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

import heapq

def main():
  na, nb, nc, K = map(int, input().split())
  As = sorted(list(map(int, input().split())), reverse=True)
  Bs = sorted(list(map(int, input().split())), reverse=True)
  Cs = sorted(list(map(int, input().split())), reverse=True)
  
  scores = [(-(As[0]+Bs[0]+Cs[0]), 0, 0, 0)]
  used = [(0, 0, 0)]
  def push(i, j, k):
    heapq.heappush(scores, (-(As[i] + Bs[j] + Cs[k]), i, j, k))
    
  for _ in range(K):
    (score, i, j, k) = heapq.heappop(scores)
    print(-score)
    for di, dj, dk in [[1,0,0], [0,1,0], [0,0,1]]:
      if not (i+di < na and j+dj<nb and k+dk < nc):
        continue        
      if (i+di, j+dj, k+dk) not in used:
        push(i+di, j+dj, k+dk)
        used.append((i+di, j+dj, k+dk))

if __name__=='__main__':
  main()
from collections import Counter
N,K=map(int,input().split())
N=list(map(int,input().split()))
A=Counter(N)
C=list(A.values())
C=C.sort(reverse=True)
if len(C)<=K:
    print(0)
else:
    ans=sum(C[-(len(C)-K):])
    print(ans)

### FIXED CODE ###

from collections import Counter
N,K=map(int,input().split())
N=list(map(int,input().split()))
A=Counter(N)
C=list(A.values())
C.sort(reverse=True)
if len(C)<=K:
    print(0)
else:
    ans=sum(C[-(len(C)-K):])
    print(ans)
N = int(input())
A=[]
for i in range(N):
    A.append(int(input()))
c=0
while(True):
    b=0
    for i in A:
        if i%2==0:
            b=b+1
        if b==N:
            for j in range(N):
                A[j]=A[j]/2
            c=c+1
    if b!=N:
        break
print(c)

### FIXED CODE ###

S = list(input())
print(S.count("1"))
N = int(input())
S=list(input() for k in range(N)
Slist = [0] * N
for i in range(N):
    Slist[i] = sorted(S[i])
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

if len(Slist) - len(get_unique_list(Slist)) == 0:
    print(0)
else:
    print(len(Slist) - len(get_unique_list(Slist)) + 1)

### FIXED CODE ###

from collections import Counter
 
N = int(input())
 
ans = {}
answer = 0
for _ in range(N):
    s = "".join(sorted(input()))
 
    if s not in ans:
        ans[s] = 0
 
    else:
        ans[s] += 1
        answer += ans[s]
 
print(answer)
import math

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

x=max(XY)
y=min(XY)
x_dy=x%y

ans=math.gcb(x,x_dy)

print(ans)

### FIXED CODE ###

def euclidean_alg(x,y):
    while y:
        x,y=y,x%y
    return x

XY=list(map(int,input().split()))
x=max(XY)
y=min(XY)

print(euclidean_alg(x,y))
n , m = map(int, input().split())
a = list(map(int,input().split()))
a.sort()
x=[]
for i in range(m):
    b , c = map(int, input().split())
    x+=[c]*b
x.sort(reverse=True)
t=n
if a[n-1]<x[n-1]:
    a=x[:n]
else:
    for i in range(n):
        if a[i]>=x[i]:
            t=i
            break
    a=x[:t]+a[t:]
print(sum(a))


### FIXED CODE ###

n , m = map(int, input().split())
a = list(map(int,input().split()))
a.sort()
bc=[]
for i in range(m):
    b , c = map(int, input().split())
    bc.append((b,c))
bc.sort(key = lambda x : x[1],reverse=True)

t=0
for i in range(m):
    b,c=bc[i]
    if t>=n:
        break
    if a[t]>=c:
        break
    for j in range(b):
        if a[t]<c:
            a[t]=c
            if t<n-1:
                t+=1
        else:
            break
print(sum(a))
# -*- coding: utf-8 -*-


def main():
    A, B = [int(_) for _ in input().split()]

    product = A * B
    for divisor in range(min([A, B]) // 2, 2, -1):
        if A % divisor == 0 and B % divisor == 0:
            A = A // divisor
            B = B // divisor
            product = product // divisor

    print(product)


def correct_1():
    A, B = [int(_) for _ in input().split()]

    for i in range(1, B + 1):
        if A * i % B == 0:
            print(A * i)
            break


def correct_2():
    A, B = [int(_) for _ in input().split()]

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

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

    print(lcm(A, B))


if __name__ == "__main__":
    correct_1()


### FIXED CODE ###

# -*- coding: utf-8 -*-


def main():
    A = int(input())
    B = int(input())

    print('{}'.format(6 - A - B))


if __name__ == "__main__":
    main()
r = input()
print '%.6f %.6' % (r*3.14,r*r*3.14)

### FIXED CODE ###

import math
r = input()
print '%.6f %.6f' % (r*r*math.pi,2*r*math.pi)