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())
A = [input() for _ in range(N)]
B = list()
num_M=0
num_A=0
num_R=0
num_C=0
num_H=0
for i in A:
  if i[0]=='M':
    num_M+=1
    continue
  if i[0]=='A':
    num_A+=1
    continue
  if i[0]=='R':
    num_R+=1
    continue
  if i[0]=='C':
    num_C+=1
    continue
  if i[0]=='H':
    num_H+=1
    continue
print(num_M*num_A*num_R+num_M*num_A*num_C+num_M*num_A*num_H+num_M*num_R*num_C+num_M*num_R*num_H+num_M*num_C*num_H+num_A*num_R*num_C+num_A*num_C*num_H+num_A*num_R*num_H+num_R*num_C*num_H)

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

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

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

print(ans)

Solution (Python):
from itertools import combinations

def March(n , sl):

    ans = 0
    count = {m: 0 for m in list("MARCH")}

    for i in sl:
        if i[0] in count:
            count[i[0]] += 1

    c = combinations(list("MARCH"), 3)
    for q, w, i in c:
        ans += count[q] * count[w] * count[i]

    return ans

def main():
    n = int(input())
    sl = [str(input()) for i in range(n)]
    print(March(n , sl))

if __name__ == '__main__':
    main()

Solution (Python):



N = int(input().strip())
S_list = [input().strip() for _ in range(N)]


class Combination():
    def __init__(self):
        self._selected=[]
        self._all_pattern=[]
        
    def getPattern(self, arr :list, r :int) -> list:
        self._make(arr,r)
        return self._all_pattern
        
    def _make(self, arr :list, r :int):
        if r == 0:
            self._all_pattern.append(self._selected[:])
            return 
        
        for i in range(len(arr)):
            self._selected.append( arr[i] )
            r -= 1
            
            next_arr = arr[(i+1):]
            
            ans = self._make(next_arr,r)
            if ans == None:
                del self._selected[-1]
                r += 1


cnt_word = { w:0 for w in "MARCH"}

for words in S_list:
    key = words[0]
    if key in cnt_word:
        cnt_word[ words[0] ] += 1

comb = Combination()
pattern = comb.getPattern( list("MARCH"),3)

sum=0
for p1,p2,p3 in pattern:
    sum += cnt_word[p1] * cnt_word[p2] * cnt_word[p3]

print(sum)

Solution (Python):
import itertools
N=int(input())
nameM=0
nameA=0
nameR=0
nameC=0
nameH=0
for a in range(N):
    S=input()
    ss=[]
    for b in S:
        ss.append(b)
        if ss[0]=='M':
            nameM+=1
            break
        elif ss[0]=='A':
            nameA+=1
            break
        elif ss[0]=='R':
            nameR+=1
            break
        elif ss[0]=='C':
            nameC+=1
            break
        elif ss[0]=='H':
            nameH+=1
            break
        else:
            break
list=[nameM,nameA,nameR,nameC,nameH]
answers=[a for a in list if a!=0]
b=1
if len(answers)<=2:
    print(0)
elif len(answers)==3:
    for a in answers:
        b*=a
    print(b)
elif len(answers)>=4:
    answer=0
    for x in itertools.combinations(answers,3):
        c=1
        for y in x:
            c*=y
        answer+=c
    print(answer)

Solution (Python):
import itertools

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

a_c = list(itertools.combinations([0,1,2,3,4], 3))
for i in range(len(a_c)):
    ans += a[a_c[i][0]]*a[a_c[i][1]]*a[a_c[i][2]]
print(ans)

Solution (Python):
from itertools import combinations

N = int(input())

march = list("MARCH")
S = {m: 0 for m in march}
for _ in range(N):
    s = input()
    if s[0] in S:
        S[s[0]] += 1

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

print(ans)

Solution (Python):
n = int(input())
q = []
z = ['M','A','R','C','H']
import sys
from collections import Counter
import itertools

for _ in range(n):
    s = input()
    a = s[0]
    
    if a =='M' or a =='A' or a =='R' or a =='C' or a =='H':
        q.append(a)
        
b = Counter(q)
c = list(b.keys())
m = 0

if len(b) < 3:
    print(0)
    sys.exit()
else:
    p = list(itertools.combinations(c,3))

ans = 0
for f,g,h in p:
    ans += (b[f]*b[g]*b[h])
        
print(ans)

Solution (Python):

from collections import Counter
from itertools import combinations
n = int(input())
s = [input()[0] for _ in range(n)]
cnt = Counter(s)
ans = 0
for a, b, c in combinations('MARCH', 3):
    ans += cnt[a] * cnt[b] * cnt[c]
print(ans)

Solution (Python):
from collections import defaultdict
import itertools

b = defaultdict(lambda: len(b))
n = int(input())
hed = ["M","A","R","C","H"]
for i in hed:
    b[i] 
li = [0]*5
for _ in range(n):
    a = input()
    if a[0] in hed:
        li[b[a[0]]] += 1
c = [j for j in li if j != 0]
ans = 0
for k in itertools.combinations(c,3):
    ans += k[0]*k[1]*k[2]
print(ans)

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

for i in S:
    if i in ['M','A','R','C','H']:
        d[i] += 1

e = list(d.values())

f = list(itertools.combinations(e,3))

s = 0
for i,j,k in f:
    s += i*j*k
print(s)

Solution (Python):
n=int(input())
s=[input() for _ in [0]*n]
march=[0]*5
for x in s:
  if x[0] in 'MARCH':
    march['MARCH'.index(x[0])]+=1
ans=0
for i in range(5):
  for j in range(i+1,5):
    for k in range(j+1,5):
      ans+=march[i]*march[j]*march[k]
print(ans)

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

l=[]
for i in range(n):
    l+=[input()[0]]

march=[0]*5
for j in range(n):
    if l[j]=='M':
        march[0]+=1
    elif l[j]=='A':
        march[1]+=1
    elif l[j]=='R':
        march[2]+=1
    elif l[j]=='C':
        march[3]+=1
    elif l[j]=='H':
        march[4]+=1

from itertools import combinations
ans=0
for x,y,z in combinations(march, 3):
    ans+=x*y*z

print(ans)

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

Solution (Python):

def main():
    import sys
    
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    
    from itertools import combinations, permutations
    
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    

    

    N = int(input())
    M = 0
    A = 0
    R = 0
    C = 0
    H = 0
    for _ in range(N):
        s = input().rstrip()
        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
    res = 0
    l = [M, A, R, C, H]
    for a, b, c in combinations(l, 3):
        res += a*b*c
    print(res)
    
if __name__ == '__main__':
    main()

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

num = list(name.values())
ans = 0
for i in range(3):
    for j in range(i+1,4):
        for h in range(j+1,5):
            ans += num[i]*num[j]*num[h]

print(ans)

Solution (Python):
n=int(input())
s=[input() for _ in range(n)]
from collections import Counter
cnt=0
d=Counter()
import itertools
ans=0
for i  in s:
    d[i[0]]+=1
for i , j,k in itertools.combinations("MARCH",3):
    ans+=d[i]*d[j]*d[k]
print(ans)

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

Solution (Python):
n = int(input())
headList = [0] * 5

for i in range(n):
  s = input()
  if s[0] == 'M':
    headList[0] += 1
  elif s[0] == 'A':
    headList[1] += 1
  elif s[0] == 'R':
    headList[2] += 1
  elif s[0] == 'C':
    headList[3] += 1
  elif s[0] == 'H':
    headList[4] += 1
else:
  result = 0
  result += headList[0]*headList[1]*headList[2]
  result += headList[0]*headList[1]*headList[3]
  result += headList[0]*headList[1]*headList[4]
  result += headList[0]*headList[2]*headList[3]
  result += headList[0]*headList[2]*headList[4]
  result += headList[0]*headList[3]*headList[4]
  result += headList[1]*headList[2]*headList[3]
  result += headList[1]*headList[2]*headList[4]
  result += headList[1]*headList[3]*headList[4]
  result += headList[2]*headList[3]*headList[4]

print(result)

Solution (Python):
import itertools 
N = int(input())
march = list(itertools.combinations("MARCH", 3))
dict = {i:0 for i in "MARCH"}
for _ in range(N):
    S = input()
    if(S[0] in "MARCH"):
        dict[S[0]] += 1
ans = 0
for i in range(10):
    ans +=  dict[march[i][0]]*dict[march[i][1]]*dict[march[i][2]]

print(ans)

Solution (Python):
n = int(input())
s = []
for _ in range(n):
    s.append(input()[0])
import collections
c = collections.Counter(s)
lis = [c["M"],c["A"],c["R"],c["C"],c["H"]]
from itertools import *
ans=0
for tmp in combinations(lis,3):
    ans+=tmp[0]*tmp[1]*tmp[2]
print(ans)

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

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

cnt = [cap.count(i) for i in "MARCH"]

ans = sum(x*y*z for x, y, z in combinations(cnt, 3))
print(ans)

Solution (Python):
if __name__ == "__main__":
    n = int(input())
    s = list()
    d = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
    for i in range(n):
        s.append(input())

    for ss in s:
        if ss[0] in d.keys():
            d[ss[0]] += 1

    ans = 0
    for i in d:
        for j in d:
            for k in d:
                if i != j and i != k and j != k:
                    ans += d[i] * d[j] * d[k]

    print(ans//6)

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

N = int(input())
words_count = {
  'M': 0,
  'A': 0,
  'R': 0,
  'C': 0,
  'H': 0
}
  
for _ in range(N):
  name = input()
  if name[0] in words_count.keys():
    words_count[name[0]] += 1

ans = 0
patterns = itertools.combinations(words_count.keys(), 3)
for a, b, c in patterns:
  ans += words_count[a] * words_count[b] * words_count[c]

print(ans)

Solution (Python):
from collections import Counter
from itertools import combinations
N = int(input())
Slist = [input() for _ in range(N)]
Sc = Counter([S[0] for S in Slist])
ans = 0
for x, y, z in combinations(list("MARCH"), 3):
    ans += Sc[x] * Sc[y] * Sc[z]
print(ans)

Solution (Python):
import itertools
n = int(input())
d = {x: 0 for x in ["M","A","R","C","H"]}
s = []
for _ in range(n):
    st = input()
    if st[0] in d.keys():
        d[st[0]] += 1

nonzero = sum([1 for x in d.values() if x > 0])
if nonzero == 5:
    cases = 10
elif nonzero == 4:
    cases = 4
elif nonzero == 3:
    cases = 1
else:
    cases = 0

if cases == 0:
    print(0)
elif cases == 1:
    ans = cases
    for x in d.values():
        if x == 0 or x == 1:
            pass
        else:
            ans *= x
    print(ans)
elif cases > 3:
    ans = 0
    for i in ["M","A","R","C","H"]:
        if d[i] == 0:
            del d[i]
    for v in itertools.combinations(d.values(),3):
        tmp = 1
        for x in v:
            tmp *= x
        ans += tmp
    print(ans)

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

n = int(input())
c = Counter()

for _ in range(n):
  c[input()[0]]+= 1
  
ans = sum([c[pattern_i[0]]*c[pattern_i[1]]*c[pattern_i[2]] for pattern_i in combinations(['M','A','R','C','H'], 3)])
print(ans)

Solution (Python):
n=int(input())
L=[0,0,0,0,0]
for _ 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
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 operator import mul
from functools import reduce

def cmb(n,r):
    if n < r: return 0
    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(input())
ss = [input() for _ in range(n)]
march = ['M','A','R','C','H']
d = dict(zip(march, [0]*5))

nn = 0

for s in ss:
    if s[0] in march:
        d[s[0]] += 1
        nn += 1
if nn < 3:
    print(0)
    exit()

ans = cmb(nn, 3)
for i in d.values():
    if i >= 2:
        if i > 3:
            ans -= cmb(i, 3)
        ans -= cmb(i,2)*(nn-i)

print(int(ans))

Solution (Python):
import itertools
s = set()
N = int(input())
dict = {i:0 for i in "MARCH"}

sum_v = 0
ans = 0
for i in range(N):
    S = input()
    if(S[0] in "MARCH"):
        dict[S[0]] += 1
        s.add(S[0])
        sum_v += 1
        
c = itertools.combinations(s, 3)

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

Solution (Python):

from collections import Counter, defaultdict, deque







import sys



ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    n = int(input())
    initial_num = defaultdict(int)

    for i in range(n):
        s = sys.stdin.readline().rstrip("\n")
        initial = s[0]
        initial_num[initial] += 1

    ans = 0
    march = "MARCH"
    for i in range(3):
        num1 = initial_num[march[i]]
        for j in range(i+1, 4):
            num2 = initial_num[march[j]]
            for k in range(j+1, 5):
                num3 = initial_num[march[k]]
                ans += num1 * num2 * num3

    print(ans)

if __name__ == '__main__':
    main()

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

from collections import Counter
cos = Counter(S)

num = [cos[i] for i in "MARCH"]

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

print(ans)

Solution (Python):
from itertools import combinations

n = int(input())
s = [input() for _ in range(n)]
s.sort()
march = [0, 0, 0, 0, 0]
st = ['M', 'A', 'R', 'C', 'H']
for i in range(n):
    for j in range(5):
        if s[i][0] == st[j]:
            march[j] += 1

if sum(march) == 0:
    print(0)
    exit()

ans = 0

a = list(combinations(range(5), 3))
for i in range(len(a)):
    tmp = 1
    for j in a[i]:
        tmp *= march[j]
    ans += tmp

print(ans)

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

n=int(input())

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 = 0
memo = [m,a,r,c,h]

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

Solution (Python):
from itertools import combinations
n=int(input())
num=[0 for _ in range(5)]
sum=0
for i in range(n):
    s=input()
    if s[0]=="M":
        num[0]+=1
    elif s[0]=="A":
        num[1]+=1
    elif s[0]=="R":
        num[2]+=1
    elif s[0]=="C":
        num[3]+=1
    elif s[0]=="H":
        num[4]+=1
num=[i for i in num if i>=1]
if len(num)<=2:
    print(sum)
else:
    c=list(combinations(num,3))
    for i in range(len(c)):
        sum+=c[i][0]*c[i][1]*c[i][2]
    print(sum)

Solution (Python):
import collections
import itertools
n = int(input())
M = "MARCH"
S = []
for i in range(n):
  S.append(input()[0])
T = []
for i in S:
  if i in M:
    T.append(i)
U = collections.Counter(T)
TT = set(T)
P = list(itertools.combinations(TT, 3))
ans = 0
for i in P:
  ans += U[i[0]] * U[i[1]] * U[i[2]]
print(ans)

Solution (Python):
n = int(input())
march = ['M','A','R','C','H']
counter = [0]*5
for i in range(n):
	s = input()
	if s[0] in march:
		counter[march.index(s[0])] += 1

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

print(ans)

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

Solution (Python):
n = int(input())
m = ["M", "A", "R", "C", "H"]
s = {}
for _ in range(n):
    s_ = input()[0]
    if s_ not in m: continue
    else:
        if s_ not in s.keys():
            s[s_] = 0
        s[s_] += 1
if len(list(s.keys())) <= 2:
    print(0)
    exit()
l = list(s.values())
n = len(l)
a = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            a += l[i] * l[j] * l[k]
print(a)

Solution (Python):
import itertools

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

MARCH=[0]*5
for name in s:
    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
c=list(itertools.product([0,1], repeat=5))

for i in c:
    a=1
    if sum(i)==3:
        for g in range(5):
            if i[g]==1:
                a*=MARCH[g]
        ans+=a
print(ans)

Solution (Python):
from functools import reduce
import itertools
n = int(input())
s = [input() for i in range(n)]
head = ['M','A','R','C','H']
number = [0]*26
new_s = [i for i in s if i[0] in head]
ans = [0,0,0,1,4,10]
for i in new_s:
    number[ord(i[0])-65] += 1
ans2 = [i for i in number if i!=0]
if len(ans2) <= 2:
    print(0)
else:
    mul = 0
    ans2 = list(itertools.combinations(ans2,3))
    for i in ans2:
        mul += reduce(lambda x,y:x*y,i)
    print(mul)

Solution (Python):
from collections import Counter
n = int(input())
s = [input() for _ in range(n)]
name_count = [0 for _ in range(5)]
for i in s:
    if i[0] == "M":
        name_count[0] += 1
    elif i[0] == "A":
        name_count[1] += 1
    elif i[0] == "R":
        name_count[2] += 1
    elif i[0] == "C":
        name_count[3] += 1
    elif i[0] == "H":
        name_count[4] += 1

result = 0
for s in range(3):
    for t in range(s+1, 4):
        for u in range(t+1, 5):
            result += name_count[s]*name_count[t]*name_count[u]
print(result)

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

S_first = [S[i][0] for i in range(N)]
march = ['M','A','R','C','H']
march_number = [0]*5

for i in range(5):
    march_number[i] = S_first.count(march[i])

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

Solution (Python):
import itertools 
n=int(input())
a=[]
for i in range(n):
    a.append(str(input()))
march=[0]*5

for i in range(n):
    if a[i][0:1]=='M':
        march[0]+=1
    if a[i][0:1]=='A':
        march[1]+=1
    if a[i][0:1]=='R':
        march[2]+=1
    if a[i][0:1]=='C':
        march[3]+=1
    if a[i][0:1]=='H':
        march[4]+=1



kumi_list=list(itertools.combinations([0,1,2,3,4],3))

ans=0
for i in kumi_list:
    b,c,d= i
    
    ans+=march[b]*march[c]*march[d]
print(ans)

Solution (Python):
n=int(input())
l ='MARCH'
cnt=[0,0,0,0,0]
 
for i in range(n):
    s = input()
    for j in range(len(l)):
        if s[0]==l[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):
import itertools

n=int(input())
name=("M","A","R","C","H")
name_cnt={}
for i in range(n):
    s=input()
    s0 = s[0]
    if s0 in name:
        if s0 in name_cnt.keys():
            name_cnt[s0] += 1
        else:
            name_cnt[s0] = 1
l=list(name_cnt.keys())

if len(l) < 3:
    print(0)
elif len(l) == 3:
    ans=1
    for v in name_cnt.values():
        ans *= v
    print(ans)
else:
    ans=0
    for c in itertools.combinations(l,3):
        ans1=1
        for i in c:
            ans1 *= name_cnt[i]
        ans += ans1
    print(ans)

Solution (Python):



from fractions import gcd 
from functools import reduce
import sys
sys.setrecursionlimit(200000000)
from inspect import currentframe




def printargs2err(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' : '+repr(arg) for arg in args),file=sys.stderr)
def debug(x):
    print(x,file=sys.stderr)
def printglobals():
    for (symbol, value) in globals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
def printlocals():
    for (symbol, value) in locals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)

def pin(type=int):
    return map(type,input().split())


"""
"""




def modular_w_binary_method (n,m,p):
    ans=1 if n>0 else 0
    while(p>0):
        if p%2==1:
            ans=(ans*n)%m
        n=(n**2)%m
        p//=2
    return ans


"""
    フェルマーの小定理より a**(p)%p==a isTrue
    これを利用すれば a**(p-2)%p==a**(-1) isTrue
    元と逆元とをかけてpで割れば1が余るよ！
"""
def modular_inverse(a,prime):
    return(modular_w_binary_method(a,prime,prime-2))



def conbination(n,a,mod=10**9+7):
    
    res=1 
    for s in range(a):
        res=(res*(n-s)*(modular_inverse(s+1,mod)))%mod

        
    return res

        

def resolve():
    N=int(input())
    S=([input()[0] for i in range(N)])
    MARCH=[0]*5
    c="MARCH"
    for item in S:
        for char in range(5):
            if item==c[char]:
                MARCH[char]+=1
    j=0
    for t in range(5):
        if MARCH[t]!=0:
            j+=1
    ans=0
    for x in range(5):
        for y in range(x+1,5):
            for z in range(y+1,5):
                if MARCH[x]*MARCH[y]*MARCH[z]!=0:
                    ans+=MARCH[x]*MARCH[y]*MARCH[z]
    print(ans)
    
    

"""


"""
"""
お前カッコ閉じるの忘れてるだろ
"""
import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI"""
        output = """2"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """4
ZZ
ZZZ
Z
ZZZZZZZZZZ"""
        output = """0"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO"""
        output = """7"""
        self.assertIO(input, output)

if __name__ == "__main__":
    resolve()

Solution (Python):
n=int(input())
dic={"M":0,"A":0,"R":0,"C":0,"H":0}

for _ in range(n):
  s=input()
  ss=s[0]
  if ss in ["M","A","R","C","H"]:
    dic[ss]=dic[ss]+1

keys=["M","A","R","C","H"]

i=0
result=0
while i<3:
  j=i+1
  while j<4:
    k=j+1
    while k<5:
      result+=dic[keys[i]]*dic[keys[j]]*dic[keys[k]]
      
      k+=1    
    j+=1  
  i+=1
print(result)

Solution (Python):
n = int(input())
count = [0]*5
d = {'M': 0, 'A': 1, 'R': 2, 'C':3, 'H': 4}

for i in range(n):
  s = input()
  if s[0] in 'MARCH':
    count[d[s[0]]] += 1

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

Solution (Python):
n = int(input())
dat = []
for _ in range(n):
    dat.append(input())
cm, ca, cr, cc, ch = 0,0,0,0,0
for i in range(n):
    if dat[i][0] == "M":
        cm += 1
    if dat[i][0] == "A":
        ca += 1
    if dat[i][0] == "R":
        cr += 1
    if dat[i][0] == "C":
        cc += 1
    if dat[i][0] == "H":
        ch += 1


res = 0
res += cm*ca*cr
res += cm*ca*cc
res += cm*ca*ch
res += cm*cr*cc
res += cm*cr*ch
res += cm*cc*ch

res += ca*cr*cc
res += ca*cr*ch
res += ca*cc*ch

res += cr*cc*ch
print(res)

Solution (Python):
import collections

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

for i in range(N):
    s = input()
    if (s[0] in 'MARCH'):
        S.append(s[0])

CNT = collections.Counter(S).most_common()
ans = 0

if (len(CNT) >= 3):

    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][1] * CNT[j][1] * CNT[k][1]

print(ans)

Solution (Python):
n = int(input())
L = ['M','A','R','C','H']

A = [0] * 5

for i in range(n):
    s = input()
    if s[0] not in L:
        continue
    A[L.index(s[0])] += 1
import itertools
total = 0
for i in list(itertools.combinations(A,3)):
    a, b, c = i
    total += a*b*c
print(total)

Solution (Python):
N = int(input())
INI = ["M","A","R","C","H"]
c = [0]*5
for i in range(N):
    S = input()
    if S[0] in INI:
        c[INI.index(S[0])] += 1

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

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

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):
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.keys():
        D[s[0]] += 1
ans = 0
for v in itertools.combinations(D.values(), 3):
    ans += v[0] * v[1] * v[2]
print(ans)

Solution (Python):
import itertools

n = int(input())
s = [0] * n
for _ in range(n):
    s[_] = input()
cnt = [0] * 5
for i in range(n):
    if s[i][0] == 'M':
        cnt[0] += 1
    elif s[i][0] == 'A':
        cnt[1] += 1
    elif s[i][0] == 'R':
        cnt[2] += 1
    elif s[i][0] == 'C':
        cnt[3] += 1
    elif s[i][0] == 'H':
        cnt[4] += 1
    else:
        pass

num = 0
newCnt = []
for i in range(5):
    if cnt[i] > 0:
        num += 1
        newCnt.append(cnt[i])

ans = 0
val = 1
if len(newCnt) < 3:
    ans = 0
elif len(newCnt) < 4:
    for i in range(len(newCnt)):
        val *= newCnt[i]
    ans = val
else:
    com = itertools.combinations(newCnt, 3)
    for i in com:
        val = 1
        for j in i:
            val *= j
        ans += val

print(ans)

Solution (Python):
from itertools import combinations
from collections import defaultdict
d = defaultdict(int)

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

ans = 0
for com in combinations('MARCH', 3):
    ans += d[com[0]] * d[com[1]] * d[com[2]]
print(ans)

Solution (Python):
import sys
input=sys.stdin.readline
n=int(input())
names=[input() for i in range(n)]
march=[0]*5
MARCH={j:i for i,j in enumerate('MARCH')}
for i in range(n):
    if names[i][0] in 'MARCH':
        march[MARCH[names[i][0]]]+=1
ans=0
for  i in range(5):
  for j in range(i+1,5):
    for k in range(j+1,5):
      ans+=march[i]*march[j]*march[k]      
print(ans)

Solution (Python):

from operator import mul
from functools import reduce
import itertools


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

m_cnt = 0
a_cnt = 0
r_cnt = 0
c_cnt = 0
h_cnt = 0

for _ in range(N):
    s = input()
    if s[0] == 'M':
        m_cnt += 1
    elif s[0] == 'A':
        a_cnt += 1
    elif s[0] == 'R':
        r_cnt += 1
    elif s[0] == 'C':
        c_cnt += 1
    elif s[0] == 'H':
        h_cnt += 1


ans = 0
march = (m_cnt, a_cnt, r_cnt, c_cnt, h_cnt)
for cb in itertools.combinations(march, 3):
    ans += cb[0] * cb[1] * cb[2]


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
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())
d={}
for i in range(n):
    a=input()
    if a[0]=="M" or a[0]=="A" or a[0]=="R" or a[0]=="C" or a[0]=="H":
        d[a[0]]=d.get(a[0],0)+1
a=list(d.values())
if len(a)<3:
    print(0)
    exit()
import itertools
c=list(itertools.combinations(a,3))
ans=0
for i,j,k in c:
    ans+=i*j*k
print(ans)

Solution (Python):
N = int(input())
count = {
    'M': 0,
    'A': 0,
    'R': 0,
    'C': 0,
    'H': 0
}

for i in range(N):
    S = input()
    for a in count:
        if S.startswith(a):
            count[a] += 1


val_list = {}
for key, val in count.items():
    if val > 0:
        val_list[key] = val

import itertools

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

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

M = 0
A = 0
R = 0
C = 0
H = 0


for n in range(N):
  _ = input()
  if _[0] == 'M':
    M += 1
  elif _[0] == 'A':
    A += 1
  elif _[0] == 'R':
    R += 1
  elif _[0] == 'C':
    C += 1
  elif _[0] == 'H':
    H += 1
  else:
    pass

ans = M*A*R + M*A*C + M*A*H + M*R*C + M*R*H + M*C*H
ans += A*R*C + A*R*H + A*C*H
ans += R*C*H
print(ans)