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):
N = int(input())

cnt = [0 for _ in range(5)]
ch = "MARCH"

for _ in range(N):
    S = input()
    for i in range(5):
        if S[0] == ch[i]:
            cnt[i] += 1

ans = 0
ans += cnt[0]*cnt[1]*cnt[2]
ans += cnt[0]*cnt[1]*cnt[3]
ans += cnt[0]*cnt[1]*cnt[4]
ans += cnt[0]*cnt[2]*cnt[3]
ans += cnt[0]*cnt[2]*cnt[4]
ans += cnt[0]*cnt[3]*cnt[4]

ans += cnt[1]*cnt[2]*cnt[3]
ans += cnt[1]*cnt[2]*cnt[4]
ans += cnt[1]*cnt[3]*cnt[4]

ans += cnt[2]*cnt[3]*cnt[4]

print(ans)

Solution (Python):

count=0
import itertools
N=int(input())
S=[input() for i in range(N)]
a = ['M', 'A','R', 'C', 'H']
b=[0]*5
for s in S:
    try:    
        b[a.index(s[0])]+=1
    except ValueError:pass
l=list(itertools.combinations(b,3))
for c in l:
    tmp=1
    for i in range(3):
        tmp*=c[i]
    count+=tmp
print(count)

Solution (Python):
N=int(input())
name=[input()[0] for _ in range(N)]
m=name.count("M")
a=name.count("A")
r=name.count("R")
c=name.count("C")
h=name.count("H")
print(m*a*(r+c+h)+m*r*(c+h)+m*c*h+a*r*(c+h)+a*c*h+r*c*h)

Solution (Python):
from itertools import combinations

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

for _ in range(n):
    initial=input()[0]
    if initial in "MARCH":
        march["MARCH".index(initial)]+=1

count=0
for i, j, k in combinations(range(5),3):
    count+=march[i]*march[j]*march[k]
print(count)

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


def input(): return sys.stdin.readline().strip()


def solve(S):
    c = Counter(S)

    
    if len(c.keys()) < 3:
        return 0

    
    if sum(c.values()) < 3:
        return 0

    ans = 0
    for i, j, k in combinations('MARCH', 3):
        ans += c[i] * c[j] * c[k]

    return ans


def main():
    N = int(input())
    S = [input()[0] for _ in range(N)]
    print(solve(S))


if __name__ == "__main__":
    main()

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    s="MARCH"
    n=int(input())
    k=[0]*5
    for _ in range(n):
        t=input()[0]
        if t in s: k[s.index(t)]+=1
    from itertools import combinations
    A=combinations(range(5),3)
    ans=0
    for a,b,c in A:
        ans+=k[a]*k[b]*k[c]
    print(ans)
resolve()

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

march = [0] * 5
for c in s:
    if c in 'MARCH':
        march['MARCH'.index(c)] += 1

print(march[0] * march[1] * march[2]
    + march[0] * march[1] * march[3]
    + march[0] * march[1] * march[4]
    + march[0] * march[2] * march[3]
    + march[0] * march[2] * march[4]
    + march[0] * march[3] * march[4]
    + march[1] * march[2] * march[3]
    + march[1] * march[2] * march[4]
    + march[1] * march[3] * march[4]
    + march[2] * march[3] * march[4])

Solution (Python):
def factorial(n):
    res = 1
    for i in range(1, n + 1):
        res *= i
    return res


def combination(n, r):
    return factorial(n) // (factorial(r) * factorial(n - r))


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

march = [0] * 5
for c in s:
    if c in 'MARCH':
        march['MARCH'.index(c)] += 1

k = sum(x > 0 for x in march)
if k < 3:
    print(0)
    exit()


print(march[0] * march[1] * march[2]
    + march[0] * march[1] * march[3]
    + march[0] * march[1] * march[4]
    + march[0] * march[2] * march[3]
    + march[0] * march[2] * march[4]
    + march[0] * march[3] * march[4]
    + march[1] * march[2] * march[3]
    + march[1] * march[2] * march[4]
    + march[1] * march[3] * march[4]
    + march[2] * march[3] * march[4])

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

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

print(ans)

Solution (Python):
n = int(input())
m=a=r=c=h=0
for i in range(n):
  s = input()[0]
  if s == 'M':
    m += 1
  elif s == 'A': 
    a += 1
  elif s == 'R': 
    r += 1
  elif s == 'C': 
    c += 1
  elif s == 'H': 
    h += 1
  else:
    continue
march = [m,a,r,c,h]
march.sort()
if march[0] == march[1] == march[2] == 0:
  print(0)
elif march[0] == march[1] == 0:
  print(march[2]*march[3]*march[4])
elif march[0] == 0:
  print(march[1]*march[2]*march[3]
  +march[2]*march[3]*march[4]
  +march[3]*march[4]*march[1]
  +march[4]*march[1]*march[2])
else:
  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=[]
for i in range(n):
    t=str(input())
    if t[0] in 'MARCH':
        s.append(t[0])

if s==[]:
    print(0)
else:
    l=[]
    l.append(s.count('M'))
    l.append(s.count('A'))
    l.append(s.count('R'))
    l.append(s.count('C'))
    l.append(s.count('H'))
    ans=0
    
    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):
from collections import defaultdict
import itertools
import sys
input = sys.stdin.readline


def main():
    N = int(input())
    D = defaultdict(int)
    for _ in range(N):
        S = input()
        D[S[:1]] += 1
    
    ans = 0
    for initials in itertools.combinations(['M','A','R','C','H'], 3):
        a = 1
        for i in initials:
            a *= D[i]
        ans += a
    
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
import itertools

N = int(input())
name = Counter([input()[0] for _ in range(N)])

ans = 0

for i,j,k in itertools.combinations('MARCH',3):
  ans += name[i] * name[j] * name[k]
print(ans)

Solution (Python):
n = int(input())
marchSentence = ["M", "A", "R", "C", "H"]
marchCount = [0, 0, 0, 0, 0]
marchSum = 0
for i in range(n):
    s = input()
    if marchSentence.count(s[0]) > 0:
        num = marchSentence.index(s[0])
        if num > -1:
            marchCount[num] += 1

for a in range(0, 3):
    for b in range(a + 1, 4):
        for c in range(b + 1, 5):
            marchSum += marchCount[a] * marchCount[b] * marchCount[c]
print(marchSum)

Solution (Python):
n = int(input())
marchSentence = ["M", "A", "R", "C", "H"]
marchCount = [0, 0, 0, 0, 0]
marchSum = 0
for i in range(n):
    s = input()
    sa = s[0]
    if marchSentence.count(sa) > 0:
        num = marchSentence.index(s[0])
        if num > -1:
            marchCount[num] += 1

for a in range(0, 3):
    for b in range(a + 1, 4):
        for c in range(b + 1, 5):
            marchSum += marchCount[a] * marchCount[b] * marchCount[c]
print(marchSum)

Solution (Python):
import itertools
n = int(input())
s = []
march = [0] * 5
for i in range(n):
    s = input()
    if s[0] == 'M':
        march[0] += 1
    if s[0] == 'A':
        march[1] += 1
    if s[0] == 'R':
        march[2] += 1
    if s[0] == 'C':
        march[3] += 1
    if s[0] == 'H':
        march[4] += 1

comb = itertools.combinations(list(range(5)), 3)
ans = 0
for i in comb:
    ans += march[i[0]] * march[i[1]] * march[i[2]]
print(ans)

Solution (Python):

from itertools import combinations as comb


def main():
    N, *S = open(0).read().split()
    capitals = [s[0] for s in S]
    cnt = [capitals.count(i) for i in "MARCH"]
    ans = sum(x * y * z for x, y, z in comb(cnt, 3))
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

from itertools import combinations as comb


def main():
    N, *S = open(0).read().split()
    cnt = [sum(s.startswith(i) for s in S) for i in "MARCH"]
    ans = sum(x * y * z for x, y, z in comb(cnt, 3))
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
ss = {}
for i in range(n):
    s = input()
    if s[0] in ['M', 'A', 'R', 'C', 'H']:
        if s[0] in ss.keys():
            ss[s[0]] += 1
        else:
            ss[s[0]] = 1

sss = list(ss.values())
res = 0
if len(ss.keys()) <= 2:
    res = 0
elif len(ss.keys()) == 3:
    res = sss[0] * sss[1] * sss[2]
elif len(ss.keys()) == 4:
    res = sss[0] * sss[1] * sss[2] + sss[0] * sss[1] * sss[3] + sss[0] * sss[2] * sss[3] + sss[1] * sss[2] * sss[3]
elif len(ss.keys()) == 5:
    res = sss[0] * sss[1] * sss[2] + sss[0] * sss[1] * sss[3] + sss[0] * sss[1] * sss[4] + sss[0] * sss[2] * sss[3] \
          + sss[0] * sss[2] * sss[4] + sss[0] * sss[3] * sss[4] + sss[1] * sss[2] * sss[3] + sss[1] * sss[2] * sss[4] \
          + sss[1] * sss[3] * sss[4] + sss[2] * sss[3] * sss[4]
print(res)

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

N = int(input())
S = Counter()
for _ in range(N):
    S[input()[0]] += 1
print(sum([S[a]*S[b]*S[c] for a, b, c in combinations('MARCH', 3)]))

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

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

Solution (Python):
import itertools

n = int(input())


def add(dict, str):
    if not str[0] in dict:
        dict[str[0]] = []
    dict[str[0]].append(str)


march = {}
for _ in range(n):
    s_i = input()
    if 'M' == s_i[0] or 'A' == s_i[0] or 'R' == s_i[0] or 'C' == s_i[0] or 'H' == s_i[0]:
        add(march, s_i)

key_combination = list(itertools.combinations(list(march), 3))
count = 0
for case in key_combination:
    indiv_count = 1
    for key in case:
        if not key in march:
            indiv_count = 0
            break
        indiv_count *= len(march[key])
    count += indiv_count
print(count)

Solution (Python):
import itertools

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


def add(dict, str):
    if not str[0] in dict:
        dict[str[0]] = []
    dict[str[0]].append(str)


march = {}
for s_i in s:
    if 'M' == s_i[0] or 'A' == s_i[0] or 'R' == s_i[0] or 'C' == s_i[0] or 'H' == s_i[0]:
        add(march, s_i)

key_combination = list(itertools.combinations(list(march), 3))
count = 0
for case in key_combination:
    indiv_count = 1
    for key in case:
        if not key in march:
            indiv_count = 0
            break
        indiv_count *= len(march[key])
    count += indiv_count
print(count)

Solution (Python):
N = int(input())
M = 0
A = 0
R = 0
C = 0
H = 0

for _ in range(N):
  tmp = input()[0]
  if tmp == "M":
    M += 1
  elif tmp == "A":
    A += 1
  elif tmp == "R":
    R += 1
  elif tmp == "C":
    C += 1
  elif tmp == "H":
    H += 1

ans = 0
ans += M * A * C
ans += M * A * R
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):
import collections
import itertools

n = int(input())
ls = [input().rstrip() for _ in range(n)]
counter = collections.Counter()
for x in ls:
    x = x[0]
    if x in 'MARCH':
        counter[x] += 1

res = 0
for a, b, c in itertools.combinations('MARCH', 3):
    res += counter[a] * counter[b] * counter[c]
print(res)

Solution (Python):
from functools import reduce
from itertools import combinations
import copy

N = int(input())
S = {key: 0 for key in 'MARCH'}
for _ in range(N):
  s = input()
  if s[0] in S:
    S[s[0]] += 1

newS = copy.deepcopy(S)
keys = []
for key, value in S.items():
  if value == 0: del newS[key]
  else: keys.append(key)

if len(newS) < 3:
  print(0)
  exit()
  
ans = 0
for cmb in combinations(keys,3):
  ans += reduce(lambda x,y: x*y, [newS[idx] for idx in cmb])
print(ans)

Solution (Python):
N = int(input())
S = [list(input()) for _ in range(N)]

ans = 0
cntM = 0
cntA = 0
cntR = 0
cntC = 0
cntH = 0
for i in range(N):
    cntM += (1 if S[i][0] == 'M' else 0)
    cntA += (1 if S[i][0] == 'A' else 0)
    cntR += (1 if S[i][0] == 'R' else 0)
    cntC += (1 if S[i][0] == 'C' else 0)
    cntH += (1 if S[i][0] == 'H' else 0)
cntlst = [cntM, cntA, cntR, cntC, cntH]

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

Solution (Python):
import itertools
N = int(input().strip())
name = [input().strip() for _ in range(N)]

n_dict = {k:0 for k in 'MARCH'}
for n in name:
  if n[0] in 'MARCH':
    n_dict[n[0]] += 1

ans = 0
for a,b,c in itertools.combinations('MARCH', 3):
  ans += n_dict[a]*n_dict[b]*n_dict[c]
print(ans)

Solution (Python):
N = int(input())
ls = []
ls2 = []
for i in range(N):
    ls.append(input())
for i in range(N):
    ls2.append(ls[i][0])
M = ls2.count("M")
A = ls2.count("A")
R = ls2.count("R")
C = ls2.count("C")
H = ls2.count("H")
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())
ls = []
ls2 = []
M = 0
A = 0
R = 0
C = 0
H = 0
for i in range(N):
    ls.append(input())
for i in range(N):
    ls2.append(ls[i][0])
M = ls2.count("M")
A = ls2.count("A")
R = ls2.count("R")
C = ls2.count("C")
H = ls2.count("H")
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 collections import defaultdict
import itertools
d = defaultdict(list)
n = int(input())
for i in range(n):
  s = input()
  d[s[0]].append(s)
cnt = 0
for v in itertools.combinations(["M","A","R","C","H"], 3):
  cnt += len(d[v[0]])*len(d[v[1]])*len(d[v[2]])
print(cnt)

Solution (Python):
from itertools import combinations
n = int(input())
m = []
a = []
r = []
c = []
h = []
for i in range(n):
  t = input()
  if t[0] == 'M':
    m.append(t)
  elif t[0] == 'A':
    a.append(t)
  elif t[0] == 'R':
    r.append(t)
  elif t[0] == 'C':
    c.append(t)
  elif t[0] == 'H':
    h.append(t)

names = [m,a,r,c,h]
com = list(combinations(names,3))
cnt = 0
for i in range(len(com)):
  cnt += len(com[i][0]) * len(com[i][1]) * len(com[i][2])
print(cnt)

Solution (Python):
N = int(input())
from collections import defaultdict
import itertools

a = {}
a["M"] = 0
a["A"] = 0
a["R"] = 0
a["C"] = 0
a["H"] = 0

b = defaultdict(int)
b["M"] = 1
b["A"] = 1
b["R"] = 1
b["C"] = 1
b["H"] = 1
C = ["M","A","R","C","H"]

for i in range(N):
    s = input()
    if b[s[0]] == 1:
        a[s[0]] += 1
ans = 0        
for v in itertools.combinations(C, 3):
    ans += a[v[0]]*a[v[1]]*a[v[2]]
print(ans)

Solution (Python):
N = int(input())
march = ["M", "A", "R", "C", "H"]
S = [0,0,0,0,0]

for i in range(N):
  s = str(input())
  if s[0] in march:
    index = march.index(s[0])
    S[index] += 1
    
for i in range(5):
  if 0 in S:
    S.remove(0)
   
N = len(S)
if N <= 2:
  ans = 0
elif N == 3:
  ans = S[0]*S[1]*S[2]
elif N == 4:
  mul = S[0]*S[1]*S[2]*S[3]
  ans = 0
  for i in range(4):
    ans += mul//S[i]
else:
  mul = S[0]*S[1]*S[2]*S[3]*S[4]
  ans = 0
  for i in range(5):
    for j in range(i+1,5):
      ans += mul//(S[i]*S[j])
      
print(ans)

Solution (Python):
from collections import Counter

N = int(input())
S = [input()[0] for i in range(N)]
S = [i for i in S if i in {'M', 'A', 'R', 'C', 'H'}]
s = list(Counter(S).values())
ans = 0

if len(set(S)) < 3:
    print(0)
else:
    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 += s[i] * s[j] * s[k]
    print(ans)

Solution (Python):
import itertools
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

ans = 0
for i, j, k in itertools.combinations(d.keys(), 3):
    ans += d[i] * d[j] * d[k]

print(ans)

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

dict_s = {
  "M" : 0,"A" : 0,"R" : 0,
  "C" : 0,"H" : 0,
}
for i in range(n):
  if(s[i][0] == "M"):
    dict_s["M"]=dict_s["M"]+1
  if(s[i][0] == "A"):
    dict_s["A"]=dict_s["A"]+1
  if(s[i][0] == "R"):
    dict_s["R"]=dict_s["R"]+1
  if(s[i][0] == "C"):
    dict_s["C"]=dict_s["C"]+1
  if(s[i][0] == "H"):
    dict_s["H"]=dict_s["H"]+1

sum_s=dict_s["M"]*dict_s["A"]*dict_s["R"]+ \
      dict_s["M"]*dict_s["A"]*dict_s["C"]+ \
      dict_s["M"]*dict_s["A"]*dict_s["H"]+ \
      dict_s["M"]*dict_s["R"]*dict_s["C"]+ \
      dict_s["M"]*dict_s["R"]*dict_s["H"]+ \
      dict_s["M"]*dict_s["C"]*dict_s["H"]+ \
      dict_s["A"]*dict_s["R"]*dict_s["C"]+ \
      dict_s["A"]*dict_s["R"]*dict_s["H"]+ \
      dict_s["A"]*dict_s["C"]*dict_s["H"]+ \
      dict_s["R"]*dict_s["C"]*dict_s["H"]
print(sum_s)

Solution (Python):
import math


def combi(a, b):
    ans = math.factorial(a) / (math.factorial(a - b) * math.factorial(b))
    return ans


N = int(input())
S = [0] * 5

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

c = 0
N = 0
for i in range(5):
    N += S[i]
    if S[i] != 0:
        c += 1

if c <= 2:
    print(0)

else:
    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):
from itertools import combinations
n=int(input())
march=[0,0,0,0,0]
for _ in range(n):
  s=input()
  if s[0]=="M":
    march[0]+=1
  if s[0]=="A":
    march[1]+=1
  if s[0]=="R":
    march[2]+=1
  if s[0]=="C":
    march[3]+=1
  if s[0]=="H":
    march[4]+=1
ans=0
for a,b,c in combinations([0,1,2,3,4],3):
  ans+=march[a]*march[b]*march[c]
print(ans)

Solution (Python):
N = int(input())
S = [input() for _ in range(N)]

dict = {"M" : 0, "A" : 0, "R" : 0, "C" : 0, "H" : 0}
for s in S :
    if s[0] in "MARCH" :
        dict[s[0]] += 1

counter = list(dict.values())
ret = 0
for i in range(len(counter)) :
    for j in range(i + 1, len(counter)) :
        for k in range(j + 1, len(counter)) :
            ret += counter[i] * counter[j] * counter[k]
print(ret)

Solution (Python):
n=int(input())
s=list(input() for i in range(n))
mc=ac=rc=cc=hc=0
cnt=0
for i in range(n):
    if s[i][0] == "M":
        mc+=1
    elif s[i][0] == "A":
        ac+=1
    elif s[i][0] == "R":
        rc+=1
    elif s[i][0] == "C":
        cc+=1
    elif s[i][0] == "H":
        hc+=1
lis = [mc,ac,rc,cc,hc]
if sum(lis) == 0:
    print(0)
else:
    for i in range(5):
        for j in range(i+1,5):
            for k in range(j+1,5):
                cnt+=lis[i]*lis[j]*lis[k]
    print(cnt)

Solution (Python):
from itertools import combinations as c
n=int(input());l=[input() for _ in range(n)];m="MARCH";p=[0]*5;r=0
for s in l:
  for i in range(5):
    if s[0]==m[i]:p[i]+=1
for d in c(p,3):r+=d[0]*d[1]*d[2]
print(r)

Solution (Python):
N = int(input())
S = [0 for i in range(N)]
for i in range(N):
  S[i] = input()
 
dic = {"M":0, "A":0, "R":0, "C":0, "H":0}
for i in range(N):
  if S[i][0] in dic:
    dic[S[i][0]] += 1
    
ans = dic["M"]*dic["A"]*dic["R"]+dic["M"]*dic["A"]*dic["C"]+dic["M"]*dic["A"]*dic["H"]+dic["M"]*dic["R"]*dic["C"]+dic["M"]*dic["R"]*dic["H"]+dic["M"]*dic["C"]*dic["H"]+dic["A"]*dic["R"]*dic["C"]+dic["A"]*dic["R"]*dic["H"]+dic["A"]*dic["C"]*dic["H"]+dic["R"]*dic["C"]*dic["H"]
print(ans)

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

c = []
c.append(s.count("M"))
c.append(s.count("A"))
c.append(s.count("R"))
c.append(s.count("C"))
c.append(s.count("H"))
c_len = len(c)
ans = 0
for i in range(c_len):
    for j in range(i+1, c_len):
        for k in range(j+1, c_len):
            ans += c[i] * c[j] * c[k]

print(ans)

Solution (Python):
Nm = 0
Na = 0
Nr = 0
Nc = 0
Nh = 0
S = []
N = int(input())
for i in range(N):
  S.append(input())
for i in range(N):
  if S[i][0] == "M":
    Nm += 1
  if S[i][0] == "A":
    Na += 1
  if S[i][0] == "R":
    Nr += 1
  if S[i][0] == "C":
    Nc += 1
  if S[i][0] == "H":
    Nh += 1
s = 0
s += Nm*Na*Nr
s += Nm*Na*Nc
s += Nm*Na*Nh
s += Nm*Nr*Nc
s += Nm*Nr*Nh
s += Nm*Nc*Nh
s += Na*Nr*Nc
s += Na*Nr*Nh
s += Na*Nc*Nh
s += Nr*Nc*Nh
print(s)

Solution (Python):
n=int(input())
name=[list(input()) for _ in range(n)]
march=[0]*5
for s in name:
  if s[0]=='M':
    march[0]=march[0]+1
  if s[0]=='A':
    march[1]=march[1]+1
  if s[0]=='R':
    march[2]=march[2]+1
  if s[0]=='C':
    march[3]=march[3]+1
  if s[0]=='H':
    march[4]=march[4]+1
march.sort()
a=0
if march[2]==0:
  print(0)
else:
  a=a+march[0]*march[1]*march[2]
  a=a+march[0]*march[1]*march[3]
  a=a+march[0]*march[1]*march[4]
  a=a+march[0]*march[2]*march[3]
  a=a+march[0]*march[2]*march[4]
  a=a+march[0]*march[3]*march[4]
  a=a+march[1]*march[2]*march[3]
  a=a+march[1]*march[2]*march[4]
  a=a+march[1]*march[3]*march[4]
  a=a+march[2]*march[3]*march[4]
  print(a)

Solution (Python):

N = int(input())
S = [input() for _ in range(N)]

mydict = {'M':1,'A':2,'R':3,'C':4,'H':5}
count = [0] * 6
for i in range(N):
    s = S[i][0]
    if s in mydict:
        count[mydict[s]] += 1
ans = 0
for i in range(1,6):
    for j in range(i+1,6):
        if i==j:continue
        for k in range(j+1,6):
            if i==k or j == k:continue
            ans += count[i] * count[j] * count[k]
            
            
print(ans)

Solution (Python):
import itertools
from functools import reduce

N = int(input())
S = [input() for _ in range(N)]
T = [0] * 5
for s in S:
    if s[0] == 'M':
        T[0] += 1
    elif s[0] == 'A':
        T[1] += 1
    elif s[0] == 'R':
        T[2] += 1
    elif s[0] == 'C':
        T[3] += 1
    elif s[0] == 'H':
        T[4] += 1
ans = 0
for t in itertools.combinations(T, 3):
    ans += reduce(lambda a,b:a*b, t)
print(ans)

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

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

lst=[m,a,r,c,h]
ans=0
for i in range(5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            ans+=lst[i]*lst[j]*lst[k]

print(ans)

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

dic={}
for i in s:
    if i[0]=='M' or i[0]=='A' or i[0]=='R' or i[0]=='C' or i[0]=='H':
        if i[0] in dic:
            dic[i[0]]+=1
        else:
            dic[i[0]]=1
if len(dic)<3:
    ans=0
else:
    if len(dic)==3:
        ans = 1
        for i in dic.values():
            ans *=i
    elif len(dic)==4:
        li4 = []
        for i in dic.values():
            li4.append(i)
        ans = li4[0]*li4[1]*li4[2]+li4[0]*li4[1]*li4[3]+li4[0]*li4[2]*li4[3]+li4[1]*li4[2]*li4[3]
    else:
        li5 = []
        for i in dic.values():
            li5.append(i)
        ans =li5[0]*li5[1]*li5[2]+li5[0]*li5[1]*li5[3]+li5[0]*li5[1]*li5[4]+li5[0]*li5[2]*li5[3]+li5[0]*li5[2]*li5[4]+li5[0]*li5[3]*li5[4]+li5[1]*li5[2]*li5[3]+li5[1]*li5[2]*li5[4]+li5[1]*li5[3]*li5[4]+li5[2]*li5[3]*li5[4]
print(ans)

Solution (Python):
n=int(input())
L=[input()[0] for _ in range(n)]
L=[L.count(s) for s in 'MARCH']
a=0
for i in range(3):
  for j in range(i+1,4):
    for k in range(j+1,5):
      a+=L[i]*L[j]*L[k]
print(a)

Solution (Python):
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def solve():
  n = int(input())
  s = [input() for _ in range(n)]
  march = [0]*5
  for i in range(n):
    if s[i][0] == "M":
      march[0] += 1
    elif s[i][0] == "A":
      march[1] += 1
    elif s[i][0] == "R":
      march[2] += 1
    elif s[i][0] == "C":
      march[3] += 1
    elif s[i][0] == "H":
      march[4] += 1
  ans = 0
  for i in range(3):
    for j in range(3):
      for k in range(3):
        if i < j+1 and j<k+1:
          ans += march[i]*march[j+1]*march[k+2]
  print(ans)
solve()

Solution (Python):
n = int(input())
s = [input() for _ in range(n)]
s = [t[0] for t in s if t[0] in 'MARCH']
d = {}
for t in s:
  if t in d:
    d[t] += 1
  else:
    d[t] = 1
l = list(d.keys())
result = 0
for i in range(len(l) - 2):
  for j in range(i + 1, len(l) - 1):
    for k in range(j + 1, len(l)):
      result += d[l[i]] * d[l[j]] * d[l[k]]
print(result)

Solution (Python):
import sys
import math
from fractions import gcd





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

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""


 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())


 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""



N = int(sys.stdin.readline())

target = {"M":0,"A":0,"R":0,"C":0,"H":0}
cnt = 0
for i in range(N):
    s = list(sys.stdin.readline().rstrip())
    if s[0] in target.keys():
        target[s[0]] += 1

k = list(target.keys())
ans = 0
for i in range(3):
    for j in range(i + 1, 5):
        for h in range(j + 1, 5):
            ans += target[k[i]] * target[k[j]] * target[k[h]]

print(ans)

Solution (Python):
N = int(input())
count = [0] * 5
c = "MARCH"

for i in range(N):
    s = input()
    for j in range(5):
        if s[0] == c[j]:
            count[j] += 1
            break

ind = []
for i in range(5):
    if count[i] > 0:
        ind.append(count[i])

if len(ind) < 3:
    print(0)
else:
    ans = 0
    for i in range(len(ind)):
        for j in range(i+1, len(ind)):
            for k in range(j+1, len(ind)):
                ans += ind[i] * ind[j] * ind[k]
    print(ans)

Solution (Python):

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


import itertools

N = int(input())
S = [ input().rstrip() for _ in range(N)]


C = [0] * 5
for s in S:
    i = -1
    if s[0] == 'M': i = 0
    if s[0] == 'A': i = 1
    if s[0] == 'R': i = 2
    if s[0] == 'C': i = 3
    if s[0] == 'H': i = 4

    if i > -1:
        C[i] += 1

count = 0
for x in itertools.combinations("01234", 3):
    (a, b, c) = map(int, x)
    count += C[a]*C[b]*C[c]


print(count)

Solution (Python):
import itertools

n = int(input())

d = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}

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

l = list(d.keys())
comb = list(itertools.combinations(l, 3))

ans = 0
for i in comb:
    temp = 1
    for j in i:
        temp *= d[j]

    ans += temp

print(ans)

Solution (Python):
n=int(input())
s=[input() for i in range(n)]
cnt1,cnt2,cnt3,cnt4,cnt5=0,0,0,0,0
for i in s:
    if i[0]=='M':
        cnt1+=1
    elif i[0]=='A':
        cnt2+=1
    elif i[0]=='R':
        cnt3+=1
    elif i[0]=='C':
        cnt4+=1
    elif i[0]=='H':
        cnt5+=1
print(cnt1*cnt2*cnt3+cnt1*cnt2*cnt4+cnt1*cnt2*cnt5+cnt1*cnt3*cnt4+cnt1*cnt3*cnt5+cnt1*cnt4*cnt5+cnt2*cnt3*cnt4+cnt2*cnt3*cnt5+cnt2*cnt4*cnt5+cnt3*cnt4*cnt5)

Solution (Python):
import fractions
import itertools
N = int(input())
M =[]
A = []
R = []
C = []
H = []


for i in range(N):
    name = input()
    initial = name[0]
    if initial == "M":
        M.append(name)
    elif initial == "A":
        A.append(name)
    elif initial == "R":
        R.append(name)
    elif initial == "C":
        C.append(name)
    elif initial == "H":
        H.append(name)

count = 0
S = []
if len(M) > 0:
    S.append(len(M))
if len(A) > 0:
    S.append(len(A))
if len(R) > 0:
    S.append(len(R))
if len(C) > 0:
    S.append(len(C))
if len(H) > 0:
    S.append(len(H))

if len(S) < 3:
    print("0")
    exit(0)

a = itertools.combinations(S,3)
ans = 0
for x in list(a):
    tmp = 1
    for y in x:
        tmp *= y
    ans += tmp
print(ans)

Solution (Python):
a=int(input())
lis=[input()[0] for i in range(a)]
lis2=[0,0,0,0,0]
dellist=[]
for m in lis:
  if m=="M":
    lis2[0]+=1
  elif m=="A":
    lis2[1]+=1
  elif m=="R":
    lis2[2]+=1
  elif m=="C":
    lis2[3]+=1
  elif m=="H":
    lis2[4]+=1
a=sum(lis2)
def c3(a):
  return a*(a-1)*(a-2)/6
def c2(a):
  return  a*(a-1)/2
ans=c3(a)
for i in lis2:
  ans=ans-c3(i)-c2(i)*(a-i)
print(int(ans))

Solution (Python):
from itertools import*;N,*S=open(0);print(sum(a*b*c for a,b,c in combinations([sum(1for s in S if s[0]==c)for c in"MARCH"],3)))

Solution (Python):
N = int(input())
S = [input() for _ in range(N)]

M = len([S[i] for i in range(N) if S[i][0] == "M"])
A = len([S[i] for i in range(N) if S[i][0] == "A"])
R = len([S[i] for i in range(N) if S[i][0] == "R"])
C = len([S[i] for i in range(N) if S[i][0] == "C"])
H = len([S[i] for i in range(N) if S[i][0] == "H"])

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):
def slove():
    import sys, collections, itertools
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    name = [str(input().rstrip('\n'))[0] for _ in range(n)]
    name = collections.Counter(name)
    name = dict(name.items())
    ls = list("MARCH")
    t = 0
    for i in itertools.combinations(ls, 3):
        if i[0] in name and i[1] in name and i[2] in name:
            t += (name[i[0]] * name[i[1]] * name[i[2]])
    print(t)


if __name__ == '__main__':
    slove()

Solution (Python):
import itertools
n = int(input())
s = ['' for _ in range(n)]
for i in range(n):
    s[i] = input()[0]
cnt = [s.count('M'), s.count('A'), s.count('R'), s.count('C'), s.count('H')]
ans = 0
for x in itertools.combinations(cnt, 3):
    ans += x[0] * x[1] * x[2]
print(ans)

Solution (Python):

import sys
import math
from collections import defaultdict


sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]


mod = 10**9 + 7


def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))



from itertools import combinations

N = I()
S = ['0']*N
x = [0]*5
for i in range(N):
    S[i] = str(input())
    if S[i].startswith('M'):
        x[0] += 1
    elif S[i].startswith('A'):
        x[1] += 1
    elif S[i].startswith('R'):
        x[2] += 1
    elif S[i].startswith('C'):
        x[3] += 1
    elif S[i].startswith('H'):
        x[4] += 1

ans = 0
A = list(combinations(range(5),3))
for a in A:
    ans += x[a[0]]*x[a[1]]*x[a[2]]

print(ans)