Harryxun/stf_run huggingface dataset:
from sys import stdin as s
n,m=map(int,s.readline().split())
l=[0]*n
wa=[0]*n
cor,pen=0
for i in range(m):
  x,y=s.readline().split()
  x=int(x)-1
  if y=="AC":
    l[x]=1
  elif not l[x]:
    wa[x]+=1
for i in range(n):
  if l[i]:
    cor+=1
    pen+=wa[i]
print(cor,pen)

### FIXED CODE ###

from sys import stdin as s
n,m=map(int,s.readline().split())
l=[0]*n
wa=[0]*n
cor,pen=0,0
for i in range(m):
  x,y=s.readline().split()
  x=int(x)-1
  if y=="AC":
    l[x]=1
  elif not l[x]:
    wa[x]+=1
for i in range(n):
  if l[i]:
    cor+=1
    pen+=wa[i]
print(cor,pen)
n,k = map(int, input().split())
d = []
A= []
c = []

for i in range(k):
    d.append(int(input()))
    a = input()
    A.append([int(a[j]) for j in range(a)])

for j in range(k):
    for k in range(d[j]):
        c.append(A[j][k])

print(n-len(set(c)))

### FIXED CODE ###

n,k = map(int, input().split())
d = []
A= []
c = []
 
for i in range(k):
    d.append(int(input()))
    A.append(list(map(int, input().split())))
 
for j in range(k):
    for m in range(d[j]):
        c.append(A[j][m])
 
print(n-len(set(c)))
N,K = map(int,input().split())
lis = [int(input()) for x in range(N)]
lis.sort()
print(min(lis[i+K-1] - lis[i] for x in range(N-K+1)))

### FIXED CODE ###

N,K = map(int,input().split())
lis = [int(input()) for x in range(N)]
lis.sort()
print(min(lis[i+K-1] - lis[i] for i in range(N-K+1)))
import math
import copy
H,N=map(int,input().split())

#inf=float('inf')
dp=[0]+[1e8]*H

for i in range(N):
    A,B=map(int,input().split())
    for j in range(A,H+1):
        dp[j]=min(dp[j-A]+B,dp[j])

        if j > H-A:
            dp[-1]=min(dp[-1],dp[j]+B)

    if A>=H:
        ndp[-1]=min(B,dp[-1])

print(dp[-1])


### FIXED CODE ###

import math

def main():
    H,N=map(int,input().split())

    inf=float('inf')
    dp=[0]+[inf]*H

    for i in range(N):
        A,B=map(int,input().split())
        if A>=H:
            #dp[-1]=min(B,dp[-1])
            if B < dp[-1]:
                dp[-1]=B
        else:
            for j in range(A,H+1):
                #dp[j]=min(dp[j-A]+B,dp[j])
                if dp[j-A]+B<dp[j]:
                    dp[j]=dp[j-A]+B

                if j > H-A:
                    #dp[-1]=min(dp[-1],dp[j]+B)
                    if dp[j]+B < dp[-1]:
                        dp[-1]=dp[j]+B

    print(dp[-1])

main()
N = int(input())

point = []
dist = []

for _ in range(N) :
    x, y = map(int, input().split())
    point.append((x, y))
    dist.append(abs(x) + abs(y))

maxDist = dist[-1]
mask = maxDist % 2

for d in dist :
    if d % 2 != mask :
        print('-1')
        break
    maxDist = max(maxDist, d)
else :  # 実現可能
    print(maxDist) # 腕の数
    out = [1] * maxDist
    print(*out)

    for i, (x, y) in enumerate(point) :
        # if x < 0 :
        #     holizon = ['L'] * abs(x)
        # elif x > 0 :
        #     holizon = ['R'] * abs(x)
        # else :
        #     holizon = ['']

        # if y < 0 :
        #     vertical = ['D'] * abs(y)
        # elif y > 0 :
        #     vertical = ['U'] * abs(y)
        # else :
        #     vertical = ['']

        # R = (maxDist - dist[i]) // 2
        # if R > 0 :
        #     last = ['LR'] * R
        # else :
        #     last = ['']

        # print(''.join(holizon + vertical + last))
        print('U')




### FIXED CODE ###

N=int(input())

point = []
parity = {}
for _ in range(N) :
    x, y = map(int, input().split())
    point.append((x, y))
    parity[(x + y) % 2] = 1

if len(set(parity)) == 2 :
    print('-1')
else :
    m = 38
    parity = 1 if (1 in parity) else 0
    print(m + 1 - parity)
    if parity == 1 :  # 距離が奇数
        print(*[1 << i for i in range(m)])
    else :
        print(1, *[1 << i for i in range(m)])

    def arm(x, y, m) :
        if abs(x) >= abs(y) :
            if x >= 0 :
                return ('R', x - (1<<m), y)
            else :
                return ('L', x + (1<<m), y)
        else :
            if y >= 0 :
                return ('U', x, y - (1<<m))
            else :
                return ('D', x, y + (1<<m))

    for x, y in point :
        ans = []
        for i in range(m-1, -1, -1) :
            mode, x, y = arm(x, y, i)
            ans.append(mode)
        if parity == 0 :  # 偶数の場合一つ足す
            if x == 1 :
                ans.append('R')
            elif x == -1 :
                ans.append('L')
            elif y == 1 :
                ans.append('U')
            elif y == -1 :
                ans.append('D')
        print(''.join(ans[::-1]))
H, W = map(int, input().split())

a = H * W

if(a % 2 == 0):
     print(a)
 else:
     print(a+1)

### FIXED CODE ###

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

a = H * W
b = 0


if H == 1 or W == 1:
    print(1)
else:
    print(math.ceil(a/2))
a,b=map(int,input().split())
ans=0
if a==b:
  print(0)
  exit()  
if b>0:
  if abs(a)<abs(b):
    raise "eerot"
    if a<0:
      ans+=1
      ans+=b+a  
    else:
      ans+=b-a  
  else:
    if a<0:
      ans+=abs(a)-b+1  #正
    else:
      ans+=a-b+1 #正
else:
  if abs(a)<abs(b):
    if a<0:  
      ans+=2
      ans+=a-b
    else:
      ans+=abs(b)-a
      ans+=1 
  else:
    if a<0:  #正
      ans+=b-a
    else:
      ans+=a+b+1  #正
print(ans) 

### FIXED CODE ###

a,b=map(int,input().split())
ans=0
if a==b:
  print(0)
  exit()  
if b>0:
  if abs(a)<abs(b):
    if a<0:
      ans+=1
      ans+=b+a  
    else:
      ans+=b-a  
  else:
    if a<0:
      ans+=abs(a)-b+1
    else:
      ans+=a-b+2
else:
  if abs(a)<abs(b):
    if a<0:  
      ans+=2
      ans+=a-b
    else:
      ans+=abs(b)-a
      ans+=1 
  else:
    if a<0:
      ans+=b-a
    else:
      ans+=a+b+1
print(ans)
N, K, Q = map(int, input().split())
A = []
for q in range(Q):
    a = int(input())
    A.append(a)
points = np.array([K for i in range(N)])
for a in A:
    points -= 1
    points[a-1] += 1
print(points)
for p in points:
    if p > 0:
        print('Yes')
    else:
        print('No')

### FIXED CODE ###

import numpy as np
N, K, Q = map(int, input().split())
A = []
for q in range(Q):
    a = int(input())
    A.append(a)
points2 = np.zeros(N)
for a in A:
    points2[a-1] += 1
results = []
for p in points2:
    if K - (Q - p) > 0:
        print('Yes')
    else:
        print('No')
from collections import deque
def DFS(S):
    word_list = ["dream", "dreamer", "erase", "eraser"]
    stack = deque(word_list)
    while stack:
        print(stack)
        word = stack.pop()
        if word == S[0]:
            return "Yes"
        for i in word_list:
            next_word = word + i
            check = S[0][:len(word + i)]
            if next_word != check:
                continue
            if next_word == check:
                stack.append(next_word)
    return "NO"






if __name__ == "__main__":
    S = [input()]
    print(DFS(S))

### FIXED CODE ###

def DFS(S):
    word_list = [ "dreamer","dream", "eraser", "erase"]
    stack = ["dream", "dreamer", "erase", "eraser"]
    while stack:
        word = stack.pop()
        if word == S[0]:
            return "YES"
        for i in word_list:
            next_word = word + i
            check = S[0][:len(word + i)]
            if next_word != check:
                continue
            if next_word == check:
                stack.append(next_word)
    return "NO"






if __name__ == "__main__":
    S = [input()]
    print(DFS(S))
# ANSHUL GAUTAM
# IIIT-D

A,B,C = map(int, input().split())
m = max(A,B,C)
s = sum(m-A,m-B,m-C)
if(s%2 == 0):
	print(s//2)
else:
	print(s//2 + 2)






### FIXED CODE ###

# ANSHUL GAUTAM
# IIIT-D

A,B,C = map(int, input().split())
m = max(A,B,C)
s = sum((m-A,m-B,m-C))
if(s%2 == 0):
	print(s//2)
else:
	print(s//2 + 2)
n = int(input())
sum = 0
for i in range(n+1):
    not (i % 3 == 0 and i % 5 ==0):
        sum += i
print(sum)

### FIXED CODE ###

n = int(input())
sum = 0
for i in range(n+1):
    if not (i % 3 == 0 or i % 5 ==0):
        sum += i
print(sum)
N, M = list(map(int, input().split()))
st = [list(map(int, input().split())) for _ in range(M)]

R = {}
for s, t in st:
  s -= 1
  t -= 1
  if s in R:
    R[s].append(t)
  else:
    R[s] = [t]

ans = N
for i in range(N - 1):
  DP = [0] * N
  for j in range(N - 2, -1, -1):
    su = 0
    amax = 0
    cnt = 0
    for x in R[j]:
      amax = max(amax, DP[x] + 1)
      su += A[-1]
    DP[j] = su / cnt
    if i == j and cnt != 1:
      DP[j] = (su - amax) / (cnt - 1)

  ans = min(ans, DP[0])
 
print(ans)

### FIXED CODE ###

N, M = list(map(int, input().split()))
st = [list(map(int, input().split())) for _ in range(M)]

R = {}
for s, t in st:
  s -= 1
  t -= 1
  if s in R:
    R[s].append(t)
  else:
    R[s] = [t]

DP = [0] * N
ans = N
D = [0] * N
for i in range(N - 2, -1, -1):
  ma = 0
  su = 0
  le = len(R[i])
  for j in R[i]:
    su += DP[j]
    ma = max(ma, DP[j])

  DP[i] = su / le + 1 
  if le == 1:
    D[i] = 0
  else:
    D[i] = DP[i] - (((su - ma) / (le - 1)) + 1)

P = [0] * N 
P[0] = 1
ma = 0
man = -1
for i in range(N - 1):
  t = P[i] / len(R[i])
  for j in R[i]:
    P[j] += t 
  t = P[i] * D[i]
  R[i].sort()
  if ma < t:
    ma = t
    man = i
 
if ma == -1:
  print(DP[0])
else:
  print(DP[0] - ma)
from collections import deque

N, K = map(int, input().split())
T = [[] for i in range(N)]
E = []
for i in range(N-1):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    T[a].append(b)
    T[b].append(a)
    E.append((a, b))


def bfs(n):
    visited = [False] * N
    dist = [0] * N
    queue = deque([n])
    while queue:
        node = queue.pop()
        if visited[node]:
            continue
        visited[node] = True
        for n in T[node]:
            if not visited[n]:
                dist[n] = dist[node] + 1
                queue.appendleft(n)
    return dist


dist = []
for i in range(N):
    dist.append(bfs(i))

ans = float('inf')
if K % 2 == 0:
    # 全ての頂点について全探索
    for i in range(N):
        ans = min(ans, len(list(filter(lambda x: K / 2 < x, dist[i]))))
else:
    # 全ての辺について全探索
    for a, b in E:
        dist = [min(d1, d2) for d1, d2 in zip(dist[a], dist[b])]
        ans = min(ans, len(list(filter(lambda x: (K-1) / 2 < x, dist))))

print(ans)


### FIXED CODE ###

from collections import deque

N, K = map(int, input().split())
T = [[] for i in range(N)]
E = []
for i in range(N-1):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    T[a].append(b)
    T[b].append(a)
    E.append((a, b))


def dfs(n):
    visited = [False] * N
    stack = [[n, 0]]
    longest = [-1, -1]

    while stack:
        node, weight = stack.pop()
        if visited[node]:
            continue
        visited[node] = True
        if longest[1] < weight:
            longest = [node, weight]

        for n in T[node]:
            if not visited[n]:
                stack.append([n, weight + 1])

    return longest


def bfs(n):
    visited = [False] * N
    dist = [0] * N
    queue = deque([n])
    while queue:
        node = queue.pop()
        if visited[node]:
            continue
        visited[node] = True
        for n in T[node]:
            if not visited[n]:
                dist[n] = dist[node] + 1
                queue.appendleft(n)
    return dist


xn, xw = dfs(0)
yn, yw = dfs(xn)
diameter = yw

d = bfs(0)
ans = float('inf')
if K % 2 == 0:
    # 全ての頂点について全探索
    for i in range(N):
        dist = bfs(i)
        ans = min(ans, len(list(filter(lambda x: K / 2 < x, dist))))
else:
    # 全ての辺について全探索
    for a, b in E:
        dist1 = bfs(a)
        dist2 = bfs(b)
        dist = [min(d1, d2) for d1, d2 in zip(dist1, dist2)]
        ans = min(ans, len(list(filter(lambda x: (K-1) / 2 < x, dist))))

print(ans)
N = int(input())
 monstors = [int(i) for i in input().split()]
 heros = [int(i) for i in  input().split()]
 init_monstor = sum(monstors)

 for i in range(N):
     if monstors[i] >= heros[i]:
         monstors[i] -= heros[i]
         heros[i] = 0
     else:
         heros[i] -= monstors[i]
         monstors[i] = 0
     if monstors[i+1] >= heros[i]:
         monstors[i+1] -= heros[i]
         heros[i] = 0
     else:
         heros[i] -= monstors[i+1]
         monstors[i+1] = 0
 print(init_monstor - sum(monstors))

### FIXED CODE ###

N = int(input())
monstors = [int(i) for i in input().split()]
heros = [int(i) for i in input().split()]
init_monstor = sum(monstors)

for i in range(N):
    if monstors[i] >= heros[i]:
        monstors[i] -= heros[i]
        heros[i] = 0
    else:
        heros[i] -= monstors[i]
        monstors[i] = 0
    if monstors[i+1] >= heros[i]:
        monstors[i+1] -= heros[i]
        heros[i] = 0
    else:
        heros[i] -= monstors[i+1]
        monstors[i+1] = 0
print("{}".format(init_monstor - sum(monstors)))
N, K = map(int, input().split())
P = list(map(int, input().split()))

S = []
sum_ = 0
for i, p in enumerate(P):
  sum_ += p
  S.append(sum_)


max_sum = 0
for i in range(N-K+1):
  max_sum = max(max_sum, S[i+K] - S[i])

res = (max_sum + K) / 2

print(res)

### FIXED CODE ###

N, K = map(int, input().split())
P = tuple(map(int, input().split()))
P2 = P[K:]

max_sum = 0
sum_ = sum(P[:K])

for p, q in zip(P, P2):
  max_sum = max(max_sum, sum_)
  sum_ += q - p
  
max_sum = max(max_sum, sum_)
          
res = (max_sum + K)/ 2
print(res)
import sys
sys.setrecursionlimit(300000)

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')

from math import log2


class Doubling(object):

    def __init__(self, N, K, next0):
        """
        ダブリングのメモ構築 O(NlogK)
        :param N: 解の存在空間の大きさ
        :param K: K個先までのステップを考慮する
        :param next0: i番目の要素の1個先の番号を要素として持つリスト
                      次の要素が存在しない場合には-1を要素として保持する
        """
        next = [[0] * N for _ in range(int(log2(K)) + 1)]
        next[0] = next0
        for k in range(int(log2(K))):
            for i in range(N):
                if next[k][i] == -1:
                    # 2^k個次に要素が無い時、当然2^(k+1)個次にも要素はない
                    next[k + 1][i] = -1
                else:
                    # i番目の要素の2^(k+1)個次の要素 := next[k][i](i番目の要素の2^k個次の要素)の2^k個先
                    next[k + 1][i] = next[k][next[k][i]]
        self.next = next

    def query(self, p, K):
        """
        p番目の要素のK個次の要素を求める O(logK)
        """
        for i in reversed(range(int(log2(K)) + 1)):
            if p == -1:
                return p
            if (K >> i) & 1:
                p = self.next[i][p]
        return p


S = input()

times = 10 ** 100
n0 = [i + 1 if c == 'R' else i - 1 for i, c in enumerate(S)]
d = Doubling(len(S), times, n0)

ans = [0] * len(S)
for i in range(len(S)):
    ans[d.query(i, times)] += 1
print(' '.join(str(x) for x in ans))


### FIXED CODE ###

S = input()

lst = list()
rev = False
r = 0
l = 0
start = 0
for i in range(len(S)):
    c = S[i]
    if rev and c == 'R':
        lst.append((start, r, l))
        r = 1
        l = 0
        start = i + 1
        rev = False
        continue
    if c == 'R':
        r += 1
    elif c == 'L':
        rev = True
        l += 1
lst.append((start, r, l))

ans = list()
for start, r, l in lst:
    for _ in range(r - 1):
        ans.append(0)

    a = 0
    b = 0
    if r % 2 != 0:
        a += 1
    a += r // 2
    b += r // 2
    if l % 2 != 0:
        b += 1
    a += l // 2
    b += l // 2
    ans.append(a)
    ans.append(b)

    for _ in range(l - 1):
        ans.append(0)

print(' '.join([str(x) for x in ans]))
def exc_or(int1, int2):
  exc_or = bin(int1^int2)
  return int(exc_or, 2)

def is_same(start_index_excor, alist, exc_ors):
  for i in range(0, N):
    if alist[i] != exc_ors[start_index_excor+i]:
      return False
  return True

def is_same_reverse(start_index_excor, alist, exc_ors):
  for i in range(0, N):
    if alist[i] != exc_ors[start_index_excor-i]:
      return False
  return True

N = int(input())
alist = list(map(int, input().split()))

exc_ors = []
for i in range(N-1, -1, -1):
  exc_ors.append(exc_or(alist[i-1], alist[i]))

start_index_excors = [index for index, exc_or in enumerate(exc_ors) if exc_or == alist[0]]
if len(start_index_excors) == 0:
  print("No")
  exit()
else:
  for start_index_excor in start_index_excors:
    if is_same(start_index_excor, alist, exc_ors) is True or is_same_reverse(start_index_excor, alist, exc_ors) is True:
      print("Yes")
      exit()
    else:
      pass
  print("No")
      

### FIXED CODE ###

def solve():
  n = int(input())
  ans = 0
  for a in map(int, input().split()):
    ans ^=a
  print("No" if ans else "Yes")
solve()
import math

A,B=map(int,input().split())
min=min(A,B)
rng=math.ceil(math.sqrt(min))
divisor=[1]
stack=[]
for i in range(2,min+1):
    if A%i==0 and B%i==0:
        p=min//i
        stack.append(p)
        for x in divisor:
            if i%x==0 and x!=1:
                break
        else:
            divisor+=[i]

while len(stack)==0:
    p=stack.pop()
    for x in divisor:
        if p%x==0 and x!=1:
            break
    else:
        divisor+=[p]

print(divisor)


### FIXED CODE ###

import math

divisor=[1]
stack=[]
#eiclidean algorithm
A,B=map(int,input().split())
p=max(A,B)
q=min(A,B)
int2=0
gcd=0
while True:
    int2=p%q
    if int2==0:
        gcd=q
        break
    else:
        p=q
        q=int2

if gcd!=1:
    stack.append(gcd)
    
for i in range(2,math.ceil(math.sqrt(gcd))+1):
    if gcd%i==0:
        p=gcd//i
        stack.append(p)
        for x in divisor:
            if i%x==0 and x!=1:
                break
        else:
            divisor+=[i]

while len(stack)!=0:
    p=stack.pop()
    for x in divisor:
        if p%x==0 and x!=1:
            break
    else:
        divisor+=[p]


print(len(divisor))
dic = {}
while True:
    try:
        word, pgn = input().split()

    if word in dic.keys():
        dic[word].append(int(pgn))
    else:
        dic[word] = [int(pgn)]
    except:
        for k, v in dic.items():
            print(k)
            print(' '.join(map(str, sorted(v))))
        break

### FIXED CODE ###

d = {}
while True:
    try:
        data = input().split()
    except:
        break
    word = data[0]
    number = int(data[1])
    if word in d:
        d[word].append(number)
    else:
        d[word] = [number]

for k, v in sorted(d.items(), key=lambda x: x[0]):
    print(k)
    print(*sorted(v))
# ARC073D - Simple Knapsack (ABC060D)
def knapsack_heavy(W: int, weight: "Array[int]", value: "Array[int]") -> int:
    lim = sum(value)
    dp = [0] + [float("inf")] * lim  # dp[i] := minimum weight at value i
    for w, v in zip(weight, value):
        for cur_v in range(lim, v - 1, -1):
            dp[cur_v] = min(dp[cur_v], dp[cur_v - v] + w)
    ret = max(v for v, w in enumerate(dp) if w <= W)
    return ret


def main():
    N, W, *A = map(int, open(0).read().split())
    weight, value = A[::2], A[1::2]
    ans = knapsack_heavy(W, weight, value)
    print(ans)


if __name__ == "__main__":
    main()

### FIXED CODE ###

# ARC073D - Simple Knapsack (ABC060D)
from itertools import accumulate


def main():
    N, W, *A = map(int, open(0).read().split())
    V, x = [[] for _ in range(4)], A[0]  # x: w1 (W1 ≤ wi ≤ w1 + 3)
    for i in range(0, 2 * N, 2):
        w, v = A[i : i + 2]
        V[w - x] += [v]
    for i in range(4):
        V[i] = tuple(accumulate([0] + sorted(V[i], reverse=1)))
    L = [len(v) for v in V]
    ans = 0
    for i in range(L[0]):
        for j in range(L[1]):
            for k in range(L[2]):
                w = i * x + j * (x + 1) + k * (x + 2)
                if w > W:
                    break
                l = min(L[3] - 1, (W - w) // (x + 3))
                v = V[0][i] + V[1][j] + V[2][k] + V[3][l]
                ans = max(ans, v)
    print(ans)


if __name__ == "__main__":
    main()
# coding: utf-8

import numpy as np
import math

A=int(input())
B=int(input())
C=int(input())
D=int(input())
E=int(input())

#１の位が0以外でより小さい値のものを最後にする
dishes=np.array([A,B,C,D,E])
dishes_1=np.array(list(map(lambda x: x%10, dishes)))
# print(dishes)
# print(dishes_1)
last=0
ans=0
if np.all(dishes_1==0):
  print(A+B+C+D+E)
else:
  dishes=np.stack([dishes, dishes_1], 1)
  dishes=sorted(dishes, key=lambda x: x[1])
  for i in range(len(dishes)):
      if dishes[i][1]!=0:
          last=dishes[i]
          dishes.pop(i)
          break
  for j in range(len(dishes)):
      ans=ans+dishes[j][0]+((10-dishes[j][0]%10)%10)
  print(ans+last[0])


### FIXED CODE ###

import numpy as np
import math

A=int(input())
B=int(input())
C=int(input())
D=int(input())
E=int(input())

#１の位が0以外でより小さい値のものを最後にする
dishes=np.array([A,B,C,D,E])
dishes_1=np.array(list(map(lambda x: x%10, dishes)))
# print(dishes)
# print(dishes_1)
last=0
ans=0
if np.all(dishes_1==0):
  print(A+B+C+D+E)
else:
  dishes=np.dstack([dishes, dishes_1])
  dishes=dishes[0]
  dishes=sorted(dishes, key=lambda x: x[1])
  for i in range(len(dishes)):
      if dishes[i][1]!=0:
          last=dishes[i]
          dishes=np.delete(dishes, [i], axis=0)
          break
  for j in range(len(dishes)):
      ans=ans+dishes[j][0]+((10-dishes[j][0]%10)%10)
  print(ans+last[0])
N, M = map(int, input().split())
*storeList = map(int, open().read().split())
ans = 0
for a, b in sorted(zip(storeList[::2], storeList[1::2])):
    ans += a * min(m, b) ; m = max(0, m - b)
print(ans)


### FIXED CODE ###

n, m = map(int, input().split())
tupList = []
for i in range(n):
    a, b = [int(i) for i in input().split()]
    tupList.append((a, b))

def tupVal(tup):
    return tup[0]
tupList.sort(key = tupVal)
ans = 0
for i in tupList:
    if m >= i[1]:
        ans += i[0] * i[1]
        m -= i[1]
    else:
        ans += i[0] * m
        break
print(ans)
#At coder 2020/2/9 D
import numpy as np

# 入力
N,K= map(int, input().split())
p = list(map(int, input().split())) 
#p2 = sorted(p, reverse=True)
#print(p2)
kk=[0] * (N-K+1)
p=np.array(p)
if N==K:
    kk=sum(p)
else:
    for ii in range(N-K+1):
        kk[ii]=np.sum(p[ii:K+ii])
kk=max(kk)
K=float(K)
kk=float(kk)
ans=0.5*(kk+K)

print(ans)

### FIXED CODE ###

#At coder 2020/2/9 D
#import numpy as np

# 入力
N,K= map(int, input().split())
p = list(map(int, input().split())) 
#p2 = sorted(p, reverse=True)
#print(p2)
kk=[0] * (N-K+1)
#p=np.array(p)
kk[0]=sum(p[0:K])
for ii in range(1,N-K+1):
    kk[ii]=kk[ii-1]-p[ii-1]+p[K+ii-1]
kk=max(kk)
K=float(K)
kk=float(kk)
ans=0.5*(kk+K)

print(ans)
n,m=map(int,input.split())
print(n*m if max(n,m)<10 else -1)

### FIXED CODE ###

n,m=map(int,input().split())
print(n*m if max(n,m)<10 else -1)
A, B = map(int, input().split())
X = 0
if A >= 13:
	X = B
elif A < 13 AND A >= 6:
	X = B/2

print(X)

### FIXED CODE ###

A, B = map(int, input().split())
X = 0
if A > 12:
	X = B
elif A > 5:
	X = int(B/2)
elif A < 6:
	X = 0

print(X)
n = int(input())
s = []
for i in range(n):
    s.append(str(input()))
march = ["M","A","R","C","H"]
march_num = [0,0,0,0,0]
for i in range(n):
    if s[i][0] in march:
        march_num[march.index(s[i][0])] += 1
ans = 0
for i in range(len(s)-2):
    for j in range(i+1,len(s)-1):
        for k in range(j+1,len(s)):
            ans += (march_num[i]*march_num[j]*march_num[k])
print(ans)

### FIXED CODE ###

n = int(input())
s = ["" for _ in range(n)]
for i in range(n):
    s[i] = str(input())
    s[i] = s[i][0]

march = ["M","A","R","C","H"]
march_num = [0,0,0,0,0]

for i in range(len(s)):
    if s[i] in march:
        march_num[march.index(s[i])] += 1
ans = 0
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            ans += (march_num[i]*march_num[j]*march_num[k])
print(ans)