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())

cnt_dict = {'M':0, 'A':0, 'R': 0, 'C':0, 'H':0}
first_letters = cnt_dict.keys()

for i in range(N):
    first_letter = input()[0]
    if first_letter in first_letters:
        cnt_dict[first_letter] += 1
        
sum_cnt = 0
for comb in itertools.combinations(cnt_dict, 3):
    comb_num = 1
    for c in comb:
        comb_num *= cnt_dict[c]
    sum_cnt += comb_num

print(sum_cnt)

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

Solution (Python):
import itertools
N=int(input())
key='MARCH'
cnt=[0]*5
for i in range(N):
    S=input()
    for j in range(5):
        if(S[0]==key[j]):
            cnt[j]+=1
ans=0
for v in itertools.combinations(cnt,3):
    ans+=v[0]*v[1]*v[2]
print(ans)

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

Solution (Python):
comp='MARCH'
cnt=[0,0,0,0,0]

n=int(input())
for i in range(n):
  word=input()
  for j in range(len(comp)):
    if word[0]==comp[j]: cnt[j]+=1

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

Solution (Python):
from itertools import combinations

N = int(input())

candidates = {c:0 for c in "MARCH"}
combination = combinations("MARCH", 3)

for c in tuple(input()[0] for _ in range(N)):
    if c in "MARCH":
        candidates[c] += 1

print(0 if sum(candidates.values()) < 3 else sum(candidates[a] * candidates[b] * candidates[c] for a, b, c in combination))

Solution (Python):
from collections import defaultdict
def Combi2(n):
  return n*(n-1)//2
def Combi3(n):
  return n*(n-1)*(n-2)//6
def main():
  n=int(input())
  d=defaultdict(int)
  l="MARCH"
  for _ in range(n):
    s=input()[0]
    if s in l:
      d[s]+=1
  if len(d)<3:
    print(0)
    return
  s=sum(d.values())
  ans=Combi3(s)
  for i in d.values():
    if i>=2:
      ans-=Combi2(i)*(s-i)
      if i>=3:
        ans-=Combi3(i)
  print(ans)
main()

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

ans = 0
m, a, r, c, h = 0, 0, 0, 0, 0
for _ 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 += 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 collections import Counter
from itertools import combinations

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

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):
from itertools import combinations
n = int(input())
names = [input() for _ in range(n)]
march = "MARCH"
cnt = {k: 0 for k in march}
for name in names:
    if any(name.startswith(s) for s in march):
        cnt[name[0]] += 1
cnt = [v for _, v in cnt.items()]
if len([v for v in cnt if v > 0]) < 3:
    print(0)
else:
    result = sum(a * b * c for a, b, c in combinations(cnt, 3))
    print(result)

Solution (Python):

import math
import heapq
import bisect
import numpy as np
from collections import Counter


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

cnt = [0]*5
M = 'MARCH'
for s in S:
    for i in range(5):
        if s[0] == M[i]:
            cnt[i] += 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)

Solution (Python):

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

cnt = [0]*5
for i in range(n):
    if s[i][0] == "M": cnt[0]+=1
    if s[i][0] == "C": cnt[1]+=1
    if s[i][0] == "R": cnt[2]+=1
    if s[i][0] == "A": cnt[3]+=1
    if s[i][0] == "H": cnt[4]+=1
ans = 0

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

Solution (Python):
n=int(input())
march=["M","A","R","C","H"]
count=[0]*5
for i in range(n):
    s=input()
    for j in range(5):
        if s[0]==march[j]:
            count[j]+=1
c0=count[0]
c1=count[1]
c2=count[2]
c3=count[3]
c4=count[4]
ans=c0*c1*c2+c0*c1*c3+c0*c1*c4+c0*c2*c3+c0*c2*c4+c0*c3*c4+c1*c2*c3+c1*c2*c4+c1*c3*c4+c2*c3*c4
print(ans)

Solution (Python):
import itertools
from collections import defaultdict
n = int(input())
d = defaultdict(lambda: 0)
for i in range(n):
    s = input()
    d[s[0]] += 1
ans = 0

for x, y, z in list(itertools.combinations(['M', 'A', 'R', 'C', 'H'], 3)):
    ans += d[x]*d[y]*d[z]
print(ans)

Solution (Python):
import itertools

N=int(input())
L=[0,0,0,0,0]
T="MARCH"

for i in range(N):
    S=input()
    for i in range(5):
        if S[0]==T[i]:
            L[i]+=1
            
ans=0
for itr in itertools.combinations(range(5), 3):
    ans+=L[itr[0]]*L[itr[1]]*L[itr[2]]
    
print(ans)

Solution (Python):


N = int(input())




sList=[input() for i in range(N)]

m = 0;
a = 0;
r = 0;
c = 0;
h = 0;
for i in range(len(sList)):
  s = sList[i];
  if s[0] == 'M':
    m = m + 1;
  elif s[0] == 'A':
    a = a + 1;
  elif s[0] == 'R':
    r = r + 1;
  elif s[0] == 'C':
    c = c + 1;
  elif s[0] == 'H':
    h = h + 1;
  


result = m * a * r + m * a * c + m * a * h + m * r * c + m * r * h + m * c * h + a * r * c + a * r * h + r * c * h + a * c * h;
print(result);

Solution (Python):
import itertools
import math
import sys
from collections import Counter
from fractions import gcd
from functools import reduce

n = int(input())
cnt = 0
ans = [0] * 5
for i in range(n):
    s = input()
    letters = ["M", "A", "R", "C", "H"]
    if s[0] in letters:
        ans[letters.index(s[0])] += 1

cnt = 0
for i in ans:
    if i >= 1:
        cnt += 1
if cnt < 3:
    print(0)
else:
    ans2 = 1
    without0 = []
    for i in ans:
        if i > 0:
            without0.append(i)
            ans2 *= i
    
    if cnt == 3:
        print(ans2)
    elif cnt == 4:
        ans3 = 0
        for i in without0:
            ans3 += ans2 // i
        print(ans3)
    else:
        ans4 = 0
        for i in range(len(without0) - 1):
            for j in range(i + 1, len(without0)):
                division = without0[i] * without0[j]
                ans4 += ans2 // division
        print(ans4)

Solution (Python):
N=int(input())
S=[]
for i in range(0,N):
    S.append(input())
namedata=[0,0,0,0,0]
for i in range(0,N):
    if S[i][0]=='M':
        namedata[0]+=1
    elif S[i][0]=='A':
        namedata[1]+=1
    elif S[i][0]=='R':
        namedata[2]+=1
    elif S[i][0]=='C':
        namedata[3]+=1
    elif S[i][0]=='H':
        namedata[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+=namedata[i]*namedata[j]*namedata[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
    if s[0] == "A":
        a += 1
    if s[0] == "R":
        r += 1
    if s[0] == "C":
        c += 1
    if s[0] == "H":
        h += 1

D = []
D.append(m)
D.append(a)
D.append(r)
D.append(c)
D.append(h)

P = [0, 0, 0, 0, 0, 0, 1, 1, 1, 2]
Q = [1, 1, 1, 2, 2, 3, 2, 2, 3, 3]
R = [2, 3, 4, 3, 4, 4, 3, 4, 4, 4]

ans = 0
for i in range(10):
    ans += D[P[i]] * D[Q[i]] * D[R[i]]
print(ans)

Solution (Python):
if __name__ == '__main__':
    N=int(input())
    Ms=set()
    As=set()
    Rs=set()
    Cs=set()
    Hs=set()
    for i in range(N):
        name=input()
        if name[0]=="A":
            As.add(name)
        elif name[0]=="M":
            Ms.add(name)
        elif name[0]=="R":
            Rs.add(name)
        elif name[0]=="C":
            Cs.add(name)
        elif name[0]=="H":
            Hs.add(name)
    NAMES=[Ms.__len__(),As.__len__(),Rs.__len__(),Cs.__len__(),Hs.__len__()]
    zeros=NAMES.count(0)
    if zeros>=3:
        print(0)
    else:
        from itertools import combinations
        ans=0
        for comb in combinations(NAMES,3):
            if 0 in comb:
                continue
            else:
                temp=1
                for c in comb:
                    temp*=c
                ans+=temp
        print(ans)

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

Solution (Python):
from collections import Counter
march = "MARCH"
n = int(input())
initial = Counter([input()[0] for _ in range(n)])
ans = []
for i, num in initial.items():
    if i in march:
        ans.append(num)

x = len(ans)
if x < 3:
    print(0)
elif x >= 3:
    y = 0
    for i in range(0, x-2):
        for j in range(i+1, x-1):
            for k in range(j+1, x):
                y += ans[i] * ans[j] * ans[k]
    print(y)

Solution (Python):


import sys
import math
import time
import numpy as np
import collections
from collections import deque
import queue
import copy


def gcd(m,n):
  x = max(m,n)
  y = min(m,n)
  if x%y == 0:
    return y
  else:
    while x%y != 0:
      z = x%y
      x = y
      y = z
    else:
      return z


def bfs(SS, x, y, H, W):
  x_next = [0, 0, -1, 1]
  y_next = [1, -1, 0, 0]
  tempx = x
  tempy = y
  mlength = 0
  q = deque()
  xytuple = (x, y, 0)
  q.append(xytuple)


  while q:
    xytuple = q.popleft()
    SS[xytuple[0]][xytuple[1]] = "x" 
    for i in range(4): 
      tempx = xytuple[0] + x_next[i]
      tempy = xytuple[1] + y_next[i]
      
      
      if(0 <= tempx and tempx < H and 0 <= tempy and tempy < W and SS[tempx][tempy] == "."):
        temptuple = (tempx, tempy, xytuple[2]+1)
        SS[temptuple[0]][temptuple[1]] = "x" 
        mlength = max(mlength, xytuple[2] +1)
        q.append(temptuple)
      
  return mlength

def brick(a,n,m,N):
  
  if not m in a[n:]:
    print(N-(m-1))
  else:
    
    brick(a,a[n:].index(m),m+1,N)




N = int(input())
S = []
Mc = 0
Ac = 0
Rc = 0
Cc = 0
Hc = 0
ans = 0

for i in range(N):
    S.append(str(input())[0])
    if(S[i]=="M"):
        Mc +=1
    elif(S[i]=="R"):
        Rc += 1
    elif(S[i]=="A"):
        Ac += 1
    elif(S[i]=="C"):
        Cc += 1
    elif(S[i]=="H"):
        Hc += 1

ans += Mc*Ac*Rc
ans += Mc*Ac*Cc
ans += Mc*Ac*Hc
ans += Mc*Rc*Cc
ans += Mc*Rc*Hc
ans += Mc*Cc*Hc
ans += Ac*Rc*Cc
ans += Ac*Hc*Cc
ans += Ac*Rc*Hc
ans += Cc*Rc*Hc

print(ans)

Solution (Python):
import itertools
N = int(input())
S_num = [0] * 5
answer = 0
for _ in range(N):
    S = input()
    if S[0] == 'M':
        S_num[0] += 1
    elif S[0] == 'A':
        S_num[1] += 1
    elif S[0] == 'R':
        S_num[2] += 1
    elif S[0] == 'C':
        S_num[3] += 1
    elif S[0] == 'H':
        S_num[4] += 1

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

Solution (Python):
def main():
    n = int(input())
    initials = ["M", "A", "R", "C", "H"]
    person_name = {}
    for initial in initials:
        person_name[initial] = 0
    for _ in range(n):
        name = input()
        if name[0] in person_name:
            person_name[name[0]] += 1
    answer = 0
    for i in range(5):
        for j in range(i + 1, 5):
            for k in range(j + 1, 5):
                answer += person_name[initials[i]] * person_name[initials[j]] * person_name[initials[k]]
    print(answer)


if __name__ == '__main__':
    main()

Solution (Python):
from itertools import combinations
from collections import Counter
N=int(input())
S=Counter()
for i 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())
lis = [0] * 5
name = ['M','A','R','C','H']

for i in range(n):
    s = list(input())
    for j in range(5):
        if s[0] == name[j]:
            lis[j] += 1

ans = 0

for i in range(5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            ans += lis[i] * lis[j] * lis[k]
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())
m,a,r,c,h = [0]*5
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
x = [m,a,r,c,h]
y = ["M","A","R","C","H"]
ans = 0
for i in itertools.combinations(x,3):
    ans += i[0]*i[1]*i[2]
print(ans)

Solution (Python):
import math
n = int(input())
a = ["M","A","R","C","H"]
dic = {}
def combination(n,r):
	return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))
for i in range(n):
	x = input()
	if x[0] in a:
		if x[0] in dic:
			dic[x[0]] += 1
		else:
			dic[x[0]] = 1
b = []
for i in dic.values():
	b.append(i)

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

Solution (Python):
n=int(input())
slist=[input() for i in range(n)]
m,a,r,c,h = 0,0,0,0,0
for s in slist:
  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
li=[m,a,r,c,h]
li=[i for i in li if i>0]
import itertools
if len(li)<3:
  print(0)
  exit()

b = list(itertools.combinations(li, 3))
ans=0
for i in b:
  ans += i[0]*i[1]*i[2]
print(ans)

Solution (Python):
n=int(input())
info=[["M",0],["A",0],["R",0],["C",0],["H",0]]
kind=0
for i in range(n):
    s=input()
    for i in range(5):
        if s[0]==info[i][0]:
            if info[i][1]==0:
                kind+=1
            info[i][1]+=1
            break
if kind<=2:
    print(0)
else:
    kind_num=[] 
    for i in range(5):
        if info[i][1]!=0:
            kind_num.append(info[i][1])
    all_=[]
    for i in range(kind):
        for j in range(kind):
            if j<=i:
                continue
            for k in range(kind):
                if k<=j:
                    continue
                all_.append([i,j,k])
    ans=0
    for i in range(len(all_)):
        ans+=kind_num[all_[i][0]]*kind_num[all_[i][1]]*kind_num[all_[i][2]]
    print(ans)

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 = m[0]*m[1]*m[2]
ans += m[0]*m[1]*m[3]
ans += m[0]*m[1]*m[4]
ans += m[0]*m[2]*m[3]
ans += m[0]*m[2]*m[4]
ans += m[0]*m[3]*m[4]
ans += m[1]*m[2]*m[3]
ans += m[1]*m[2]*m[4]
ans += m[1]*m[3]*m[4]
ans += m[2]*m[3]*m[4]
print(ans)

Solution (Python):
from itertools import combinations

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

ret = 0
for a, b, c in combinations(lst, 3):
    ret += a * b * c

print(ret)

Solution (Python):
import itertools
N = int(input())
S = []
count = [0, 0, 0, 0, 0]
l = list('MARCH')
for _ in range(N):
    name = input()
    
    if name[0] in list('MARCH'):
        S.append(name)
        count[l.index(name[0])] += 1



count = list(itertools.filterfalse(lambda x: x == 0, count))


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

Solution (Python):
from itertools import combinations 
n = int(input())
march_num = {"M":0,"A":0,"R":0,"C":0,"H":0}

for _ in range(n):
    s = input()
    if s[0] in set(march_num):
        march_num[s[0]] += 1;
        
ans = 0
for x,y,z in combinations(set(march_num),3):
    ans += march_num[x] * march_num[y] * march_num[z]
        
print(ans)

Solution (Python):
N = int(input())
li = ['0'] * N
for i in range(N) :
    li[i] = input()
import collections
from collections import deque
M = deque()
A = deque()
R = deque()
C = deque()
H = deque()
for i in range(N) :
    if li[i][0] == 'M' :
        M.append(li[i])
    if li[i][0] == 'A' :
        A.append(li[i])
    if li[i][0] == 'R' :
        R.append(li[i])
    if li[i][0] == 'C' :
        C.append(li[i])
    if li[i][0] == 'H' :
        H.append(li[i])
m = len(M)
a = len(A)
r = len(R)
c = len(C)
h = len(H)
s = m * a * (r + c + h) + m * r * (c + h) + m * c * h + a * r * (c + h) + r * c * h + a * c * h
print(s)

Solution (Python):
N = int(input())
S = []
for i in range(N):
    S.append(input())
r = ["M","A","R","C","H"]
x = dict()

for i in range(N):
    if S[i][0] not in r:
        continue
    if S[i][0] in x:
        x[S[i][0]] += 1
    else:
        x[S[i][0]] = 1

l = []
num = 0

for idx in x:
    l.append(x[idx])

n = len(l)
ans = 0
if n<=2:
    print(0)
    exit()

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())

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

P = [0, 0, 0, 0, 0, 0, 1, 1, 1, 2]
Q = [1, 1, 1, 2, 2, 3, 2, 2, 3, 3]
R = [2, 3, 4, 3, 4, 4, 3, 4, 4, 4]

d = [m, a, r, c, h]

ans = 0
for i in range(10):
  ans += d[P[i]] * d[Q[i]] * d[R[i]]

print(ans)

Solution (Python):
from collections import Counter
from itertools import combinations
import numpy as np
n=int(input())
L=[]
for i in range(n):
    w=input()
    L.append(w[0])
CNT=Counter(L)
m=CNT['M']
a=CNT['A']
r=CNT['R']
c=CNT['C']
h=CNT['H']
comb=combinations([m,a,r,c,h], 3)
ans=0
for kumi in comb:
    ans+=np.prod(kumi)
print(ans)

Solution (Python):
import itertools

def solve(n, S):
    initials = ('M', 'A', 'R', 'C', 'H')
    d = {}
    for s in S:
        if s[0] in initials:
            d[s[0]] = d.get(s[0], 0) + 1
    return sum(d[x] * d[y] * d[z] for x, y, z in itertools.combinations(d.keys(), 3))

_n = int(input())
_S = [input() for _ in range(_n)]
print(solve(_n, _S))

Solution (Python):
n = int(input())
l = [0]*5
for i in range(n):
    a = input()
    if a[0] == "M":
        l[0] += 1
    elif a[0] == "A":
        l[1] += 1
    elif a[0] == "R":
        l[2] += 1
    elif a[0] == "C":
        l[3] += 1
    elif a[0] == "H":
        l[4] += 1
    
    
ans = 0
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())
data = {'M':0 , 'A':0 , 'R':0 , 'C':0 , 'H':0 }
for i in range(n):
  s = input()
  if(s[0] == 'M'):
    data['M'] += 1
  if(s[0] == 'A'):
    data['A'] += 1
  if(s[0] == 'R'):
    data['R'] += 1
  if(s[0] == 'C'):
    data['C'] += 1
  if(s[0] == 'H'):
    data['H'] += 1
Data = sorted(data.values())
ans = 0
for i in range(0,5):
  for j in range(i+1,5):
    for k in range(j+1,5):
      ans += Data[i]*Data[j]*Data[k]
      
print(ans)

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

n=int(input())
s=[input() for i in range(n)]
name=['M','A','R','C','H']

cnt=defaultdict(lambda:0)
for i in range(n):
    if s[i][0] in name:
        cnt[s[i][0]]+=1

cnt=cnt.values()
if len(cnt)<3:
    print(0)
    exit()
ans=0


for x,y,z in combinations(cnt,3):
    ans+=x*y*z

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 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
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):
import itertools
N=int(input())
S=list(str(input()) for i in range(N))
m,a,r,c,h=[0]*5
ans=0
for i in range(len(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

x=[m,a,r,c,h]
for i in itertools.combinations(x,3):
  ans+=i[0]*i[1]*i[2]
print(ans)

Solution (Python):
import itertools

n = int(input())
m, a, r, c, h = [0] * 5
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
x = [m, a, r, c, h]
y = ["M", "A", "R", "C", "H"]
ans = 0
for i in itertools.combinations(x, 3):
    ans += i[0] * i[1] * i[2]
print(ans)

Solution (Python):
n=int(input())
m,a,r,c,h=0,0,0,0,0
for i in range(n):
  x=input()[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
s=[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(sum(s))

Solution (Python):
from collections import Counter
from itertools import combinations
N=int(input())
S=[input()[0] for i in range(N)]
S=Counter(S)
h=combinations(['M','A','R','C','H'],3)
h_dic={'M':0,'A':0,'R':0,'C':0,'H':0}
ans = 0
for key,value in S.items():
    if key in h_dic:
        h_dic[key] = value

for i in h:
    tmp = 1
    for j in i:
        tmp *= h_dic[j]
    ans += tmp
print(ans)

Solution (Python):
import itertools
import numpy as np
n = int(input())

names = {}
for i in range(n):
    initial = input()[0]
    names[initial] = names.get(initial, 0) + 1

print(np.sum(np.prod(pattern) for pattern in itertools.combinations([names.get(v, 0) for v in 'MARCH'], r=3)))

Solution (Python):

from itertools import combinations

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


filter_1 = {'M', 'A', 'R', 'C', 'H'}
canditates = [S for S in SSS if S[0] in filter_1]
cand_inits = [c[0] for c in canditates]
cand_inits_set = set(cand_inits)
init_counts = {init_c: cand_inits.count(init_c) for init_c in filter_1}

n_combi = 0
for init_combi in combinations(cand_inits_set, 3):
    tmp_combi = 1
    for init_c in init_combi:
        tmp_combi *= init_counts[init_c]

    n_combi += tmp_combi

print(n_combi)

Solution (Python):

import sys
import math
import os
import itertools

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]

class Util():
    def round_up(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Util.round_up(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x

N = cin.int()
S = cin.stringList(N)
A = [0] * 5
for key,value in itertools.groupby(sorted(S),key = lambda x : x[0]):
    if key in "MARCH":
        A["MARCH".index(key)] = len(list(value))
ans = 0        
for p in itertools.combinations(range(5),3):
    ans += A[p[0]] * A[p[1]] * A[p[2]]
print(ans)

Solution (Python):
from collections import defaultdict
import itertools
N = int(input())
dic = defaultdict(int)
for i in range(N):
    S = input()[0]
    dic[S] += 1
lis = itertools.combinations(["M","A","R","C","H"],3)
ans = 0
for a,b,c in lis:
    ans += dic[a]*dic[b]*dic[c]
print(ans)

Solution (Python):
from itertools import combinations
from collections import defaultdict
N = int(input())
names = [input() for _ in range(N)]

d = defaultdict(int)
for name in names:
    tmp = name[0]
    if tmp in 'MARCH':
        d[tmp] += 1

keys = d.keys()
if len(keys) < 3:
    print(0)
else:
    cnt = 0
    for a, b, c in combinations(keys, 3):
        cnt += d[a] * d[b] * d[c]
    print(cnt)

Solution (Python):
from functools import reduce
from operator import mul
from itertools import combinations

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

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

c = [ss.count(x) for x in march]
combi = list(combinations(c, 3))

print(sum([reduce(mul, x) for x in combi]))

Solution (Python):
import itertools
N = int(input())
M = {'M':0,'A':0,'R':0,'C':0,'H':0}
for _ in range(N):
    s = input()
    if M.get(s[0]) != None:
        M[s[0]] += 1
X = [M[key] for key in M.keys()]
Z = [i for i in range(5)]
Y = list(itertools.combinations(Z,r=3))
ans = 0
for i in Y:
    tmp = 1
    for j in i:
        tmp *= X[j]
    ans += tmp
print(ans)

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

M = []
A = []
R = []
C = []
H = []
for _ in range(N):
  s = input()
  if s[0] == 'M':
    M.append(s)
  if s[0] == 'A':
    A.append(s)
  if s[0] == 'R':
    R.append(s)
  if s[0] == 'C':
    C.append(s)
  if s[0] == 'H':
    H.append(s)
m_len = len(M)
a_len = len(A)
r_len = len(R)
c_len = len(C)
h_len = len(H)
ans = 0
ans += m_len * a_len * r_len
ans += m_len * a_len * c_len
ans += m_len * a_len * h_len
ans += m_len * r_len * c_len
ans += m_len * r_len * h_len
ans += m_len * c_len * h_len
ans += a_len * r_len * c_len
ans += a_len * r_len * h_len
ans += a_len * c_len * h_len
ans += r_len * c_len * h_len

print(ans)

Solution (Python):
import sys
import collections
import itertools

input = sys.stdin.readline


def main():
    N = int(input())
    C = collections.Counter()
    for _ in range(N):
        S = input().strip()
        C[S[0]] += 1

    ans = 0
    for x, y, z in itertools.combinations("MARCH", 3):
        ans += C[x] * C[y] * C[z]

    print(ans)



if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
import itertools
n = int(input()) 
l = [input()[0] for _ in range(n)]
l = [i for i in l if i in {'M','A','R','C','H'}]

if len(l) < 3:
    print(0)
else:
    c = Counter(l)
    cl = list(itertools.combinations(c,3))
    ans = 0
    for i in cl:
        ans += c[i[0]] * c[i[1]] * c[i[2]]
    print(ans)

Solution (Python):


import itertools
N=int(input())
A=[[]]*5
L=['M','A','R','C','H']

C=[0]*5

for i in range(N):
    name=input()
    if name[0] in L:
        C[L.index(name[0])]+=1

n=0
ans=0
for i in range(5):
    if C[i]!=0:
        n+=1
        
if n<3:
    print(0)
else:
    C_=[]
    for i in range(5):
        if C[i]!=0:
            C_.append(C[i])
    
    
    
    l=len(C_)
    
    for i in range(l-2):
        for j in range(i+1,l-1):
            for k in range(j+1,l):
                
                
                m=C_[i]*C_[j]*C_[k]
                ans+=m
                m=0
    print(ans)

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

for _ in range(n):
    t = input()
    for i in range(5):
        if t[0] == s[i]:
            m[i] += 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):
n=int(input())
m,a,r,c,h=0,0,0,0,0
for i in range(n):
    x=input()
    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
    else:
        continue

ans=0
ans+=(m*a*r)
ans+=(m*a*c)
ans+=(m*a*h)
ans+=(m*c*r)
ans+=(m*h*r)
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

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

march = ["M", "A", "R", "C", "H"]
d = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
cnt = 0
for i in range(N):
    if Sn[i][0] not in march:
        continue
    d[Sn[i][0]] += 1
    cnt += 1

ans = 0
for a, b, c in combinations(march, 3):
    ans += d[a] * d[b] * d[c]

print(ans)

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

ls_cn = [0] * 5

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

x = 0

for j in range(2**5):
    ls_mul = []
    for k in range(n):
        if ((j >> k) & 1):
            ls_mul.append(ls_cn[k])
    
    if len(ls_mul) == 3:
        x += ls_mul[0] * ls_mul[1] * ls_mul[2]

print(x)

Solution (Python):
from collections import Counter
from itertools import combinations
S = [input()for _ in range(int(input()))]
C = Counter(s[0] for s in S)
march = [s for s in "MARCH" if s in C]
ans = 0
for p in combinations(march, 3):
    ans += C[p[0]]*C[p[1]]*C[p[2]]
print(ans)

Solution (Python):
import functools
import itertools
import operator

required_char = 'MARCH'
N = int(input())
name_counter = {s: 0 for s in required_char}
for _ in range(N):
    S = input()
    if S[0] in required_char:
        name_counter[S[0]] += 1
ans = 0
for cmb in itertools.combinations(name_counter.values(), 3):
    ans += functools.reduce(operator.mul, cmb)
print(ans)

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

cont_M = 0
cont_A = 0
cont_R = 0
cont_C = 0
cont_H = 0

for i in range(N):
    if A[i][0][0] =='M':
        cont_M += 1
    elif A[i][0][0] =='A':   
        cont_A += 1
    elif A[i][0][0] =='R':   
        cont_R += 1
    elif A[i][0][0] =='C': 
        cont_C += 1
    elif A[i][0][0] =='H': 
        cont_H += 1
B = [cont_M , cont_A , cont_R , cont_C , cont_H ]



import itertools

c = list(itertools.combinations(B, 3))

ans = 0
for i in c:
    ans += i[0] * i[1] * i[2]
    
print(ans)

Solution (Python):
import sys

if sys.platform =='ios':
	sys.stdin=open('input_file.txt')
	

import itertools
n=int(input())
a={}
for _ in range(n):
	s=input().strip()
	t=a.get(s[0], 0)
	a[s[0]]=t+1

ans=0
for x,y,z in itertools.combinations(list('MARCH'), 3):
	ans+=a.get(x, 0)*a.get(y, 0)*a.get(z, 0)
	
print(ans)

Solution (Python):
import sys

if sys.platform =='ios':
	sys.stdin=open('input_file.txt')
	

import itertools
n=int(input())
a={}
for _ in range(n):
	s=input().strip()
	t=a.get(s[0], 0)
	a[s[0]]=t+1

ans=0
for x,y,z in itertools.combinations(list('MARCH'), 3):
	ans+=a.get(x, 0)*a.get(y, 0)*a.get(z, 0)
	
print(ans)