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())
count = {c: 0 for c in ['M', 'A', 'R', 'C', 'H']}

for _ in range(N):
    S = input()
    if S[0] in ['M', 'A', 'R', 'C', 'H']:
        count[S[0]] += 1

num = [count[c] for c in count]
ans = 0
for v in itertools.combinations(num, 3):
    ans += (v[0] * v[1] * v[2])
print(ans)

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



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

total = 0
total += march["M"]*march["R"]*march["A"]
total += march["M"]*march["A"]*march["C"]
total += march["M"]*march["A"]*march["H"]
total += march["M"]*march["R"]*march["C"]
total += march["M"]*march["R"]*march["H"]
total += march["A"]*march["R"]*march["C"]
total += march["A"]*march["C"]*march["H"]
total += march["R"]*march["C"]*march["H"]
total += march["C"]*march["H"]*march["M"]
total += march["A"]*march["R"]*march["H"]

print(total)

Solution (Python):
from collections import deque,Counter
from itertools import permutations,combinations,combinations_with_replacement

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

cnt = Counter(rows)

ans = 0
for k in combinations(["M","A","R","C","H"],3):
    ans += cnt[k[0]]*cnt[k[1]]*cnt[k[2]]

print(ans)

Solution (Python):
from collections import deque,Counter
from itertools import permutations,combinations,combinations_with_replacement

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

cnt = Counter(rows)

ans = 0
for k in combinations(["M","A","R","C","H"],3):
    ans += cnt[k[0]]*cnt[k[1]]*cnt[k[2]]

print(ans)

Solution (Python):
from sys import stdin
import itertools
def main():
    
    readline=stdin.readline
    N=int(readline())
    MARCH=[0,0,0,0,0]
    M=0
    A=1
    R=2
    C=3
    H=4
    for _ in range(N):
        S=readline().strip()
        if S[0]=="M":
            MARCH[M]+=1
        elif S[0]=="A":
            MARCH[A]+=1
        elif S[0]=="R":
            MARCH[R]+=1
        elif S[0]=="C":
            MARCH[C]+=1
        elif S[0]=="H":
            MARCH[H]+=1

    seq=[M,A,R,C,H]
    coms=itertools.combinations(seq,3)
    res=0
    for li in coms:
        X=li[0]
        Y=li[1]
        Z=li[2]
        res+=MARCH[X]*MARCH[Y]*MARCH[Z]

    print(res)
    
if __name__=="__main__":
    main()

Solution (Python):
from itertools import combinations
n = int(input())
s = []
for _ in range(n):
    s.append(input())

march = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
for i in s:
    if i[0] in march:
        march[i[0]] += 1

ans = 0
for i, j, k in combinations(march.values(), 3):
    ans += i*j*k
print(ans)

Solution (Python):
N=int(input())
s=[]
for i in range(N):
  S=input()
  s.append(S)
m=0
a=0
r=0
c=0
h=0
for i in range(N):
  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
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):
import itertools
def main():
    N = int(input())
    initial = {"M" : 0, "A" : 0, "R" : 0, "C" : 0, "H" : 0}

    for i in range(N):
        S = input()
        if S[0] == "M" or S[0] == "A" or S[0] == "R" or S[0] == "C" or S[0] == "H":
            initial[S[0]] += 1
    pat = 0

    for c in itertools.combinations("MARCH", 3):
        pat += initial[c[0]]*initial[c[1]]*initial[c[2]]
        
    print(pat)
if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
dict1 = {}
li = ['M', 'A', 'R', 'C', 'H']
ans = 0

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

for i in range(5):
    for j in range(i+1, 5):
        for k in range(j+1, 5):
            if li[i] in dict1 and li[j] in dict1 and li[k] in dict1:
                ans += dict1[li[i]] * dict1[li[j]] * dict1[li[k]]

print(ans)

Solution (Python):
from itertools import permutations, combinations,combinations_with_replacement,product

n = int(input())
p = [0 for i in range(5)]

for i in range(n):
    kar = input()
    if kar[0] == "M":
        p[0] += 1
    elif kar[0] == "A":
        p[1] += 1
    elif kar[0] == "R":
        p[2] += 1
    elif kar[0] == "C":
        p[3] += 1
    elif kar[0] == "H":
        p[4] += 1

a=[0,1,2,3,4]

tyu = list(combinations(a,3))
ans = 0
for x , y , z in tyu:
    ans += p[x]*p[y]*p[z]
print(ans)

Solution (Python):
n=int(input())
l=[0]*5
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
k0=l[0]*(l[1]*(l[2]+l[3]+l[4])+l[2]*(l[3]+l[4])+l[3]*l[4])
k1=l[1]*(l[2]*(l[3]+l[4])+l[3]*l[4])
k2=l[2]*l[3]*l[4]
print(k0+k1+k2)

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

Solution (Python):
n=int(input())
march=[0,0,0,0,0]
for i in range(n):
  s=input()
  if s[0]=="M":
    march[0]+=1
  elif s[0]=="A":
    march[1]+=1
  elif s[0]=="R":
    march[2]+=1
  elif s[0]=="C":
    march[3]+=1
  elif s[0]=="H":
    march[4]+=1
finalans=0
for i in range(2**5):
  ans=1
  count=0
  for j in range(5):
    if ((i>>j)&1):
      ans*=march[j]
      count+=1
  if count!=3:
    ans=0
  finalans+=ans
print(finalans)

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

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

s = Counter(S)

sd = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}

for i in 'MARCH':
    sd[i] += s[i]
    
ans = 0

for ss in combinations(['M','A','R','C','H'], 3):
    ans += sd[ss[0]]*sd[ss[1]]*sd[ss[2]]
    
print(ans)

Solution (Python):
n = int(input())
m = "MARCH"
l = {}
cnt = 0
for _ in range(n):
    init = input()[0]
    if init not in m:
        continue
    if init not in l:
        cnt += 1
        l[init] = 0
    l[init] += 1
if cnt <= 2:
    print(0)
    exit()
l = list(l.values())
n = len(l)
ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            ans += l[i] * l[j] * l[k]
print(ans)

Solution (Python):
n = int(input())
import collections
import itertools
wo = ["M","A","R","C","H"]
co = collections.Counter()
for i in range(n):
    s = input()
    if s[0] in wo:
        co[s[0]] +=1
ans = 0
for c in itertools.combinations(wo,3):
    tmp =1
    for w in c:
        tmp*=co[w]
    ans+=tmp
print(ans)

Solution (Python):


n=int(input())
s=[]
for i in range(n):
    s.append(input())
t=[0]*5


for i in range(n):
    c=list(s[i])
    if c[0]=='M':
        t[0]+=1
    if c[0]=='A':
        t[1]+=1
    if c[0]=='R':
        t[2]+=1
    if c[0]=='C':
        t[3]+=1
    if c[0]=='H':
        t[4]+=1
    
ans=0
cnt=1

for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
                cnt=t[k]*t[j]*t[i]
                ans+=cnt
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 s in S:
  if 'M' == s[0]:
    m+=1
  elif 'A' == s[0]:
    a+=1
  elif 'R' == s[0]:
    r+=1
  elif 'C' == s[0]:
    c+=1
  elif 'H' == s[0]:
    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):
def bit_make(n,m):
    s = [list(map(int,bin(x)[2:].zfill(n))) for x in range(2**n)]
    s2 = []
    for i in range(2**n):
        if sum(s[i])==m:
            s2.append(s[i])
    return s2

n = int(input())
march = [0]*5
c = [0]*5
ans = 0
for i in range(n):
    s = input()
    if s[0] == 'M':
        march[0]+=1
        c[0]=1
    if s[0] == 'A':
        march[1]+=1
        c[1]=1
    if s[0] == 'R':
        march[2]+=1
        c[2]=1
    if s[0] == 'C':
        march[3]+=1
        c[3]=1
    if s[0] == 'H':
        march[4]+=1
        c[4]=1
m = sum(c)
march.sort(reverse = True)
x = bit_make(m,3)
ans1 = 1
for i in range(len(x)):
    for j in range(m):
        if x[i][j]==1:
            ans1*=march[j]*x[i][j]
    ans+=ans1
    ans1=1

print(ans)

Solution (Python):
from collections import Counter
import itertools
N = int(input())
S = [input()[0] for _ in range(N)]

counter = Counter(S)
answer = 0
for x,y,z in itertools.combinations('MARCH',3):
  answer += counter[x] * counter[y] * counter[z]

print(answer)

Solution (Python):
N = int(input())
dic = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
p = ["M", "M", "M", "M", "M", "M", "A", "A", "A", "R"]
q = ["A", "R", "C", "A", "R", "A", "R", "R", "C", "C"]
r = ["R", "C", "H", "C", "H", "H", "C", "H", "H", "H"]


for _ in range(N):
    s = input()
    if s[0] in "MARCH":
        dic[s[0]] += 1

res = 0
for i in range(10):
    res += dic[p[i]] * dic[q[i]] * dic[r[i]]

print(res)

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

ans = 0

M = len(dic['M'])
A = len(dic['A'])
R = len(dic['R'])
C = len(dic['C'])
H = len(dic['H'])

memo =[[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]]
for i in memo:
    ans += (i[0]*i[1]*i[2])
    
    
print(ans)

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

counts = [0] * 5
for i in range(n):
    name = input()
    
    if name[0] == 'M':
        counts[0] += 1
    elif name[0] == 'A':
        counts[1] += 1
    elif name[0] == 'R':
        counts[2] += 1
    elif name[0] == 'C':
        counts[3] += 1
    elif name[0] == 'H':
        counts[4] += 1
 
ans = 0       
for i in range(5):
    for j in range(5):
        for k in range(5):
            if i == j or j == k or k == i:
                continue
            
            
            ans += counts[i] * counts[j] * counts[k]

print(ans // 6)

Solution (Python):
N = int(input())
listA = []
listB = []
d = ["M","A","R","C","H"]
ans = 0
for i in range(N):
    listA.append(input()[0])
for i in d:
    listB.append(listA.count(i))
listB = list(map(int,listB))
listB = [i for i in listB if i != 0]
length = len(listB)
if length < 3:
    print(0)
    exit()
total = 0
for i in range(length-2):
    for j in range(i+1,length):
        for k in range(j+1,length):
            total += listB[i] * listB[j] * listB[k]
            pass
print(total)

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

Solution (Python):
n=int(input())
m=0
a=0
r=0
c=0
h=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

d=[0]*5
d[0]=m
d[1]=a
d[2]=r
d[3]=c
d[4]=h

import itertools
dsum=0
for i in itertools.combinations(range(5), 3):
    dsum=dsum+d[i[0]]*d[i[1]]*d[i[2]]
print(dsum)

Solution (Python):
from itertools import combinations

n = int(input())
set_m = set()
set_a = set()
set_r = set()
set_c = set()
set_h = set()
for i in range(n):
    s = input()
    start = s[0]
    if start == 'M':
        set_m.add(s)
    elif start == 'A':
        set_a.add(s)
    elif start == 'R':
        set_r.add(s)
    elif start == 'C':
        set_c.add(s)
    elif start == 'H':
        set_h.add(s)
sets = [set_m, set_a, set_r, set_c, set_h]
numbers = []
for se in sets:
    if len(se) > 0:
        numbers.append(len(se))
num_group = len(numbers)
if num_group < 3:
    ans = 0
else:
    ans = 0
    ind_ls = list(range(num_group))
    c = combinations(ind_ls, 3)
    for ind1, ind2, ind3 in c:
        ans += numbers[ind1] * numbers[ind2]* numbers[ind3]
print(ans)

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

d = {}
for s in S:
    c = s[0]
    if c not in 'MARCH': continue
    if c in d:
        d[c]+=1
    else:
        d[c] = 1

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

d_list = list(d.values());
n = len(d_list)
ans = 0
for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            ans += d_list[i] * d_list[j] * d_list[k]

print(ans)

Solution (Python):
n=int(input())
p=[]
for i in range(n):
  s=input()
  p.append(s[0])
m=p.count("M")
a=p.count("A")
r=p.count("R")
c=p.count("C")
h=p.count("H")
print(m*a*r+m*a*h+m*a*c+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h)

Solution (Python):
import sys

args = []

for l in sys.stdin:
  args.append(l.strip('\n'))
  
names = args[1:]

focus_initial = 'MARCH'
initial_num = [0, 0, 0, 0, 0]
for name in names:
  for i in range(5):
    if focus_initial[i] == name[0]:
      initial_num[i] += 1
      
ct = 0
for i in range(5):
  for j in range(i+1, 5):
    for k in range(j+1, 5):
      ct += initial_num[i] * initial_num[j] * initial_num[k]

print(ct)

Solution (Python):
import collections
import itertools
n = int(input())
li = []
for i in range(n):
    li.append(input()[0])

c = collections.Counter(li)
c_li = [c['M'],c['A'],c['R'],c['C'],c['H']]


count = 0
combination = list(itertools.combinations([0,1, 2, 3,4], 3))
for co in combination:
    tmp = 1
    for c in co:
        if c_li[c] == 0:
            tmp = 0
            break
        tmp *= c_li[c]
    count += tmp
print(count)

Solution (Python):
from itertools import combinations

N = int(input())
march = list('MARCH')
name = {x: 0 for x in march}
for _ in range(N):
    s = input()
    if s[0] in march:
        name[s[0]] += 1
ans = 0
for a, b, c in combinations(name.values(), 3):
    ans += a*b*c
print(ans)

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

n = int(input())
d = defaultdict(int)

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

ls = [dd for dd in d]

if len(ls) < 3:
    print(0)
    exit()

ans = 0
for v in combinations(ls, 3):
    cnt = 1
    for vv in v:
        cnt *= d[vv]
    ans += cnt

print(ans)

Solution (Python):
import sys
readline = sys.stdin.readline

def main():
    N = int(input())
    cnt = [0, 0, 0, 0, 0]
    for _ in range(N):
        s = input()
        if s[0] == 'M':
            cnt[0] += 1
        elif s[0] == 'A':
            cnt[1] += 1
        elif s[0] == 'R':
            cnt[2] += 1
        elif s[0] == 'C':
            cnt[3] += 1
        elif s[0] == 'H':
            cnt[4] += 1
    
    ans = 0
    for i in range(5):
        for j in range(i+1, 5):
            for k in range(j+1, 5):
                ans += cnt[i] * cnt[j] * cnt[k]
    
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import collections
import itertools
n = int(input())
s = []
for i in range(n):
    a = list(input())
    s.append(a[0])

c = collections.Counter(s)
select_s = ['M', 'A', 'R', 'C', 'H']
ans = 0
for select in itertools.combinations(select_s, 3):
    ans += c[select[0]] * c[select[1]] * c[select[2]]
print(ans)

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

from itertools import combinations
key = list(dic.keys())

klist = list(combinations(key,3))


ans = 0
for i in range(len(klist)):
    ans += dic[klist[i][0]]*dic[klist[i][1]]*dic[klist[i][2]]

print(ans)

Solution (Python):
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(i+1,4):
    for k in range(j+1,5):
      ans+=MARCH[i]*MARCH[j]*MARCH[k]
print(ans)

Solution (Python):


import io
import sys
from itertools import combinations as comb

n, *S = open(0).read().split()

s = [i[0] for i in S]

array = [s.count(i) for i in 'MARCH']

ret = sum(x * y * z for x, y, z in comb(array, 3))

print(ret)

Solution (Python):
N = int(input())
pref = 'MARCH'
D = {}
for _ in range(N):
    s = input()
    if s[0] in pref:
        if s[0] in D:
            D[s[0]] += 1
        else:
            D[s[0]] = 1

lst = list(D.keys())
if len(lst) < 3:
    print(0)
    exit()
ans = 0
for i in range(len(lst)-2):
    for j in range(i+1, len(lst)-1):
        for k in range(j+1, len(lst)):
            ans += D[lst[i]] * D[lst[j]] * D[lst[k]]

print(ans)

Solution (Python):
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(i+1,4):
    for k in range(j+1,5):
      ans+=MARCH[i]*MARCH[j]*MARCH[k]
print(ans)

Solution (Python):
import itertools

n=int(input())
li=[]

for i in range(n):
    li.append(input()[0])

tm=list(itertools.combinations(["M","A","R","C","H"],3))
ans=0

for j1,j2,j3 in tm:
    ans+=li.count(j1)*li.count(j2)*li.count(j3)

print(ans)

Solution (Python):
import itertools
*s, = open(0)
print(sum(i*j*k for i,j,k in itertools.combinations([sum(t.startswith(l) for t in s) for l in "MARCH"], 3)))

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

c = itertools.combinations('MARCH', 3)

ans = 0

for i, j, k in c:
    ans += d[i]*d[j]*d[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
total = m + a + r + c + h
res = 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(res)

Solution (Python):
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 = ['M', 'A', 'R', 'C', 'H']
ans = 0
for i in range(3):
    for j in range(i+1, 4):
        for k in range(j+1, 5):
            ans += d[L[i]] * d[L[j]] * d[L[k]]
print(ans)

Solution (Python):
import sys

IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))

INIT_VAL = 0
DP2 = lambda d1, d2: [[INIT_VAL]*d2 for _ in range(d1)]
DP3 = lambda d1, d2, d3: [[[INIT_VAL]*d3 for _ in range(d2)] for _ in range(d1)]

from itertools import combinations

def main():
    n = II()
    initials = ['M', 'A', 'R', 'C', 'H']
    names = {name: [] for name in initials}
    for i in range(n):
        s = IS()
        if not s[0] in initials: continue
        names[s[0]].append(s)
    cnt = 0
    for a,b,c in combinations(initials, 3):
        cnt += len(names[a])*len(names[b])*len(names[c])
    print(cnt)

if __name__ == '__main__':
    main()

Solution (Python):
import itertools
N = int(input())
S = [input() for _ in range(N)]
march = ['M', 'A', 'R', 'C', 'H']
cnt = [0]*5
for s in S:
    if s[0] == 'M':
        cnt[0] += 1
    elif s[0] == 'A':
        cnt[1] += 1
    elif s[0] == 'R':
        cnt[2] += 1
    elif s[0] == 'C':
        cnt[3] += 1
    elif s[0] == 'H':
        cnt[4] += 1
ans = 0
for comb in itertools.combinations(cnt, 3):
    ans += comb[0]*comb[1]*comb[2]
print(ans)

Solution (Python):













mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    
    
    
    
    
    

    
    
    
    
    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)

if __name__ == '__main__':
  main()

Solution (Python):
n = int(input())
s = []
for i in range(n):
    s.append(input())
s = sorted(s)
m = 0
a = 0
r = 0
c = 0
h = 0
for i in range(n):
    x = s[i]
    if x[0]=='M': m+=1
    elif x[0]=='A': a+=1
    elif x[0]=='R': r+=1
    elif x[0]=='C': c+=1
    elif x[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):
def main():
    from collections import defaultdict
    from itertools import combinations

    N = int(input())

    d = defaultdict(int)
    for i in range(N):
        s = input()
        d[s[0]] += 1

    ans = 0
    for comb in combinations('MARCH', r=3):
        t = 1
        for char in comb:
            t *= d[char]
        ans += t
    print(ans)


if __name__ == '__main__':
    main()

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

name_dic={}
for i in range(N):
  S=input()
  if S[0]!="M" and S[0]!="A" and S[0]!="R" and S[0]!="C" and S[0]!="H":
    continue
  
  if S[0] in name_dic:
    name_dic[S[0]]+=1
  else:
    name_dic[S[0]]=1


name_list=list(name_dic.values())

answer=0
for i in range(len(name_list)):
  for j in range(i+1,len(name_list)):
    for k in range(j+1,len(name_list)):
      answer+=name_list[i]*name_list[j]*name_list[k]

print(answer)

Solution (Python):
N = int(input())
S = [0] * 5
for _ 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
 
import itertools
ans = 0
for v in itertools.combinations(S, 3):
  ans +=  v[0] * v[1] * v[2]
print(ans)

Solution (Python):
n=int(input())
s=[]
l=['M','A','R','C','H']
d={'M':0,'A':0,'R':0,'C':0,'H':0}
for _ in range(n):
  s_=input()
  if s_[0] in l:
    d[s_[0]]+=1
ans=0
for i in range(3):
  for j in range(i+1,4):
    for k in range(j+1,5):
      ans+=d[l[i]]*d[l[j]]*d[l[k]]
print(ans)

Solution (Python):
N=int(input())
m=0
a=0
r=0
c=0
h=0
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
ans=0
L=[m,a,r,c,h]
for i in range(3):
  for j in range(i+1,4):
    for k in range(j+1,5):
      ans+=L[i]*L[j]*L[k]
print(ans)

Solution (Python):
N = int(input())
S = [list(input()) for _ in range(N)]
san = [0]*5
san[0] = sum([S[i1][0]=="M" for i1 in range(N)])
san[1] = sum([S[i2][0]=="A" for i2 in range(N)])
san[2] = sum([S[i3][0]=="R" for i3 in range(N)])
san[3] = sum([S[i4][0]=="C" for i4 in range(N)])
san[4] = sum([S[i5][0]=="H" for i5 in range(N)])

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

Solution (Python):
n=int(input())
a=[0,0,0,0,0]
for i in range(n):
    b=input()[0]
    if b=='M':
        a[0]+=1
    if b=='A':
        a[1]+=1
    if b=='R':
        a[2]+=1
    if b=='C':
        a[3]+=1
    if b=='H':
        a[4]+=1
b=0
for i in range(5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            b+=a[i]*a[j]*a[k]
print(b)

Solution (Python):
N = int(input())
s = [input() for _ in range(N)]
count = [0]*5
for i in s:
    if i[0]=="M":
        count[0] += 1
    elif i[0]=="A":
        count[1] += 1
    elif i[0]=="R":
        count[2] += 1
    elif i[0]=="C":
        count[3] += 1
    elif i[0]=="H":
        count[4] += 1
ans = 1
i = 0
h = len(count)
while i < h:
    if count[i]==0:
        count.pop(i)
        h -= 1
        i = 0
    else:
        i += 1

if len(count)<3:
    ans = 0
elif len(count)==3:
    ans = 1
    for i in count:
        ans *=  i
else:
    ans = 0
    for bit in range(1<<len(count)):
        a = []
        b = 1
        for i in range(len(count)):
            mask = 1<<i
            if mask&bit:
                a.append(count[i])
                b *= count[i] 
        if len(a)==3:
            ans +=b
    
print(ans)

Solution (Python):
import sys
from itertools import combinations
N, *S = open(0).read().split()

T = [0]*5

for s in S:
    i = s[0]
    if i == 'M':
        T[0] += 1
    elif i == 'A':
        T[1] += 1
    elif i == 'R':
        T[2] += 1
    elif i == 'C':
        T[3] += 1
    elif i == 'H':
        T[4] += 1

T.sort(reverse=True)

k = 0
for t in T:
    if t:
        k += 1

ans = 0
for a, b, c in combinations(range(k), 3):
    ans += T[a] * T[b] * T[c]
print(ans)

Solution (Python):
N = int(input())
S = [0] * 5
for _ 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

import itertools
ans = 0
for v in itertools.combinations(S, 3):
  ans +=  v[0] * v[1] * v[2]
print(ans)

Solution (Python):
from collections import defaultdict
n = int(input())
h = 'MARCH'
d = [0] * 5
for _ in range(n):
    s = input()
    if s[0] in h:
        d[h.find(s[0])] += 1

ans = 0
for i in range(5):
    for j in range(i, 5):
        if i == j:
            continue
        for k in range(j, 5):
            if i == k or j == k:
                continue
            ans += d[i] * d[j] * d[k]
print(ans)

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

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

if len(cnt) < 3:
    print(0)
    exit()

ans = 0
comb = list(combinations(["M","A","R","C","H"], 3))
for i in range(len(comb)):
    tmp = 1
    for c in comb[i]:
        tmp *= cnt[c]
    ans += tmp

print(ans)

Solution (Python):
import itertools

n = int(input())
name_list = []
march = [0] * 5
name = {'M', 'A', 'R', 'C', 'H'}

for i in range(n):
    s = input()
    if s[0] not in name:
        continue
    else:
        name_list.append(s[0])
        if s[0] == 'M':
            march[0] += 1
        elif s[0] == 'A':
            march[1] += 1
        elif s[0] == 'R':
            march[2] += 1
        elif s[0] == 'C':
            march[3] += 1
        elif s[0] == 'H':
            march[4] += 1
if len(set(name_list)) < 3:
    print(0)
    exit()
else:
    ans = 0
    for i in itertools.combinations(set(name_list), 3):
        tmp = 1
        for j in i:
            if j == 'M':
                j = 0
            elif j == 'A':
                j = 1
            elif j == 'R':
                j = 2
            elif j == 'C':
                j = 3
            else:
                j = 4
            tmp *= march[j]
        ans += tmp

    print(ans)

Solution (Python):
n = int(input())
m = 0
a = 0
r = 0
c = 0
h = 0
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
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())
m=0
a=0
r=0
c=0
h=0
for i in range(n):
  s=input()[0:1]
  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
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
from collections import defaultdict
import sys
input = sys.stdin.readline

N = int(input())
S = [input().rstrip() for _ in range(N)]
cnt = defaultdict(int)
for s in S:
    if s[0] in 'MARCH':
        cnt[s[0]] += 1
ans = 0
for comb in combinations('MARCH', 3):
    ans += cnt[comb[0]] * cnt[comb[1]] * cnt[comb[2]]
print(ans)

Solution (Python):
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations
import math
import bisect
from collections import defaultdict, deque
import sys




import numpy as np


def main():
    n = int(input())
    dict = defaultdict(int)
    for _ in range(n):
        s = input()
        if s[0] in ['M', 'A', 'R', 'C', 'H']:
            dict[s[0]] += 1
    ans = 0
    if len(dict) < 3:
        print(ans)
    else:
        l = [v for v in dict.values() if v != 0]
        for a, b, c in combinations(l, 3):
            ans += a * b * c
        print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import Counter
from operator import mul
from functools import reduce


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(readline())
s = []
check = ['M', 'A', 'R', 'C', 'H']
for i in range(n):
    ss = readline().rstrip().decode()
    if ss[0] in check:
        s.append(ss[0])
counter = list(Counter(s).values())
if len(counter) < 3:
    print(0)
    exit()
ans = cmb(sum(counter), 3)
for v in counter:
    if v >= 2:
        ans -= cmb(v, 2) * (len(s) - v)
        if v >= 3:
            ans -= cmb(v, 3)
print(ans)

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

Solution (Python):
from collections import defaultdict
dic = defaultdict(int)
march = ["M","A","R","C","H"]
n = int(input())
for i in range(n):
    s = input()
    if s[0] in march:
        dic[s[0]] += 1
ans = 0
for i in range(5):
    for j in range(5):
        for k in range(5):
            if i != j and j != k and k != i:
                ans += dic[march[i]]*dic[march[j]]*dic[march[k]]
print(ans//6)

Solution (Python):
n,*name=open(0)
n=int(n)
l=[0]*5
for c in name:
	x=c[0]
	if x=="M":
		l[0]+=1
	elif x=="A":
		l[1]+=1
	elif x=="R":
		l[2]+=1
	elif x=="C":
		l[3]+=1
	elif x=="H":
		l[4]+=1
from itertools import combinations
ans=0
for c in combinations(range(5),3):
	ans+=l[c[0]]*l[c[1]]*l[c[2]]
print(ans)