Problem:
 Score : 300 points    Problem Statement There are N people. The name of the i -th person is S_i .  We would like to choose three people so that the following conditions are met:   The name of every chosen person begins with M , A , R , C or H .  There are no multiple people whose names begin with the same letter.   How many such ways are there to choose three people, disregarding order?  Note that the answer may not fit into a 32 -bit integer type.      Constraints  1 \leq N \leq 10^5  S_i consists of uppercase English letters.  1 \leq |S_i| \leq 10  S_i \neq S_j (i \neq j)         Input Input is given from Standard Input in the following format:  N  S_1  :  S_N       Output If there are x ways to choose three people so that the given conditions are met, print x .        Sample Input 1 5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI      Sample Output 1 2  We can choose three people with the following names:    MASHIKE , RUMOI , HABORO    MASHIKE , RUMOI , HOROKANAI    Thus, we have two ways.       Sample Input 2 4
ZZ
ZZZ
Z
ZZZZZZZZZZ      Sample Output 2 0  Note that there may be no ways to choose three people so that the given conditions are met.       Sample Input 3 5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO      Sample Output 3 7

Solution (Python):
import itertools
n = int(input())

lst1 = [0]*5
lst2 = [ "M","A","R","C","H" ]
for i in range(n):
    s = input()
    for j in range(5):
        if s[0] == lst2[j]:
            lst1[j] += 1
            break
    
l = (itertools.combinations(lst1,3))
ans = 0
for i in l:
    ans += i[0]*i[1]*i[2]
print(ans)

Solution (Python):
from collections import defaultdict
import itertools

march = set('MARCH')
count = defaultdict(int)
n = int(input())
for _ in range(n):
    name = input()
    if name[0] in march:
        count[name[0]] += 1


num_of_people = []
for s in 'MARCH':
    num_of_people.append(count[s])


ans = 0
for a, b, c in itertools.combinations(num_of_people, 3):
    ans += a * b * c

print(ans)

Solution (Python):
import itertools
N=int(input())
S=[list(input()) for _ in range(N)]
d={'M':0,'A':1,'R':2,'C':3,'H':4}
a=[0]*5
l=set('MARCH')
for s in S:
    if s[0] in l:
        a[d[s[0]]]+=1
for i in reversed(range(5)):
    if a[i]==0:
        del a[i]
X=list(itertools.combinations(a,3))
len_x=len(X)
ans=0
def f(ary,i):
    if i==0:
        return ary[i]
    return ary[i]*f(ary,i-1)
for x in X:
    ans+=f(x,2)
print(ans)

Solution (Python):
N=int(input())
m=0
a=0
r=0
c=0
h=0
for _ in range(N):
  s=input()
  if s[0]=="M":
    m+=1
  elif s[0]=="A":
    a+=1
  elif s[0]=="R":
    r+=1
  elif s[0]=="C":
    c+=1
  elif s[0]=="H":
    h+=1
ans=0
ans+=m*a*r
ans+=m*a*c
ans+=m*a*h
ans+=m*r*c
ans+=m*r*h
ans+=m*c*h
ans+=a*r*c
ans+=a*r*h
ans+=a*c*h
ans+=r*c*h
print(ans)

Solution (Python):
from itertools import combinations
dic = dict(zip(list("MARCH"),[0]*len("MARCH")))
N = int(input())
for i in range(N):
    tmp = input()[0]
    if tmp in "MARCH":
        dic[tmp] += 1
c = combinations(list("MARCH"),3)
ans = 0
for i in c:
    ans += dic[i[0]]*dic[i[1]]*dic[i[2]]
print(ans)

Solution (Python):
n=int(input())
s=[input() for i in range(n)]
m=0
a=0
r=0
c=0
h=0

for i in s:
  if i[0]=="M":
    m+=1
  elif i[0]=="A":
    a+=1
  elif i[0]=="R":
    r+=1
  elif i[0]=="C":
    c+=1
  elif i[0]=="H":
    h+=1

nan=0
li=[m,a,r,c,h]

for i in li:
  if i>0:
    nan+=1

import itertools

if nan<3:
  print(0)
else:
  ans=0
  for x,y,z in itertools.combinations(range(5),3):
    ans+=li[x]*li[y]*li[z]
  print(ans)

Solution (Python):
n=int(input())
a=[list(input())for i in range(n)]
d={'M':0,"A":0,"R":0,'C':0,'H':0}
for i in a:
    if i[0] in d:
        d[i[0]]+=1
dl=[]
for i in d.values():
    dl.append(i)
ans=0
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            ans+=dl[i]*dl[j]*dl[k]
print(ans)

Solution (Python):
import itertools
N=int(input())
lst=[input() for i in range(N)]
data={"M":0,"A":0,"R":0,"C":0,"H":0}
for S in lst:
    for c in data:
        if S[0]==c:
            data[c]+=1

ite=itertools.combinations("MARCH",3)
print(sum([data[a]*data[b]*data[c] for a,b,c in ite]))

Solution (Python):
from collections import defaultdict
from itertools import combinations

N = int(input())
S = [input()[0] for _ in range(N)]
dic_S = defaultdict(int)
for s in S:
  if s in "MARCH":
    dic_S[s] += 1

ans = 0
for a, b, c in combinations(dic_S.values(), 3):
  ans += a*b*c
  
print(ans)

Solution (Python):
N= int(input())
S = ['M','A','R','C','H']
C = [0]*5
for _ in range(N):
  X = (input())[0]
  if X in S:
    C[S.index(X)] += 1
from itertools import permutations, combinations,combinations_with_replacement,product
L = list(combinations(range(5), 3))   
ans = 0
for i in L:
  ans += C[i[0]]*C[i[1]]*C[i[2]]
print(ans)

Solution (Python):
from itertools import combinations
n = int(input())
counter = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for i in range(n):
  s = input()[0]
  if s in "MARCH":
    counter[s] += 1
ans = 0
for c in combinations("MARCH", 3):
  ans += counter[c[0]] * counter[c[1]] * counter[c[2]]
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
n=int(input())
S=[input().strip() for _ in range(n)]
a=[]

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


from collections import Counter
for s in S:
    if s[0] in ["M","A","R","C","H"]:
        a.append(s[0])

if len(a)<=2:
    print(0)
    exit()

a=Counter(a)


asum=sum(a.values())
b=0
c=0
for i in a.values():
    if i ==1:
        continue
    if i==2:
        b+=asum-i
    if i>=3:
        b+=cmb(i,2)*(asum-i)
        c+=cmb(i,3)
print(cmb(asum,3)-b-c)

Solution (Python):
N = int(input())
k = [0]*5
ans = 0
for i in range(N):
  S = input()
  if S[0] == "M":
    k[0] += 1
  elif S[0] == "A":
    k[1] += 1
  elif S[0] == "R":
    k[2] += 1
  elif S[0] == "C":
    k[3] += 1
  elif S[0] == "H":
    k[4] += 1
  else:
    continue
ans += k[0]*k[1]*k[2]
ans += k[0]*k[1]*k[3]
ans += k[0]*k[1]*k[4]
ans += k[0]*k[2]*k[3]
ans += k[0]*k[2]*k[4]
ans += k[0]*k[3]*k[4]
ans += k[1]*k[2]*k[3]
ans += k[1]*k[2]*k[4]
ans += k[1]*k[3]*k[4]
ans += k[2]*k[3]*k[4]
print(ans)

Solution (Python):
import itertools as it

N = int(input())
march = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for i in range(N):
    ini = input()[0]
    if ini in march:
        march[ini] += 1
ans = 0
for i, j, k in it.combinations("MARCH", 3):
    ans += march[i] * march[j] * march[k]
print(ans)

Solution (Python):
n=int(input())
m,a,r,c,h=0,0,0,0,0
for i in range(n):
    s=input()
    if s[0]=='M':
        m+=1
    elif s[0]=='A':
        a+=1
    elif s[0]=='R':
        r+=1
    elif s[0]=='C':
        c+=1
    elif s[0]=='H':
        h+=1

ans=m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h
print(ans)

Solution (Python):
N = int(input())
D = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
for i in range(N):
  S = input()
  if S[0] in D:
    D[S[0]] += 1
L1 = [D[i] for i in D]
M = 0
for i in range(3):
  for j in range(i+1, 4):
    for k in range(j+1, 5):
      M += L1[i]*L1[j]*L1[k]
print(M)

Solution (Python):
from itertools import combinations

N = int(input())
name=[]
m,a,r,c,h=0,0,0,0,0
for i in range(N):
    si = input()
    if si[0] in ['M', 'A', 'R', 'C', 'H']:
        name.append(si)
        if si[0]=='M':
            m+=1
        if si[0]=='A':
            a+=1
        if si[0]=='R':
            r+=1
        if si[0]=='C':
            c+=1
        if si[0]=='H':
            h+=1

if name==[]:
    print(0)
    exit()

names=dict({'m':m,'a':a,'r':r,'c':c,'h':h})
ans=0
for n in list(combinations(['m','a','r','c','h'],3)):
    ans += names[n[0]] * names[n[1]] * names[n[2]]
print(ans)

Solution (Python):
n=int(input())
s=[]
for i in range(n):
    s.append(input())
march_dict={"M":0,"A":1,"R":2,"C":3,"H":4}
march_list=[0,0,0,0,0]
for i in range(n):
    if s[i][0] in march_dict:
        march_list[march_dict[s[i][0]]]+=1
ans=0
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            ans+=march_list[i]*march_list[j]*march_list[k]
print(ans)

Solution (Python):
from itertools import combinations
from collections import Counter

n = int(input())
s = [input()[0] for _ in range(n)]

c  =Counter(s)
ans = 0
for x, y, z in combinations("MARCH", 3):
    ans += c[x] * c[y] * c[z]

print(ans)

Solution (Python):
from itertools import combinations

n = int(input())
d = [0] * 5

for _ in range(n):
    s = input()
    if s[0] == "M":
        d[0] += 1
    if s[0] == "A":
        d[1] += 1
    if s[0] == "R":
        d[2] += 1
    if s[0] == "C":
        d[3] += 1
    if s[0] == "H":
        d[4] += 1

d = [n for n in d if n !=0]

comb = combinations(d, 3)
ans = 0
for c in comb:
    ans += c[0]*c[1]*c[2]

print(ans)

Solution (Python):

import sys
from itertools import product

def solve(N: int, S: "List[str]"):
    answer = 0
    march_dict = {'M':0,'A':0,'R':0,'C':0,'H':0}
    for i in range(N):
        if march_dict.get(S[i][0]) != None:
            march_dict[S[i][0]] += 1
    values = list(march_dict.values())
    bit_list = product([0,1],repeat=5)

    for bit in bit_list:
        if bit.count(1) == 3:
            a = 1
            for i in range(5):
                if bit[i] == 1:
                    a *= values[i]
            answer += a

    print(answer)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    S = [next(tokens) for _ in range(N)]  
    solve(N, S)

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
d = {'M': 0, "A": 0, "R": 0, "C": 0, "H": 0}
for _ in range(N):
    try:
        d[input()[0]] += 1
    except KeyError:
        pass

ans = 0
v = d.values()
v = list(v)
for i in range(5):
    for j in range(i+1, 5):
        for k in range(j+1, 5):
            ans += v[i]*v[j]*v[k]
print(ans)

Solution (Python):
n = int(input())
s = [input() for i in range(n)]
dic = {'M':0,'A':1,'R':2,'C':3,'H':4}
ar = [0, 0, 0, 0, 0]
for i in s:
    if i[0] not in dic:
        continue
    ar[dic[i[0]]]+=1
dp = [[0 for i in range(6)] for j in range(6)]
dp[0][0] = 1
for i in range(1, 6):
    for j in range(6):
        dp[i][j] = dp[i-1][j]
        if j==0:
            continue
        dp[i][j] += dp[i-1][j-1]*ar[i-1]
print(dp[5][3])

Solution (Python):
n = int(input())
s = [input() for i in range(n)]
lst = ["M","A","R","C","H"]
dct = {c:0 for c in lst}
ans = 0

for name in s:
    if name[0] in dct:
        dct[name[0]] += 1

for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            ans += dct[lst[i]]*dct[lst[j]]*dct[lst[k]]

print(ans)

Solution (Python):
n=int(input())
name=[]
for i in range(n):
    name.append(input().split(" "))
m, a, r, c, h=0, 0, 0, 0, 0
for w in range(n):
    if name[w][0][0]=='M':
        m+=1
    if name[w][0][0]=='A':
        a+=1
    if name[w][0][0]=='R':
        r+=1
    if name[w][0][0]=='C':
        c+=1
    if name[w][0][0]=='H':
        h+=1
print(m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h)

Solution (Python):
from itertools import combinations

capital = ['M', 'A', 'R', 'C', 'H']
count = [0 for i in range(5)]

N = int(input())

for i in range(N):
  name = input()
  init = name[0]
  for i, c in enumerate(capital):
    if init == c:
      count[i] += 1
    
ret = 0
for comb in combinations(count, 3):
  ret += comb[0] * comb[1] * comb[2]
  
print(ret)

Solution (Python):
from itertools import combinations


import sys

n = int(input())
march = ["M", "A", "R", "C", "H"]
num_mar = {}

s = []
for i in range(n):
    t = input()
    if t[0] not in march:
        continue
    s.append(t)
    if t[0] not in num_mar.keys():
        num_mar[t[0]] = 1
    else:
        num_mar[t[0]] += 1



len_num_mar = len(num_mar.keys())



if len_num_mar < 3:
    print(0)
    sys.exit()



ans = 0

for keys in combinations(num_mar.keys(), 3):
    res = 1
    for k in keys:
        res *= num_mar[k]
    ans += res




print(ans)

Solution (Python):
from collections import defaultdict
n=int(input())
c=["M","A","R","C","H"]
d=defaultdict(int, {})
ans=0
for _ in range(n):
  s=input()
  d[s[0]]+=1
for i in range(len(c)):
  for j in range(i+1,len(c)):
    for k in range(j+1,len(c)):
      ans+=d[c[i]]*d[c[j]]*d[c[k]]
print(ans)

Solution (Python):
n=int(input())
M=['M','A','R','C','H']
S = {'M':0,'A':0,'R':0,'C':0,'H':0}
for _ in range(n):
  a = input()
  if a[0] in S:
  	S[a[0]] +=1
ANS=0
for i in range(len(M)):
  for j in range(i+1,len(M)):
    for k in range(j+1,len(M)):
      ANS += (S[M[i]] * S[M[j]]* S[M[k]])
print(ANS)

Solution (Python):
def main():
    n=int(input())
    S=list(input() for _ in range(n))
    a,b,c,d,e=0,0,0,0,0
    for s in S:
        if s[0]=="M": a += 1
        if s[0]=="A": b += 1
        if s[0]=="R": c += 1
        if s[0]=="C": d += 1
        if s[0]=="H": e += 1
    print(c*(a+b)*(d+e)+a*b*(c+d+e)+d*e*(a+b+c))
main()

Solution (Python):
import itertools
from operator import mul
from functools import reduce
heads = ["M","A","R","C","H"]

N = int(input())
S = [0,0,0,0,0]

for i in range(N):
  s = input()[0]
  if s in heads:
    n = heads.index(s)
    S[n] += 1

S = [i for i in S if i != 0]

nums = list(itertools.combinations(S,3))

total = 0

for list in nums:
  total += reduce(mul,list)

print(total)

Solution (Python):
N = int(input())
c, MARCH = [0] * 5, ["M", "A", "R", "C", "H"]
for _ in range(N):
    ini = input()[0]
    if ini in MARCH:
        c[MARCH.index(ini)] += 1
print(c[0]*c[1]*(c[2]+c[3]+c[4]) + (c[0]+c[1])*c[2]*(c[3]+c[4]) + (c[0]+c[1]+c[2])*c[3]*c[4])

Solution (Python):
import itertools

N = int(input())
nums = {key: 0 for key in "MARCH"}

for _ in range(N):
    name = input()
    if name[0] in nums:
        nums[name[0]] += 1

result = 0
for combination in itertools.combinations("MARCH", 3):
    first, second, third = combination
    result += nums[first] * nums[second] * nums[third]

print(result)

Solution (Python):
n=int(input())
s=[input() for i in range(n)]
d={}
for i in range(n):
  if (s[i][0]=='M' or s[i][0]=='A' or s[i][0]=='C' or s[i][0]=='R' or s[i][0]=='H') and s[i][0] not in d:
    d[s[i][0]]=1
  elif s[i][0] in d:
    d[s[i][0]]+=1
nd=list(d.values())
if len(nd)<3:
  print(0)
else:
  ans=0
  for i in range(len(nd)-2):
    for j in range(i+1,len(nd)-1):
      for k in range(j+1,len(nd)):
        ans+=nd[i]*nd[j]*nd[k]
  print(ans)

Solution (Python):
import sys
from collections import Counter
from itertools import combinations

MARCH = set('MARCH')

n = int(sys.stdin.readline().rstrip())
s = [x[0] for x in sys.stdin.read().split() if x[0] in MARCH]

def main():
    c = Counter(s)
    ways = 0
    for comb in combinations('MARCH', 3):
        res = 1
        for i in comb:
            res *= c.get(i, 0)
        ways += res
    
    return ways

if __name__ == '__main__':
    ans = main()
    print(ans)

Solution (Python):
N = int(input())
inis = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for i in range(N):
    s = list(input())
    if s[0] == "M" or s[0] == "A" or s[0] == "R" or s[0] == "C" or s[0] == "H":
        inis[s[0]] += 1

ans = 0
march = ["M","A","R","C","H"]
for i in range(len(march)):
    for j in range(i, len(march)):
        for k in range(j, len(march)):
            if march[i] != march[j] and march[i] != march[k] and march[j] != march[k]:
                ans += inis[march[i]] * inis[march[j]] * inis[march[k]]

print(ans)

Solution (Python):
N = int(input())

w = "MARCH"
count = {key: 0 for key in w}

for i in range(N):
    S = input()
    c = S[0]
    if c in w:
        count[c] += 1

ans = 0
M = len(w)

for i in range(M):
    for j in range(i + 1, M):
        for k in range(j + 1, M):
            ans += count[w[i]] * count[w[j]] * count[w[k]]

print(ans)

Solution (Python):
n = int(input())
d = {c: 0 for c in 'MARCH'}
for i in range(n):
    s = input()
    c = s[0]
    if c in d:
        d[c] += 1
v = [d[c] for c in d]

import itertools
ans = 0
for i, j, k in itertools.combinations(range(5), 3):
    ans += v[i] * v[j] * v[k]
print(ans)

Solution (Python):
N = int(input())
S = []
for i in range(N):
  S.append(input())

key = "MARCH"
C = [0] * 5

for i in range(len(S)):
  for j in range(5):
    if S[i][0] == key[j]:
      C[j] += 1

ans = 0
for i in range(5):
  for j in range(i+1, 5):
    for k in range(j+1, 5):
      ans += C[i] * C[j] * C[k]

print(ans)

Solution (Python):
import sys
from collections import Counter
from itertools import combinations
n = int(sys.stdin.readline().strip())
s_ls = []
cnt = Counter()
for i in range(n):
    s = sys.stdin.readline().strip()
    cnt.update(s[0])
_sum = 0
for combi in combinations("MARCH", 3):
    score = 1
    for c in combi:
        score *= cnt[c]
    _sum += score
print(_sum)

Solution (Python):
n = int(input())
a = b = c = d = e = 0
for _ in range(n):
    s = input()
    if s[0] == 'M':
        a += 1
    elif s[0] == 'A':
        b += 1
    elif s[0] == 'R':
        c += 1
    elif s[0] == 'C':
        d += 1
    elif s[0] == 'H':
        e += 1
print(a * b * c + a * b * d + a * b * e + a * c * d + a * c * e + a * d * e +
      b * c * d + b * c * e + b * d * e + c * d * e)

Solution (Python):
from collections import defaultdict
from itertools import combinations
N = int(input())
S = defaultdict(set)
march = 'MARCH'
for i in range(N):
    a = input()
    for j in range(5):
        if a[0] == march[j]:
            S[j].add(a)
sv = []
for i in S.values():
    sv.append(len(i))
if len(sv) < 3:
    print(0)
else:
    ans = 0
    for a,b,c in combinations(sv,3):
        ans += a*b*c
    print(ans)

Solution (Python):
from collections import defaultdict
N = int(input())
S = defaultdict(set)
march = 'MARCH'
for i in range(N):
    a = input()
    for j in range(5):
        if a[0] == march[j]:
            S[j].add(a)
sv = []
for i in S.values():
    sv.append(len(i))
if len(sv) < 3:
    print(0)
else:
    ans = 0
    for i in range(len(sv)-2):
        for j in range(i+1,len(sv)-1):
            for k in range(j+1,len(sv)):
                ans += sv[i]*sv[j]*sv[k]
    print(ans)

Solution (Python):
from collections import defaultdict
N = int(input())
S = defaultdict(set)
for i in range(N):
    a = input()
    if a[0] ==  'M':
        S[0].add(a)
    if a[0] == 'A':
        S[1].add(a)
    if a[0] == 'R':
        S[2].add(a)
    if a[0] == 'C':
        S[3].add(a)
    if a[0] == 'H':
        S[4].add(a)
d = 1
count = 0
sv = []
for i in S.values():
    sv.append(len(i))
if len(sv) < 3:
    print(0)
else:
    ans = 0
    for i in range(len(sv)-2):
        for j in range(i+1,len(sv)-1):
            for k in range(j+1,len(sv)):
                ans += sv[i]*sv[j]*sv[k]
    print(ans)

Solution (Python):
from collections import defaultdict
from itertools import combinations
N = int(input())
d = defaultdict(int)
strlist = ["M","A","R","C","H"]
for i in range(N):
    S = input()
    for s in strlist:
        if S[0] == s:
            d[s] += 1
combs = list(combinations(strlist,3))
ans = 0
for s1,s2,s3 in combs:
    ans += d[s1] * d[s2] * d[s3]
print(ans)

Solution (Python):
import itertools
n = int(input())
S = "MARCH"
d = {s:0 for s in S}
ans = 0
for i in range(n):
  f = input()[0]
  if f in S:
    d[f] += 1
for x,y,z in itertools.combinations(d.keys(),3):
  ans += d[x] * d[y] * d[z]
print(ans)

Solution (Python):
import itertools
n = int(input())
S = [input() for _ in range(n)]
M,A,R,C,H = 0,0,0,0,0
ans = 0
for s in S:
  if s[0] == "M":
    M += 1
  elif s[0] == "A":
    A += 1
  elif s[0] == "R":
    R += 1
  elif s[0] == "C":
    C += 1
  elif s[0] == "H":
    H += 1
U = [M,A,R,C,H]
for x,y,z in itertools.combinations(U,3):
  ans += x * y * z
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
m, a, r, c, h = [0, 0, 0, 0, 0]
for _ in range(N):
    s = input()
    if s[0] == "M":
        m += 1
    elif s[0] == "A":
        a += 1
    elif s[0] == "R":
        r += 1
    elif s[0] == "C":
        c += 1
    elif s[0] == "H":
        h += 1
print(m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h)

Solution (Python):
from itertools import  combinations as c
n=int(input())
l=[0]*5
for i in range(n):
  s=input()
  s=s[0]
  if s in "MARCH":
    l["MARCH".index(s)]+=1
ans=0
for x,c,v in c(range(5),3):
  ans+=l[x]*l[c]*l[v]
print(ans)

Solution (Python):
m=0
a=0
r=0
c=0
h=0

N=int(input())
for i in range(N):
  S=input()
  if S[0]=='M':
    m+=1
  if S[0]=='A':
    a+=1
  if S[0]=='R':
    r+=1
  if S[0]=='C':
    c+=1
  if S[0]=='H':
    h+=1
    
nums=[m, a, r, c, h]

counter=0
for i in range(3):
  for j in range(i+1, 4):
    for k in range(j+1, 5):
      counter+=nums[i]*nums[j]*nums[k]
      
print(counter)

Solution (Python):


n = int(input())
from collections import defaultdict
d = defaultdict(int)

for _ in range(n):
    d[input()[0]]+=1

march = []
for k,v in d.items():
    if k in ["M","A","R","C","H"]:
        march.append(v)



from itertools import combinations
from operator import mul
ret = 0
if len(march) <= 2:
    print(0)
else:
    ret = 0
    for i in combinations(march,3):
        mul_of_i = 1
        for j in i:
            mul_of_i *= j
        ret += mul_of_i
    print(ret)

Solution (Python):
n = int(input())
s = [input() for _ in range(n)]

march='MARCH'
h = []
for x in s:
  if x[0] in march:
    h.append(x[0])

d = {}
for c in march:
  d[c]=0

for x in h:
  d[x] += 1

ans=0
import itertools
for com in itertools.combinations(d.values(), r=3):
  pro=1
  for x in com:
    pro *= x
  ans+=pro

print(ans)

Solution (Python):
n=int(input())
D={}
for i in range(n):
      s=input()[0]
      if s in D:
            D[s]+=1
      else:
            D[s]=1
L=[]
for p in "MARCH":
      if p in D:
            L.append(D[p])
ans=0
for i in range(len(L)):
      for j in range(i+1,len(L)):
            for k in range(j+1,len(L)):
                  ans +=L[i]*L[j]*L[k]
print(ans)

Solution (Python):
from collections import defaultdict
n = int(input())
dic = defaultdict(int)
for i in range(n):
    dic[input()[0]] += 1
L = []
for s in "MARCH":
    if s in dic:
        L.append(dic[s])

ans = 0
for i in range(len(L)):
    for j in range(i+1,len(L)):
        for k in range(j+1,len(L)):
            ans += L[i]*L[j]*L[k]
print(ans)

Solution (Python):
n = int(input())
s = [input() for i in range(n)]

f = [a for a in s if a.startswith('M')]
g = [b for b in s if b.startswith('A')]
h = [c for c in s if c.startswith('R')]
i = [d for d in s if d.startswith('C')]
j = [e for e in s if e.startswith('H')]

k = len(f)*len(g)*len(h)
l = len(f)*len(g)*len(i)
m = len(f)*len(g)*len(j)
n = len(f)*len(h)*len(i)
o = len(f)*len(h)*len(j)
p = len(f)*len(i)*len(j)
q = len(g)*len(h)*len(i)
r = len(g)*len(h)*len(j)
s = len(g)*len(i)*len(j)
t = len(h)*len(i)*len(j)

sum = k+l+m+n+o+p+q+r+s+t
print(sum)

Solution (Python):
import itertools

A = "MARCH"
c = {a: 0 for a in A}
N = int(input())
for _ in range(N):
    S = input()
    if S[0] in A:
        c[S[0]] += 1

print(sum([c[cb[0]] * c[cb[1]] * c[cb[2]]
           for cb in itertools.combinations(A, 3)]))

Solution (Python):
n=int(input())
A=["M","A","R","C","H"]
B=[0,0,0,0,0]
s=[]
for i in range(n):
    S=input()
    if S[0] in A:
        s.append(S)

for i in s:
    for j in range(5):
        if A[j]==i[0]:
            B[j]+=1
            break
c=B.count(0)
if c>2:
    print(0)
else:
    c=0
    for i in range(3):
        for j in range(i+1,4):
            for k in range(j+1,5):
                c+=(B[i]*B[j]*B[k])
    print(c)

Solution (Python):
import itertools
'''
　 ∧_,,∧    究極奥義「WAがACになーれ！！」
　（`・ω・)つ━☆・*。
　⊂　　 ノ 　　　・゜+.
　 し’´Ｊ　　*・ 
'''
n=int(input())

a=["M","A","R","C","H"]
cnt=[0]*5
for i in range(n):
    s=input()
    for i in range(5):
        if s[0]==a[i]:
            cnt[i]+=1
ans=0
for i in itertools.combinations(range(5),3):
    ans+=cnt[i[0]]*cnt[i[1]]*cnt[i[2]]
print(ans)

Solution (Python):
import itertools
'''
　 ∧_,,∧    究極奥義「WAがACになーれ！！」
　（`・ω・)つ━☆・*。
　⊂　　 ノ 　　　・゜+.
　 し’´Ｊ　　*・ 
'''
import sys
input = sys.stdin.readline
n=int(input())

a=["M","A","R","C","H"]
cnt=[0]*5
for i in range(n):
    s=input()
    for i in range(5):
        if s[0]==a[i]:
            cnt[i]+=1
ans=0
for i in itertools.combinations(range(5),3):
    ans+=cnt[i[0]]*cnt[i[1]]*cnt[i[2]]
print(ans)

Solution (Python):
n = int(input())
a = [0]*6
for i in range(n):
    s=input()
    if   s[:1] == "M":j=0
    elif s[:1] == "A":j=1
    elif s[:1] == "R":j=2
    elif s[:1] == "C":j=3
    elif s[:1] == "H":j=4
    else:j=5
    
    a[j]+=1

ans=0
for i in range(5):
    for j in range(5):
        for k in range(5):
            if j == k or i ==k or j==i : f=0
            else:
              f=1
              
              
            ans += a[i]* a[j] * a[k] * f

print(ans//6)

Solution (Python):
n = int(input())
s = [input() for _ in range(n)]
prefix = ['M', 'A', 'R', 'C', 'H']
cnt = [0] * 5
ans = 0
for i in range(n):
    for j in range(5):
        if s[i][0] == prefix[j]:
            cnt[j] += 1
for i in range(2 ** 5):
    flag = [False] * 5
    for j in range(5):
        if (i >> j) & 1:
            flag[j] = True
    if flag.count(True) == 3:
        tmp = 1
        for k in range(5):
            if flag[k]:
                tmp *= cnt[k]
        ans += tmp
print(ans)

Solution (Python):
import sys
from itertools import combinations as comb
n, *S = open(0).read().split()
s = [i[0] for i in S]
c = [s.count(i) for i in 'MARCH']
ret = sum(x * y * z for x, y, z in comb(c, 3))
print(ret)

Solution (Python):
n = int(input())
lst = [0] * 5
march = ['M', 'A', 'R', 'C', 'H']
for i in range(n):
  nf = input()[0]
  if nf in march:
    lst[march.index(nf)] += 1
ret = 0
for a in range(0, 3):
  for b in range(a + 1, 4):
    for c in range(b + 1, 5):
      ret += lst[a] * lst[b] * lst[c]
print(ret)

Solution (Python):
from itertools import combinations
n=int(input())
march=[0,0,0,0,0]
for i in range(n):
  k=input()
  if k[0]=="M":
    march[0]+=1
  if k[0]=="A":
    march[1]+=1
  if k[0]=="R":
    march[2]+=1
  if k[0]=="C":
    march[3]+=1
  if k[0]=="H":
    march[4]+=1
ans=0
for (i,j,k) in combinations(march,3):
  ans+=i*j*k
print(ans)

Solution (Python):
import sys
from operator import mul
from functools import reduce

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

MARCH = 'MARCH'
def cmb(n,r):
    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 = INT()
S = [input().rstrip() for _ in range(N)]

S = [s for s in S if s[0] in MARCH]

A = [0]*5
for s in S:
	A[MARCH.index(s[0])] += 1



if sum(A) < 3:
	print(0)
	sys.exit()

ans = cmb(sum(A), 3)


for a in A:
	if a<=1:continue
	if a>=3:
		ans -= cmb(a, 3)
	ans -= cmb(a, 2) * (sum(A)-a)

print(ans)

Solution (Python):
from collections import Counter
from itertools import combinations

n = int(input())
l = [input()[0] for _ in range(n)]
lc = Counter(l)

con = []
for c in "MARCH":
    if c in lc:
        con.append(lc[c])
ans = 0
for a, b, c in combinations(con, 3):
    ans += a * b * c
print(ans)

Solution (Python):
import itertools
N = int(input())
dic = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
for i in range(N):
  s = input()
  if s[0] in dic:
    dic[s[0]] += 1
lst = list(dic.values())
ans = list(itertools.combinations(lst, 3))
cnt = 0
for i in ans:
    if 0 in ans:
        break
    else:
        cnt += i[0]*i[1]*i[2]

print(cnt)

Solution (Python):
N = int(input())
l = [0]*5
l1 = [[0,1,2],[0,1,3],[0,1,4],[0,2,3],[0,2,4],[0,3,4],
      [1,2,3],[1,2,4],[1,3,4],[2,3,4]]
ans = 0
for i in range(N):
  s = input()
  if s[0] == "M":
    l[0] += 1
  elif s[0] == "A":
    l[1] += 1
  elif s[0] == "R":
    l[2] += 1
  elif s[0] == "C":
    l[3] += 1
  elif s[0] == "H":
    l[4] += 1
for i in range(len(l1)):
  ans += l[l1[i][0]]*l[l1[i][1]]*l[l1[i][2]]
print(ans)

Solution (Python):
n=int(input())
s=[input() for i in range(n)]
m,a,r,c,h=0,0,0,0,0
for i in range(len(s)):
    x=s[i][0]
    if x=="M":m+=1
    elif x=="A":a+=1
    elif x=="R":r+=1
    elif x=="C":c+=1
    elif x=="H":h+=1
print(m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h)

Solution (Python):
n = int(input())
s = [input()[0] for _ in range(n)]

cnt = [s.count(v) for v in ("M", "A", "R", "C", "H")]
ans = 0
for i in range(5):
    for j in range(i):
        for k in range(j):
            ans += cnt[i] * cnt[j] * cnt[k]
            
print(ans)

Solution (Python):
N = int(input())
names = [0] * 5
pattern = []

def make_pattern(arr, cnt):
    if len(arr) == 5:
        if cnt == 3 :
            pattern.append(arr)
        return
    make_pattern(arr + '1', cnt + 1)
    make_pattern(arr + '0', cnt)

for _ in range(N):
    name = input()
    initial = name[0]
    if 'M' == initial:
        names[0] += 1
    elif 'A' == initial:
        names[1] += 1
    elif 'R' == initial:
        names[2] += 1
    elif 'C' == initial:
        names[3] += 1
    elif 'H' == initial:
        names[4] += 1
    else:
        continue

make_pattern('', 0)

ans = 0
for p in pattern:
    ret = 1
    for i in range(5):
        if p[i] == '1':
            ret *= names[i]
    ans += ret
print(ans)

Solution (Python):
N = int(input())

s = [0, 0, 0, 0, 0]    
for i in range(N):
    S = input()
    if S[0] == "M":
        s[0] += 1
    elif S[0] == "A":
        s[1] += 1
    elif S[0] == "R":
        s[2] += 1
    elif S[0] == "C":
        s[3] += 1
    elif S[0] == "H":
        s[4] += 1
        
ans = 0

for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            ans += s[i] * s[j] * s[k]

print(ans)

Solution (Python):
import itertools

n = int(input())
S = []
for _ in range(n):
    S.append(str(input()))

First = ['M', 'A', 'R', 'C', 'H']

M, A, R, C, H = [], [], [], [], []
for s in S:
    if s[0] == 'M':
        M.append(s)
    elif s[0] == 'A':
        A.append(s)
    elif s[0] == 'R':
        R.append(s)
    elif s[0] == 'C':
        C.append(s)
    elif s[0] == 'H':
        H.append(s)

ans = 0

for first_cmb in itertools.combinations(First, 3):
    temp = 1
    for i in first_cmb:
        if i == 'M':
            temp = temp*len(M)
        elif i == 'A':
            temp = temp*len(A)
        elif i == 'R':
            temp = temp*len(R)
        elif i == 'C':
            temp = temp*len(C)
        elif i == 'H':
            temp = temp*len(H)
        
    ans += temp


print(ans)

Solution (Python):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n = int(input())
d = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
for _ in range(n):
    s = input()[:-1]
    if not s[0] in d.keys():
        continue
    d[s[0]] += 1

ans = 0
l = list(d.values())
for i in range(5):
    for j in range(i+1, 5):
        for k in range(j+1, 5):
            ans += l[i]*l[j]*l[k]
print(ans)

Solution (Python):
N = int(input())
NameList = []
CharCnt = [0] * 5
CharList = ["M","A","R","C","H"]
for _ in range(N):
    S = input()
    for i in range(5):
        if S[0] == CharList[i]:
            CharCnt[i] += 1
ans = 0

for i in range(3):
    for j in range(i + 1, 4):
        for k in range(j + 1, 5):
            tmp_ans = CharCnt[i] * CharCnt[j] * CharCnt[k]
            if tmp_ans != 0:
                ans += tmp_ans
if sum(CharCnt) < 3:
    print("0")
else:
    print(ans)