Harryxun/stf_run huggingface dataset:
#標準入力
H, W = map(int, input().split())
grid = []
for i in range(H):
    tmp = input()
    grid.append(tmp)

#グリッドの縦横を別々に調べる
import numpy as np
grid_int = np.zeros((H, W))
for i in range(H):
    count = 0
    for j in range(W):
        if grid[i][j] == '.':
            count += 1
            if j == W - 1:
                grid_int[i, j-count + 1:j + 1] = count
        elif grid[i][j] == '#':
            if j == 0:
                continue
            grid_int[i, j- count, j] = count
            count = 0


for j in range(W):
    count = 0
    for i in range(H):
        if grid[i][j] == '.':
            count += 1
            if i == H - 1:
                grid_int[i - count + 1, i + 1, j] += count
        elif grid[i][j] == '#':
            if i == 0:
                continue
            grid_int[i-count: i, j] += count
            count = 0

ans = 0
for i in range(H):
    tmp_max = max(grid_int[i]) - 1
    if ans < tmp_max:
        ans = tmp_max
print(int(ans))


### FIXED CODE ###

#import sys
#input = sys.stdin.buffer.readline
import numpy as np

def main():
    H,W = map(int,input().split())
    S = np.array([list(input()) for _ in range(H)]) == '.' #'.'に一致するならTrueしなければFalse

    up = np.zeros((H,W), dtype=int)
    down = np.zeros((H,W), dtype=int)
    left = np.zeros((H,W), dtype=int)
    right = np.zeros((H,W), dtype=int)
    
    for i in range(H-1):
        up[i+1,:] = (up[i,:] + 1) * S[i,:] #npの変数名[k,l]でk行l列を取り出す
    for i in range(H-1):                   #:なら全部をそれぞれについて見ていく
        down[H - 2 - i,:] = (down[H - 1 - i,:] + 1) * S[H - 1 - i,:]
    for i in range(W-1):
        left[:,i+1] = (left[:,i] + 1) * S[:,i]
    for i in range(W-1):
        right[:,W - 2 - i] = (right[:,W - 1 - i] + 1) * S[:,W - 1 - i]
        
    print(((up+down+left+right)*S).max()+1) #カケザンデ要素ごとの掛け算可能
    
if __name__ == "__main__":
    main()
n,T=[int(i) for i in input().split()]
ans=[]
for i in range(n):
  c,t=[int(i) for i in input().split()]
  if t<=T:
    ans.append(c)
print(min(ans) if len(c)!=0 else "TLE")


### FIXED CODE ###

n,T=[int(i) for i in input().split()]
ans=[]
for i in range(n):
  c,t=[int(i) for i in input().split()]
  if t<=T:
    ans.append(c)
print(min(ans) if len(ans)!=0 else "TLE")
from fractions import gcd
x, y = int(input().split())
print(gcd(x, y))

### FIXED CODE ###

x, y = map(int, input().split())
while y != 0:
    x, y = y, x % y
print(x)
N,K=input().split()
S=input()
S[K-1]=S[K-1].lower()
print(S)

### FIXED CODE ###

N,K=input().split()
S=list(input())
for i in range(len(S)):
    if i==int(K)-1:
        S[i]=S[i].lower()
print(''.join(S))
def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))

    l = []
    for _ in range(40):
        cnt = 0
        for i in range(n):
            if a[i] & 1:
                cnt += 1
            a[i] >>= 1
        l.append(cnt)

    pows = [1]
    for _ in range(39):
        pows.append(pows[-1] * 2)

    right = k.bit_length()

    y = 0
    for i in range(right, 40):
        y += l[i] * pows[i]

    def solve(k, right):
        x = 0
        y = 0
        for i in range(right):
            if l[i] < n - l[i]:
                x += pows[i]
                y += (n - l[i]) * pows[i]
            else:
                y += l[i] * pows[i]

        if x <= k:
            return y

        else:
            return max(y - (n-2*l[right-1]) * pows[right-1], (n - l[i]) * pows[right-1] + solve(k - pows[right-1], right-1))

    print(y + solve(k, right))

main()

### FIXED CODE ###

def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))

    l = []
    for _ in range(40):
        cnt = 0
        for i in range(n):
            if a[i] & 1:
                cnt += 1
            a[i] >>= 1
        l.append(cnt)

    pows = [1]
    for _ in range(39):
        pows.append(pows[-1] * 2)

    if k == 0:
        print(sum([l[i] * pows[i] for i in range(40)]))
        exit()

    # when it does not use the biggest bit of k
    ans1 = 0
    for i in range(k.bit_length() - 1):
        if l[i] < n - l[i]:
            ans1 += (n - l[i]) * pows[i]
        else:
            ans1 += l[i] * pows[i]
    for i in range(k.bit_length() - 1, 40):
        ans1 += l[i] * pows[i]

    # when it use the biggest bit of k
    ans2 = 0
    ans3 = 0
    for i in range(40):
        if l[i] < n - l[i]:
            if k & 1:
                ans2 += (n - l[i]) * pows[i]
            else:
                ans2 += l[i] * pows[i]
            ans3 += (n - l[i]) * pows[i]
        else:
            if k & 1:
                ans2 = ans3 + l[i] * pows[i]
            else:
                ans2 += l[i] * pows[i]
            ans3 += l[i] * pows[i]
        k >>= 1

    print(max(ans1, ans2))

main()
string = input()
pattern = ["A","C","G","T"]

c = 0
result = []
for i in string:
    if i in pattern:
        c += 1
    else:
        result.append(c)
        c = 0

print(max(result))

### FIXED CODE ###


string = input()
pattern = ["A","C","G","T"]

c = 0
result = []
for i in string:
    if i in pattern:
        c += 1
        if string[len(string)-1] == i:
            result.append(c)
    else:
        result.append(c)
        c = 0

if len(result) == 0:
    print(len(string))
else:
    print(max(result))
from itertools import combinations
 
A, B, C, K = map(int, input().split(" "))

a = -100
_sum = 0
for i in combinations([1] * A + [0] * B + [-1]*C, K):
  if (_sum := sum(i)) > a:
    a = _sum
print(a)

### FIXED CODE ###

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

if A >= K:
  print(K)
elif A + B >= K:
  print(A)
else:
  k = K - A - B
  print(A - k)
S=input()
T=input()

s = ''.join(sorted(list(S))
t = ''.join(sorted(list(T), reverse=True))

if s < t:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

S=input()
T=input()

s = ''.join(sorted(list(S)))
t = ''.join(sorted(list(T), reverse=True))

if s < t:
  print('Yes')
else:
  print('No')
import itertools
r,g,b,n=map(int,input().split())
x,y=n//r,n//g
x,y=list(range(0,r*x+1,r)),list(range(0,g*y+1,g))
l=[i+j for i,j in ()itertools.product(x,y) if i+j<n]
print(l)

### FIXED CODE ###

import collections
import itertools
r,g,b,n=map(int,input().split())
x,y=n//r,n//g
x,y=list(range(0,r*x+1,r)),list(range(0,g*y+1,g))
l=[i+j for i,j in itertools.product(x,y) if i+j<=n]
z=collections.Counter(l)
count=0
for key,value in zip(z.keys(),z.values()):
  v=n-key
  if v==0:
    count+=value
  elif v%b==0:
    count+=value
print(count)
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
N = input()
b = [(int(input())) for _ in range(N)]

print(A1)

### FIXED CODE ###


A = [list(map(int, input().split())) for i in range(3)]
N = int(input())
b = [(int(input())) for _ in range(N)]

bingo1 = [0, 0, 0]
bingo2 = [0, 0, 0]
bingo3 = [0, 0, 0]

# 穴を開ける工程
for i in range(3):
  for j in range(N):
    if A[i][0] == b[j]:
      bingo1[i] = 1
    if A[i][1] == b[j]:
      bingo2[i] = 1
    if A[i][2] == b[j]:
      bingo3[i] = 1
      

# ビンゴ判定
if bingo1[0] == bingo1[1] == bingo1[2] == 1:
    print("Yes")
elif bingo2[0] == bingo2[1] == bingo2[2] == 1:
    print("Yes")
elif bingo3[0] == bingo3[1] == bingo3[2] == 1:
    print("Yes")
elif bingo1[0] == bingo2[0] == bingo3[0] == 1:
    print("Yes")
elif bingo1[1] == bingo2[1] == bingo3[1] == 1:
    print("Yes")
elif bingo1[2] == bingo2[2] == bingo3[2] == 1:
    print("Yes")
elif bingo1[0] == bingo2[1] == bingo3[2] == 1:
    print("Yes")
elif bingo1[2] == bingo2[1] == bingo3[0] == 1:
    print("Yes")
else:
    print("No")
a, b, m = map(int, input().split())
a1 = list(map(int, input().split()))
b1 = list(map(int, input().split()))

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

import itertools
import numpy as np

b2 = np.array(b1)
b2 = np.tile(b2, (a,1))

for i in range(a):
    b2[i] = b2[i] + np.tile(a1[i], b)


ans = []
from collections import deque
ans = deque(ans)
for i in range(m):
    ans.append( a1[disc[i][0]-1] + b1[disc[i][1]-1] - disc[i][2] )

ans = list(ans)
print(min(np.min(b2), min(ans)))





### FIXED CODE ###

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

disc = [list(map(int, input().split())) for i in range(m)]
import numpy as np


from collections import deque
ans = []

ans = deque(ans)

for i in range(m):
    ans.append( a1[disc[i][0]-1] + b1[disc[i][1]-1] - disc[i][2] )

ans = list(ans)

print(min( min(ans), min(a1)+min(b1) ))
N,M = map(int,input().split())
A=[int(n) for n in input().split()]
A.sort()
        
for _ in range(M):
    a = A[-1]//2
    del A[-1]
    for i in range(N):
        if A[i] >a:
            A.insert(i, a)
            break
    print(A)
print(sum(A))

### FIXED CODE ###

import heapq
N,M = map(int,input().split())
H=[]
for i in input().split():
    heapq.heappush(H,-int(i))
for i in range(M):
    a = heapq.heappop(H)
    heapq.heappush(H,-(-a//2))
print(-sum(H))
K = int(input)

if K%2 == 0:
  ak = k**2//4
else:
  ak = (k**2-1)//4

print(ak)

### FIXED CODE ###

K = int(input())

if K%2 == 0:
  ak = K**2//4
else:
  ak = (K**2-1)//4

print(ak)
n = int(input())
arr = tuple(map(int, input().split()))

def cal(i, dst):
  if i == -1:
    return 0

  result = None
  for j in dst:
    next_dst = [v for v in dst if v != j]
    val = arr[i] * abs(i - j) + cal(i - 1, next_dst)
    result = max(result, val) if result else val

  return result

print(cal(n - 1, [i for i in range(n)]))


### FIXED CODE ###


def main():

  n = int(input())
  arr = map(int, input().split())
  arr = tuple(sorted(enumerate(arr), key=lambda tpl: -tpl[1]))

  dp = [[0] * (n + 1) for _ in range(n + 1)]
  for i, (p, a) in enumerate(arr):
    for l in range(i + 1):
      dp[i + 1][l] = max(dp[i + 1][l], dp[i][l] + a * abs(p - (n - (i - l) - 1)))
      dp[i + 1][l + 1] = max(dp[i + 1][l + 1], dp[i][l] + a * abs(p - l))

  print(max(dp[n]))

main()
from bisect import bisect_left

n=int(input())
l=sorted(list(map(int,input().split())))

ans=0
for i in range(n):
    for j in range(i+1,n):
        ans+=bisect.bisect_left(l[j+1:], l[i]+l[j])

print(ans)


### FIXED CODE ###

from bisect import bisect_left
N = int(input())
L = sorted(list(map(int, input().split())))
 
ans = 0
for i in range(N):  # １番短い棒
    for j in range(i + 1, N):  # 真ん中の長さの棒
        ans += bisect_left(L, L[i] + L[j]) - (j + 1)
 
print(ans)
inp = input().split()
l = list(map(int,inp)).sort()
print(l[0],l[1],l[2])

### FIXED CODE ###

inp = list(map(int,input().split()))
inp.sort()
print(inp[0],inp[1],inp[2])
A,B = map(int,input().split())
n=B-A+1
a = "0"*(50-len(bin(A))+2)+bin(A)[2:]
b = ""
for k in range(1,51):
    if k==1:
        x = str(r%2)
    else:
        m = int(a[-k:],2)
        r = n%(2**k)
        if a[-k]=="0":
            if (m+r-1)%(2**k)>=2**(k-1):
                x = str((m+r-1-2**(k-1)+1)%2)
            else:
                x = "0"
        else:
            if (m+r-1)%(2**k)>=2**(k-1):
                x = str(r%2)
            else:
                x = str((2**k-1-m+1)%2)
    b = x+b
print(int(b,2))

### FIXED CODE ###

def f(N):
    if N==0:
        return 0
    if N==1:
        return 1
    if N==2:
        return 1^2
    if N==3:
        return 0
    k = 2
    while 2**k<=N:
        k += 1
    k -= 1
    if 2**k==N:
        return N
    n = (N-2**k)//4
    cnt = 0
    i = 2**k+4*n
    while i<=N:
        cnt = cnt^i
        i += 1
    return cnt
A,B = map(int,input().split())
if A==0 and B==0:
    print(0)
elif A==0 and B>0:
    print(f(B))
else:
    print(f(B)^f(A-1))
s=list(input())
t=list(input())
n=len(s)
m=len(t)
if m>n:
    print('UNRESTORABLE')
    exit()
af=0
for i in range(n-m+1):
    k=s[n-m-i:n-i]
    f=0
    for j in range(m):
        if k[i]=='?' or k[i]==t[i]:
            f+=1
    if f==m:
        af+=1
        s[n-m-i:n-i]=t
        break
if af>0:
    ans=''
    for i in range(n):
        if s[i]=='?':
            ans+='a'
        else:
            ans+=s[i]
    print(ans)
else:
    print('UNSTORABLE')
        

### FIXED CODE ###

s=list(input())
t=list(input())
n=len(s)
m=len(t)
if m>n:
    print('UNRESTORABLE')
    exit()
af=0
for i in range(n-m+1):
    k=s[n-m-i:n-i]
    f=0
    for j in range(m):
        if k[j]=='?' or k[j]==t[j]:
            f+=1
    if f==m:
        af+=1
        s[n-m-i:n-i]=t
        break
if af>0:
    ans=''
    for i in range(n):
        if s[i]=='?':
            ans+='a'
        else:
            ans+=s[i]
    print(ans)
else:
    print('UNRESTORABLE')
def prepare(n,arr):
    nodeArr = [[] for i in range(n)]
    for ar in arr:
        nodeArr[ar[0]-1].append([ar[1]-1,ar[2]])
        nodeArr[ar[1]-1].append([ar[0]-1,ar[2]])
    return nodeArr

def dfs(parent,currentNode,distance):

    if len(nodeArr[currentNode]) == 1:
        if currentNode != 0:
            # 末点
            res[currentNode] = distance
            return

    for next in nodeArr[currentNode]:
        nextNode = next[0]
        nextNodeDistance = next[1]
        if nextNode == parent:
            continue
        dfs(currentNode,nextNode,distance + nextNodeDistance)
        res[currentNode] = distance


n = int(input())

# arr = []
#
# for i in range(n-1):
#     arr.append([int(s) for s in input().split(" ")])
#
# nodeArr = prepare(n, arr)

nodeArr = [[] for i in range(n)]
for i in range(n-1):
    u, v, w = map(int, input().split())
    nodeArr[u-1].append([v-1, w])
    nodeArr[v-1].append([u-1, w])


res = [-1 for i in range(n)]

dfs(-1,0,0)

result = [(re % 2) for re in res]

for re in res:
    print(re % 2)



### FIXED CODE ###

import sys
sys.setrecursionlimit(20000000)
def prepare(n,arr):
    nodeArr = [[] for i in range(n)]
    for ar in arr:
        nodeArr[ar[0]-1].append([ar[1]-1,ar[2]])
        nodeArr[ar[1]-1].append([ar[0]-1,ar[2]])
    return nodeArr

def dfs(currentNode,distance):
    res[currentNode] = distance
    for next in nodeArr[currentNode]:
        nextNode = next[0]
        nextNodeDistance = next[1]
        if res[nextNode] == -1:
            dfs(nextNode,distance + nextNodeDistance)




n = int(input())

arr = []

for i in range(n-1):
    arr.append([int(s) for s in input().split(" ")])

nodeArr = prepare(n, arr)


if n == 1:
    print(1)
else:
    res = [-1 for i in range(n)]

    dfs(0,0)

    result = [(re % 2) for re in res]

    for re in res:
        print(re % 2)
N = int(input())
A = [int(i) for i in input().split()]
values = [str(i+1) for i in range(N)]
dic = {key: val for key, val in zip(A, values)}
dic_s = deque(sorted(dic.items()))
s =[]
for i in range(N):
    s.append(dic_s[i][1])

ans = ' '.join(s)
print(ans)

### FIXED CODE ###

from collections import deque
N = int(input())
A = [int(i) for i in input().split()]
values = [str(i+1) for i in range(N)]
dic = {key: val for key, val in zip(A, values)}
dic_s = deque(sorted(dic.items()))
s =deque()
for i in range(N):
    s.append(dic_s[i][1])

ans = ' '.join(list(s))
print(ans)
N = int(input())
B = [int(x) for x in input().split()]
ans = [0]*(N)
for i in range(1,N-2):
  ans[i] = min(B[i-1],B[i],B[i+1])
ans[0] = min(B[0],B[1])
ans[N-2] =  min(B[N-3],B[N-2])
ans[N-1] = B[N-2]
print(sum(ans))

### FIXED CODE ###

N = int(input())
B = [int(x) for x in input().split()]
ans = [0]*(N)
if N==2:
  print(int(B[0])*2)
  exit()
for i in range(1,N-1):
  ans[i] = min(B[i-1],B[i])
ans[0] = B[0]
ans[N-1] = B[N-2]
print(sum(ans))
import numpy as np

N = int(input())
A_i = np.array(list(map(int, input().split())))
stu = [[nums+1,student] for nums, student in enumerate(A_i)]

hh = np.full(N, np.nan)
for i, j in stu:
    hh[j-1] = i
    print(int(hh[j-1]))

### FIXED CODE ###

import numpy as np

N = int(input())

nums_list = np.arange(1,N+1)
odd_list = nums_list[nums_list%2==1]
print(len(odd_list)/len(nums_list))
def main():
  N = int(input())
  S = input()
  R = 0
  B = 0
  for i in range(0,N):
    if S[i] == "R":
      R = R + 1
    else:
      B = B + 1
	if R > N/2:
      print("Yes")
      return
    elif B > N/2:
      print("No")
      return
    
if __name__ == '__main__':
  main()


### FIXED CODE ###

def main():
    N = int(input())
    S = input()
    R = 0
    B = 0
    for i in range(0,N):
        if S[i] == "R":
            R = R + 1
        else:
            B = B + 1
        if R > N/2:
            print("Yes")
            return
        elif B > N/2:
            print("No")
            return
    print("No")
    
if __name__ == '__main__':
    main()
a,b,c=input().split()
print((a[0]+b[0]+[0]).upper())

### FIXED CODE ###

a,b,c=input().split()
print((a[0] + b[0] + c[0]).upper())
D = int(input())
print('Christmas'+'Eve'*(25 - D)

### FIXED CODE ###

D = int(input())
print('Christmas'+' Eve'*(25 - D))
s=input()
K=int(input())-1
N=len(s)
L=set()
for i in range(N):
    for j in range(i+1,N):
        L.add(s[i:j])
ans=sorted(list(L))
print(ans[K])

### FIXED CODE ###

s=input()
K=int(input())
N=len(s)
L=set()
for i in range(N+1):
    for j in range(i,i+K+1):
        #print(s[i:j])
        L.add(s[i:j])
ans=sorted(list(L))
ans.remove('')
print(ans[K-1])
import math
n = []
while True:
    try:
        n.append(int(raw_input()))
    except:
        break
 
r = max(n)+1
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        p[2*i+1::i+1] = [0 for range(2*i+1,r,i+1)]:
           
 
for i in n:
     print sum(p[:i])

### FIXED CODE ###

import math
n = []
while True:
    try:
        n.append(int(raw_input()))
    except:
        break
  
r = max(n)+1
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
p[3::2] = [0 for x in range(3,r,2)]
for i in range(2,sqrt,2):
    if p[i]:
        p[2*i+1::i+1] = [0 for x in range(2*i+1,r,i+1)] 
  
for i in n:
     print sum(p[:i])
import math
import fractions

# A以上B以下の数でXの倍数の個数
def countX(X) :
    if X > B :
        return 0
    minX = max(math.ceil(A / X),0)
    maxX = max(math.floor(B / X),0)
    return maxX - minX + 1

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

if C == 1 :
  print(z)

ans = B - A + 1

# 最小公倍数
Z = int(C * D / fractions.gcd(C,D))

ans -= countX(C)
ans -= countX(D)
ans += countX(Z)

print(int(ans))



### FIXED CODE ###

import math
import fractions

# A以上B以下の数でXの倍数の個数
def countX(X) :
    if X > B :
        return 0

    minX = (A - 1) // X
    maxX = B // X

    return maxX - minX

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

ans = B - A + 1

# 最小公倍数
Z = int(C * D / fractions.gcd(C,D))

ans -= countX(C)
ans -= countX(D)
ans += countX(Z)

print(int(ans))
from numba import jit

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

a.sort()

import collections
c = collections.Counter(a)

d=[]
for ck,cv in c.items():
    if cv>=2:
       d.append(ck) 
dset=set(d)
    
aaset=set()

@jit
def dp():
    while True:
        aaset.add(a[0])
        a2=[]
        for i,ai in enumerate(a,1):
            if ai%a[0]!=0:
                a2.append(ai)
        a=a2.copy()
        if len(a2)==0:
          break
    return True

yn=dp()
aaset=aaset-dset    
print(len(aaset))


### FIXED CODE ###

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

a.sort()
amax=max(a)
dp=[True]*(amax+1)

import collections
c = collections.Counter(a)

d=[]
for ck,cv in c.items():
    if cv>=2:
       d.append(ck) 
dset=set(d)
    
aa=set()
for ai in a:
    if dp[ai]:
        aa.add(ai)
        for aj in range(ai*2,amax+1,ai):
            dp[aj]=False

aa=aa-dset    
print(len(aa))
s = raw_input()

c = "CODEFESTIVAL2016"

ans  = 0
for i in range(len(c)):
    if s[i] != c[[i]:
                 ans += 1
print ans


### FIXED CODE ###

s = raw_input()

c = "CODEFESTIVAL2016"

ans  = 0
for i in range(len(c)):
    if s[i] != c[i]:
        ans += 1
print ans
x=(W-w)*(H-h)

### FIXED CODE ###

H,W=map(int,input().split())#標準入力を行う
h,w=map(int,input().split())#標準入力を行う
print((H-h)*(W-w))
x = input(int, )


def func(p):
    q = 1
    while p ** q <= x:
        q += 1
    return p ** (q - 1)


ctn = []
a = 1

while a <= x ** (1/2):
    ctn.append(func(a))
    a += 1

print(max(ctn))


### FIXED CODE ###

x = int(input())

if x == 1:
    print("1")
    exit()


def func(p):
    q = p
    while q < x:
        q *= p
        if q == x:
            return q
    if q / p == p:
        return 1
    else:
        return q // p


z = []
a = 2

while a <= x:
    z.append(func(a))
    a += 1

print(max(z))
N, M = [int(s) for s in input().split(' ')]
As = [int(s) for s in input().split(' ')]
CBs = []
for m in range(M):
    B, C = [int(s) for s in input().split(' ')]
    CBs.append((C, B))
As.sort(reverse=True)
CBs.sort(reverse=True)
ret = 0
a = 0
bc = 0
n = 0
while n < N:
    C, B = CBs[bc]
    if As[a] < C:
        bc += 1
        pick = min(N - n, B)
        ret += pick * C
        n += pick
    else:
        ret += As[a]
        a += 1
        n += 1
print(ret)




### FIXED CODE ###

N, M = [int(s) for s in input().split(' ')]
As = [int(s) for s in input().split(' ')]
CBs = []
for m in range(M):
    B, C = [int(s) for s in input().split(' ')]
    CBs.append((C, B))
As.sort(reverse=True)
CBs.sort(reverse=True)
CBs.append((0, 0))
ret = 0
a = 0
bc = 0
n = 0
while n < N:
    C, B = CBs[bc]
    if As[a] < C:
        bc += 1
        pick = min(N - n, B)
        ret += pick * C
        n += pick
    else:
        ret += As[a]
        a += 1
        n += 1
print(ret)
import math

N,D=map(int,input().split())
X=[]
for _ in range(N):
  X.append(list(map(int, input().split())))
count=0
for i in range(N-1):
  for j in range(i+1,N):
    a=0
    for k in range(D):
      a+=(X[i][k]-X[j][k])**2
    if math.sqrt(a).is_integer():
      coutn+=1
print(count)

### FIXED CODE ###

import math
 
N,D=map(int,input().split())
X=[]
for _ in range(N):
  X.append(list(map(int, input().split())))
count=0
for i in range(N-1):
  for j in range(i+1,N):
    a=0
    for k in range(D):
      a+=(X[i][k]-X[j][k])**2
    if math.sqrt(a).is_integer():
      count+=1
print(count)
# -*- coding: utf-8 -*-
# ABC 083 B - Some Sums
# スペース区切りの整数の入力
b = [int(s) for s in input().split()]
sum = 0
for i in range(1, b[0]+1):
    s = 0
    t = i
    while t != 0:
        s = s + t % 10
        t = t // 10
    if (b[1] <= s) and (s <= b[2]):
        sum = sum + i
print(r)

### FIXED CODE ###

# -*- coding: utf-8 -*-
# ABC 083 B - Some Sums
# スペース区切りの整数の入力
b = [int(s) for s in input().split()]
sum = 0
for i in range(1, b[0]+1):
    s = 0
    t = i
    while t != 0:
        s = s + t % 10
        t = t // 10
    if (b[1] <= s) and (s <= b[2]):
        sum = sum + i
print(sum)
a=int(input())
b=[input() for i in range(a)]
c=[AC,WA,TLE,RE]
for value in c:
  e=b.count(value)
  print("{0}x{1}".format(value,e))
  
  


### FIXED CODE ###

N = int(input())
s = [input() for i in range(N)]
for v in ['AC', 'WA', 'TLE', 'RE']:
  print('{0} x {1}'.format(v, s.count(v)))
t=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
p,q=[0],[0]
w=[(a[0]-b[0])*t[0],(a[1]-b[1])*t[1]]
if sum(w)==0:
    print("infinity")
else:
    print(w[9])


### FIXED CODE ###

T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
 
P = (A1 - B1) * T1
Q = (A2 - B2) * T2
if P > 0:
	P *= -1
	Q *= -1
 
if P + Q < 0:
	print(0)
elif P + Q == 0:
	print("infinity")
else:
	S = (-P) // (P + Q)
	T = (-P) % (P + Q)
	if T != 0:
		print(S * 2 + 1)
	else:
		print(S * 2)
def min(a,i)
for t in range(0, i)
  if a[0] > a[t]:
    a[0] = a[t]
  return a[0]

def max(a,i)
for t in range(0, i)
  if a[0] < a[t]:
    a[0] = a[t]
  return a[0]

def sum(a,i)
for t in range(1, i)
  a[0] += a[t]
  return a[0]

i = int(raw_input().split())
a = map(int, raw_input().split())
print min(a,i) max(a,i) sum(a,i)

### FIXED CODE ###

def min(a,i):
  x = a[0]
  for t in range(0, i):
    if x > a[t]:
      x = a[t]
  return x

def max(a,i):
  y = a[0]
  for t in range(0, i):
    if y < a[t]:
      y = a[t]
  return y

def sum(a,i):
  s = 0
  for t in range(0, i):
    s += a[t]
  return s

i = int(raw_input())
a = map(int, raw_input().split())
print "%d %d %d" % (min(a,i), max(a,i), sum(a,i))
S = print()
#SがS,C,Rとなるようにする
print(s | c | r)
T = print()
#TがS,C,Rとなるようにする
print((s | c | r))
S == T

### FIXED CODE ###

S = input()
T = input()

count = 0
#iを３回数えてもらう
for i in range(3):
#数えてｓとｔが同じならカウント１とする
    if S[i]==T[i]:
        count += 1
print(count)