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 collections
import itertools
import sys
def main():
    n = int(input())
    a = [input()[0] for i in range(n)]
    b = collections.Counter(a)
    c = list(b.keys())

    char = ['M','A','R','C','H']
    check = list(map(lambda x: x in char, c))
    vals = [c[x] for x in filter(lambda x: check[x], range(len(check)))]

    if sum(b[val] for val in vals) < 3:
        print(0)
        sys.exit()

    count = 0
    for comb in itertools.combinations(vals,3):
        count+=b[comb[0]] * b[comb[1]] * b[comb[2]]
    print(count)

if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
S = []
m = ['M', 'A', 'R', 'C', 'H']
M, A, R, C, H = 0, 0, 0, 0, 0
ans = 0

if N <= 2:
    print(0)
else:
    for i in range(N):
        na = input()
        if na[0] in m:
            S.append(na)
    S =set(S)
    for i in S:
        fa = i[0]
        if fa == 'M':
            M += 1
        elif fa == 'A':
            A += 1
        elif fa == 'R':
            R += 1
        elif fa =='C':
            C += 1
        else:
            H += 1
    
    print(M*A*R + M*A*C + M*A*H + M*R*C + M*R*H + M*C*H + A*R*C + A*R*H + A*C*H + R*C*H)

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

m, a, r, c, h, zero = 0,0,0,0,0,0
for l in range(N):
	if S[l][0] == 'M':
		m += 1
	elif S[l][0] == 'A':
		a += 1
	elif S[l][0] == 'R':
		r += 1
	elif S[l][0] == 'C':
		c += 1
	elif S[l][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):

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

ACHMR = [0] * 5
idx = 0
for i, Si in enumerate(sorted(list(filter(lambda x: x[0] in "MARCH", S)))):
    
    if i == 0:
        ACHMR[0] += 1
        Si_prev = Si
        head_prev = Si[0]
        continue
    elif Si[0] != head_prev: idx += 1
    
    ACHMR[idx] += 1
    head_prev = Si[0]
    Si_prev = Si



ans = 0
for code in range(2 ** 5):
    
    code_tmp = code
    code_bin = [0] * 5
    for i in range(5):
        code_bin[i] = code_tmp % 2
        code_tmp = code_tmp >> 1
    
    if sum(code_bin) != 3: continue
    
    ans_tmp = 1
    for cnt, bit in zip(ACHMR, code_bin):
        if bit > 0: ans_tmp = ans_tmp * (cnt * bit)
    
    ans += ans_tmp

print(ans)

Solution (Python):
from itertools import combinations


def solve(N, Ss):
    caps = {c: set() for c in 'MARCH'}
    for s in Ss:
        caps.setdefault(s[0], set()).add(s)
    sum = 0
    for d in combinations('MARCH', 3):
        sum += len(caps[d[0]]) * len(caps[d[1]]) * len(caps[d[2]])
    return sum


if __name__ == "__main__":
    N = int(input())
    Ss = [input() for _ in range(N)]
    print(solve(N, Ss))

Solution (Python):
N = int(input())
li=[0]*5
for i in range(N):
    s = input().strip()
    if s[0]=='M':
        li[0]+=1
    if s[0]=='A':
        li[1]+=1
    if s[0]=='R':
        li[2]+=1
    if s[0]=='C':
        li[3]+=1
    if s[0]=='H':
        li[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+=li[i]*li[j]*li[k]
print(ans)

Solution (Python):
N = int(input())
countM = 0
countA = 0
countR = 0
countC = 0
countH = 0
for i in range(N):
    s = input()
    if (s[0] == "M"):
        countM += 1
        continue
    elif (s[0] == "A"):
        countA += 1
        continue
    elif (s[0] == "R"):
        countR += 1
        continue
    elif (s[0] == "C"):
        countC += 1
        continue
    elif (s[0] == "H"):
        countH += 1
print(countM*countA*countR+countM*countA*countC+countM*countA*countH+countM*countR*countC+countM*countR*countH+countM*countC*countH+countA*countR*countC+countA*countR*countH+countA*countC*countH+countR*countC*countH)

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

n=int(input())
l=[input().rstrip() for i in range(n)]
l_num=[0]*5
m=0
for i in range(n):
    if l[i][0]=='M':
        l_num[0]+=1
    elif l[i][0]=='A':
        l_num[1]+=1
    elif l[i][0]=='R':
        l_num[2]+=1
    elif l[i][0]=='C':
        l_num[3]+=1
    elif l[i][0]=='H':
        l_num[4]+=1
for i in range(5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            m+=l_num[i]*l_num[j]*l_num[k]
print(m)

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

m = []
a = []
r = []
c = []
h = []
for i in s:
    if i[0] == "M":
        m.append(i)
    elif i[0] == "A":
        a.append(i)
    elif i[0] == "R":
        r.append(i)
    elif i[0] == "C":
        c.append(i)
    elif i[0] == "H":
        h.append(i)

ml = len(m)
al = len(a)
rl = len(r)
cl = len(c)
hl = len(h)

count1 = ml*al*rl + ml*al*cl + ml*al*hl + ml*rl*cl + ml*rl*hl + ml*cl*hl + al*rl*cl + al*rl*hl + al*cl*hl + rl*cl*hl
print(count1)

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

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

print(ans)

Solution (Python):

import sys

iN = int(sys.stdin.readline())
dS = {"M":0,"A":0,"R":0,"C":0,"H":0}
for s in [_ for  _ in sys.stdin.readlines() if _[0] in ("M","A","R","C","H")]:
    dS[s[0]] += 1
m = dS["M"]
a = dS["A"]
r = dS["R"]
c = dS["C"]
h = dS["H"]
print(m*a*r + m*a*c + m*a*h + m*r*c+m*r*h + m*c*h + a*r*c + a*r*h +a*c*h+ r*c*h)

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

l=len(x)
if l<3:
    print(0)
elif l==3:
    print(x[0]*x[1]*x[2])
elif l==4:
    a,b,c,d=x[0],x[1],x[2],x[3]
    print(a*b*c+a*b*d+a*c*d+b*c*d)
else:
    a,b,c,d,e=x[0],x[1],x[2],x[3],x[4]
    print(a*b*c+a*b*d+a*c*d+b*c*d\
         +e*a*b+e*a*c+e*a*d+e*b*c+e*b*d\
         +e*c*d)

Solution (Python):
import re
from itertools import groupby
from itertools import groupby, combinations
import functools
import operator

pattern = r"^(M|A|R|C|H).*"
checker = re.compile(pattern)

N = int(input())
names = []
for i in range(N):
    name = input()
    if checker.match(name):
        names.append(name)
        
counts = {}
for group, item in groupby(names, lambda x:x[0]):
    counts[group] = counts[group]+(len(list(item))) if group in counts.keys() else (len(list(item)))

total = 0
for comb in combinations(counts.keys(), 3):
    tmp = []
    for letter in comb:
        tmp.append(counts[letter])

    n_comb = functools.reduce(operator.mul, tmp)
    total += n_comb
    
print(total)

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
	else:
		pass

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

Solution (Python):
def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b

n = getN()
names = {"M":0 , "A":0, "R":0, "C":0, "H":0}
for i in range(n):
    name = input()
    if name[0] in names.keys():
        names[name[0]] += 1
m,a,r,c,h = names["M"], names["A"], names["R"], names["C"], names["H"]

ans = m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h

print(ans)

Solution (Python):
n = int(input())
march = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
for i in range(n):
    str = input()
    if str[0] in march:
        march[str[0]] += 1
for i in list(march):
    if march[i] == 0:
        march.pop(i)
c = 0
if len(march) == 3:
    tmpc = 1
    for chr in march:
        tmpc *= march[chr]
    c += tmpc
elif len(march) == 4:
    for i in march:
        tmpm = march.copy()
        tmpm.pop(i)
        tmpc = 1
        for chr in tmpm:
            tmpc *= tmpm[chr]
        c += tmpc
elif len(march) == 5:
    keys = list(march.keys())
    for i in range(len(keys)):
        for j in range(i + 1, len(keys)):
            tmpm = march.copy()
            tmpm.pop(keys[i])
            tmpm.pop(keys[j])
            tmpc = 1
            for chr in tmpm:
                tmpc *= tmpm[chr]
            c += tmpc
print(c)

Solution (Python):
import itertools
N = int(raw_input())
S = [raw_input() for _ in range(N)]
march = list("MARCH")
I = {"M":0,"A":0,"R":0,"C":0,"H":0}
for s in S:
  if s[0] in I.keys():
    I[s[0]] += 1
for i in march:
  if I[i] < 1:
    I.pop(i)
K = list(I.keys())
ans = long(0)
for c in list(itertools.combinations(K, 3)):
    ans += I[c[0]]*I[c[1]]*I[c[2]]
print ans

Solution (Python):
import sys
import numpy as np
import itertools

N = int(sys.stdin.readline().strip())
dct = {}
dct["M"] = 0
dct["A"] = 0
dct["R"] = 0
dct["C"] = 0
dct["H"] = 0
char_list = ["M", "A", "R", "C", "H"]

for _ in range(N):
    name = sys.stdin.readline().strip()
    first = name[0]
    if first not in dct:
        continue
    dct[first] += 1

count = 0
for a, b, c in list(itertools.combinations(char_list, 3)):
    count += dct[a] * dct[b] * dct[c]
print(count)

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

Solution (Python):
N = int(input())
D = {"M":0, "A":0, "R":0, "C":0, "H":0}
for i in range(N):
    a = input()
    if a[0] in D:
        D[a[0]] += 1
L = [D["M"], D["A"], D["R"], D["C"], D["H"]]
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())
S=sorted(list(map(str, [input() for i in range(N)])))
MARCH=[0]*5
ans=0

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

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

Solution (Python):
N = int(input())
S = []
L = []
for i in range(N) :
    s = input()
    S.append(s[0])
m = S.count("M")
a = S.count("A")
r = S.count("R")
c = S.count("C")
h = S.count("H")
L.append(m)
L.append(a)
L.append(r)
L.append(c)
L.append(h)
L = sorted(L,reverse=True)
ans = 0
if len(list(set(S))) < 3 :
    print(0)
elif len(list(set(S))) == 3 :
    print(L[0]*L[1]*L[2])
elif len(list(set(S))) == 4 :
    print(L[0]*L[1]*L[2]+L[0]*L[1]*L[3]+L[0]*L[2]*L[3]
          +L[1]*L[2]*L[3])
else :
    print(L[0]*L[1]*L[2]+L[0]*L[1]*L[3]+L[0]*L[1]*L[4]+L[0]*L[2]*L[3]
          +L[0]*L[2]*L[4]+L[0]*L[3]*L[4]
          +L[1]*L[2]*L[3]+L[1]*L[2]*L[4]+L[1]*L[3]*L[4]
          +L[2]*L[3]*L[4])

Solution (Python):
from itertools import combinations

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

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

comb = (m, a, r, c, h)
ans = 0
for x, y, z in combinations(comb, 3):
    ans += x * y * z

print(ans)

Solution (Python):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
march = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for _ in range(n):
    s = lc()
    if s[0] in march.keys():
        march[s[0]] += 1
        
ans = 0
vals = list(march.values())
for i in range(5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            ans += vals[i]*vals[j]*vals[k]
            
print(ans)

Solution (Python):
import itertools
from collections import Counter
N = int(input())
src = [input() for i in range(N)]
ctr = Counter()
for s in src:
    ctr[s[0]] += 1

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

Solution (Python):
from itertools import combinations

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

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

count = 0
for i in combinations(march.keys(), 3):
    count += march[i[0]] * march[i[1]] * march[i[2]]

print(count)

Solution (Python):

import itertools

N = int(input())
S = []
match_char = ['M','A','R','C','H']

for i in range(N):
    S.append(input())

S_dict = {}
for c in match_char:
    S_dict[c] = 0

for Si in S:
    if Si[0] in match_char:
        S_dict[Si[0]] += 1

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

print(ans)

Solution (Python):

import collections
import itertools
N = int(input())
d = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
for i in range(N):
    s = input()
    if s[0] in d:
        d[s[0]] += 1

ans = 0
for i in itertools.combinations(['M', 'A', 'R', 'C', 'H'], 3):
    ans = ans + d[i[0]]*d[i[1]]*d[i[2]]

print(ans)

Solution (Python):
def head_clf(N, A):
    import itertools
    head = ['M', 'A', 'R', 'C', 'H']
    head_cnt = [0 for _ in range(5)]
    for _ in range(N):
        S = input()
        if S[0] in head:
            A.append(S)
    A = list(set(A))
    for a in A:
        ind = head.index(a[0])
        head_cnt[ind] += 1   
    com =  list(itertools.combinations(head_cnt,3))
    ans = 0
    for i in com:
        ans += i[0]*i[1]*i[2]
    return ans

def main():
    N = int(input())
    A = []
    print(head_clf(N, A))

if __name__ == '__main__':
    main()

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

def first_name(x):
    x = x[0]
    return x
w_first = list(map(first_name, w))
import collections
w_c=collections.Counter(w_first)
import itertools
from functools import reduce
march_list = ['M', 'A', 'R', 'C', 'H']
march_combinations = list(itertools.combinations(march_list,3))
ans = 0
for march_com in march_combinations:
    march_c = []
    for march in march_com:
        if not w_c.get(march) == None:
            march_c.append(w_c.get(march))
            ans_plus = reduce(lambda x, y: x * y, march_c)
    if len(march_c) == 3:
        ans += ans_plus
print(ans)

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

Solution (Python):
from itertools import combinations

N = int(input())
S = [input() for _ in range(N)]
init = {}
count = 0

for s in S:
    if s[0] in ["M", "A", "R", "C", "H"]:
        if s[0] not in init:
            init[s[0]] = 1
        else:
            init[s[0]] += 1

if len(init) < 3:
    print(0)
else:
    for comb in combinations(init.values(), 3):
        count += comb[0] * comb[1] * comb[2]

    print(count)

Solution (Python):
n = int(input())
countM=0
countA=0
countR=0
countC=0
countH=0
countL=[countM, countA, countR, countC, countH]
index=0
while index < n:
    nameL = list(input())
    if nameL[0] == "M":
        countL[0]+=1
    elif nameL[0] == "A":
        countL[1]+=1
    elif nameL[0] == "R":
        countL[2]+=1
    elif nameL[0] == "C":
        countL[3]+=1
    elif nameL[0] == "H":
        countL[4]+=1
    index+=1

LLL =[]
for count in countL:
    if count!=0:
        LLL.append(count)
if len(LLL) < 3:
    print(0)
else:
    if len(LLL) == 3:
        ans=1
        for l in LLL:
            ans*=l
    elif len(LLL) == 4:
        ans = LLL[0]*LLL[1]*LLL[2] + LLL[0]*LLL[1]*LLL[3]+ LLL[0]*LLL[2]*LLL[3] + LLL[1]*LLL[2]*LLL[3]
    else:
        ans = LLL[0]*LLL[1]*LLL[2] + LLL[0]*LLL[1]*LLL[3]+ LLL[0]*LLL[1]*LLL[4] + LLL[0]*LLL[2]*LLL[3] + LLL[0]*LLL[2]*LLL[4] + LLL[0]*LLL[3]*LLL[4] + LLL[1]*LLL[2]*LLL[3] + LLL[1]*LLL[2]*LLL[4] + LLL[1]*LLL[3]*LLL[4] + LLL[2]*LLL[3]*LLL[4]
    print(ans)

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

keys = ['M', 'A', 'R', 'C', 'H']
chars = dict(zip(keys, [0]*5))
for i in range(n):
    if s[i][0] in keys:
        chars[s[i][0]] += 1


ans = 0
for i in range(1<<5):
    if bin(i).count('1') != 3:
        continue
    num = 1
    for j in range(5):
        if i&1 == 1:
            num *= chars[keys[j]]
        i >>= 1
    ans += num
print(ans)

Solution (Python):
import itertools

n = int(input())
dict_ans = {}
for i in range(n):
    s = str(input())
    if s[0] in ["M","A","R","C","H"]:
        try:
            dict_ans[s[0]] += 1
        except KeyError:
            dict_ans[s[0]] = 1

if len(list(dict_ans.values())) < 3:
    ans = 0
else:
    list_ans = list(dict_ans.values())
    ans = 0
    for i,j,k in list(itertools.combinations(list_ans, 3)):
        ans += i*j*k
print(ans)

Solution (Python):
N=int(input())
dic={}

for _ in range(N):
    s = input()
    if dic.get(s[0],0)==0:
        dic[s[0]]=1
    else:
        dic[s[0]]+=1
ans=0

m='MARCH'
for i in range(5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            ans+=dic.get(m[i],0)*dic.get(m[j],0)*dic.get(m[k],0)
print(ans)

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

di = {'M': 0, 'A': 1, 'R': 2, 'C': 3, 'H': 4}
cnt = [0 for i in range(5)]

for i in range(n):
    c = input()[0]
    if c in di:
        cnt[di[c]] += 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())
march = [0, 0, 0, 0, 0]
for i in range(n):
    s = list(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
ans = 0
for i in range(3):
    for j in range(3 - i):
        for k in range(3-i-j):
            ans += march[i] * march[i + j + 1] * march[i + j + k + 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
    if s[0]=="A":
        a+=1
    if s[0]=="R":
        r+=1
    if s[0]=="C":
        c+=1
    if s[0]=="H":
        h+=1

l=[m,a,r,c,h]
ans=0

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

Solution (Python):
N = int(input())
S = [list(input()) for i in range(N)]
M = []
A = []
R = []
C = []
H = []
for j in range(N):
  if (S[j][0] == 'M'):
    M.append(S[j])
  elif (S[j][0] == 'A'):
    A.append(S[j])
  elif (S[j][0] == 'R'):
    R.append(S[j])
  elif (S[j][0] == 'C'):
    C.append(S[j])
  elif (S[j][0] == 'H'):
    H.append(S[j])
  else:
    None
print(len(M)*len(A)*len(R)+len(M)*len(A)*len(C)+len(M)*len(A)*len(H)+len(M)*len(R)*len(C)+len(M)*len(R)*len(H)+len(M)*len(C)*len(H)+len(A)*len(R)*len(C)+len(A)*len(R)*len(H)+len(R)*len(C)*len(H)+len(A)*len(C)*len(H))

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

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

n = int(input())
s = Counter([input()[0] for _ in range(n)])
m = []
for i in "MARCH":
    if i in s:
        m.append(s[i])
ans = 0
for a, b, c in combinations(m, 3):
    ans += a * b * c
print(ans)

Solution (Python):
from collections import Counter

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

ans = 0
cnt = [v for v in Counter(s).values()]
if len(cnt) == 3:
    ans = cnt[0] * cnt[1] * cnt[2]
elif len(cnt) == 4:
    for i in range(4):
        ans += cnt[0] * cnt[1] * cnt[2] * cnt[3] // cnt[i]
elif len(cnt) == 5:
    for i in range(4):
        for j in range(i+1, 5):
            ans += cnt[0] * cnt[1] * cnt[2] * cnt[3] * cnt[4] // (cnt[i] * cnt[j])

print(ans)

Solution (Python):
import itertools
N = int(input())
MARCH = [0, 0, 0, 0, 0]
final_ans = 0
for i in range(N):
    a = input()
    if a[0] =='M':
        MARCH[0] += 1
    elif a[0] =='A':
        MARCH[1] += 1
    elif a[0] =='R':
        MARCH[2] += 1
    elif a[0] =='C':
        MARCH[3] += 1
    elif a[0] =='H':
        MARCH[4] += 1

MARCH = list(itertools.combinations(MARCH,3))

for i in MARCH:
    final_ans += i[0]*i[1]*i[2]
print(final_ans)

Solution (Python):
import itertools
N = int(input())
M, A, R, C, H = 0, 0, 0, 0, 0
final_ans = 0
for i in range(N):
    a = input()
    if a[0] =='M':
        M += 1
    elif a[0] =='A':
        A += 1
    elif a[0] =='R':
        R += 1
    elif a[0] =='C':
        C += 1
    elif a[0] =='H':
        H += 1

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

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

Solution (Python):
n = int(input())
S = []
for i in range(n):
    S.append(input())
march = [0, 0, 0, 0, 0]
for i in S:
    
    if i[0] == "M":
        march[0] += 1
    if i[0] == "A":
        march[1] += 1
    if i[0] == "R":
        march[2] += 1
    if i[0] == "C":
        march[3] += 1
    if i[0] == "H":
        march[4] += 1
march.sort()
i = 0
while True:
    if i >= len(march):
        break
    if march[i] == 0:
        del march[i]
        i -= 1
    i += 1
ans = 0

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

Solution (Python):
N = int(input())
m = 0
a = 0
r = 0
c = 0
h = 0
counter = 0

for _ in range(N):
	s = input()[0]
	if s == 'M':
		m += 1
	elif s == 'A':
		a += 1
	elif s == 'R':
		r += 1
	elif s == 'C':
		c += 1
	elif s == 'H':
		h += 1

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

print(ans)

Solution (Python):
from itertools import combinations

N = int(input())

cnt = [0 for i in range(5)]
march = "MARCH"
for i in range(N):
    s = input()
    if s[0] in march:
        cnt[march.find(s[0])] += 1

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

Solution (Python):


from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

N = input()
A = [0, 0, 0, 0, 0]
for i in range(N):
    S = raw_input()
    if S[0] in 'MARCH':
        A['MARCH'.find(S[0])] += 1

ans = 0

for a, b, c in it.combinations(A, 3):
    ans += a * b * c

print ans

Solution (Python):
from itertools import combinations
from sys import stdin


ns = lambda: stdin.readline()
ni = lambda: int(stdin.readline())
na = lambda: list(map(int, stdin.readline().split()))

N = ni()

target = 'MARCH'
first = [0 for _ in range(5)]
for _ in range(N):
    s = ns()
    if s[0] in target:
        first[target.find(s[0])] += 1

res = 0
for c in combinations(first, 3):
    res += c[0]*c[1]*c[2]
    
print(res)

Solution (Python):
from itertools import combinations

N = int(input())

target = 'MARCH'
first = [0 for _ in range(5)]
for _ in range(N):
    s = input()
    if s[0] in target:
        first[target.find(s[0])] += 1

res = 0
for c in combinations(first, 3):
    res += c[0]*c[1]*c[2]
    
print(res)

Solution (Python):
from itertools import combinations as comb

N = int(input())

S = list("MARCH")
A = {}
for i in range(N):
    s = input()[0:1]
    if(s not in S):
        continue

    A[s] = A.get(s, 0) + 1

if(len(A) < 3):
    print(0)
else:
    ans = 0
    c = list(comb(list(A.values()), 3))
    for a1, a2, a3 in c:
        ans += a1 * a2 * a3
    
    print(ans)

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

Solution (Python):
import itertools
seq = ('M', 'A', 'R', 'C', 'H')
combs = list(itertools.combinations(seq, 3))
chr_dic = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}

n = int(input())
s = []
for _ in range(n):
  l = input()
  if l[0] in chr_dic:
    chr_dic[l[0]] += 1
  s.append(l)

ans = 0
for cmb in combs:
  if chr_dic[cmb[0]] > 0 and chr_dic[cmb[1]] > 0 and chr_dic[cmb[2]] > 0:
    ans += chr_dic[cmb[0]] * chr_dic[cmb[1]] * chr_dic[cmb[2]]
print(ans)

Solution (Python):

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

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


    lst =[0,0,0,0,0]
    for i in S:
        if i[0] == "M":
            lst[0]+=1
        if i[0] == "A":
            lst[1]+=1
        if i[0] == "R":
            lst[2]+=1
        if i[0] == "C":
            lst[3]+=1
        if i[0] == "H":
            lst[4]+=1

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

    print(ans)


if __name__ == "__main__":
        main()

Solution (Python):
from collections import defaultdict
from itertools import combinations
N = int(input())
counter = defaultdict(int)
for i in range(N):
    head = input()[0]
    if head not in ('M', 'A', 'R', 'C', 'H'):
        continue
    counter[head] += 1
if len(counter) < 3:
    print(0)
else:
    count = 0
    for v in combinations(counter.values(), 3):
        count += v[0] * v[1] * v[2]
    print(count)

Solution (Python):
march = ['M', 'A', 'R', 'C', 'H']
counter = [0, 0, 0, 0, 0]
N = int(raw_input())
for i in range(0, N):
	s = raw_input()
	for j in range(0, 5):
		if s[0] == march[j]:
			counter[j] = counter[j] + 1
ans = 0
for i in range(0, 5):
	for j in range(i+1, 5):
		for k in range(j+1, 5):
			ans = ans + counter[i] * counter[j] * counter[k]

print ans

Solution (Python):
n = int(input())
s = [input() for i 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

ans1 = march[0]*march[1]*(march[2]+march[3]+march[4])
ans2 = march[3]*march[4]*(march[0]+march[1]+march[2])
ans3 = (march[0]+march[1])*march[2]*(march[3]+march[4])

print(ans1+ans2+ans3)

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N = int(input())
march = ['M','A','R','C','H']
nums = [0]*5

for _ in range(N):
	s = input()
	if s[0] in march:
		nums[march.index(s[0])] +=1

def next_com(bit):
	x = bit & -bit
	y = bit + x
	return (((bit & ~y) // x) >> 1) | y

n,k = 5,3
bit = (1<<k)-1
ans = 0
while bit < (1<<n):
	tmp = 1
	for i in range(5):
		if (bit>>i) & 1:
			tmp *= nums[i]
	ans += tmp
	bit = next_com(bit)

print(ans)

Solution (Python):
from collections import Counter
import itertools
N = int(input())
S = []
for i in range(N):
    tmp = list(input())
    S.append(tmp[0])
Ini = Counter(S)
seq = ['M','A','R','C','H']
COMB = list(itertools.combinations(seq, 3))
sum = 0
for i in range(len(COMB)):
    sum += Ini[str(COMB[i][0])] * Ini[str(COMB[i][1])] * Ini[str(COMB[i][2])]
print(sum)

Solution (Python):
import itertools

N = int(input())

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

MARCH = []
initials = []

for _ in range(N):
    s = input()
    initials.append(s[0])

for x in march:
    MARCH.append(initials.count(x))

L = [i for i in range(5)]
C = itertools.combinations(L, 3)

ans = 0

for c in C:
    ans += MARCH[c[0]] * MARCH[c[1]] * MARCH[c[2]]

print(ans)

Solution (Python):
n = int(input())
march = [0]*5
for _ in range(n):
    s = input()
    for i in range(5):
        if 'MARCH'[i] == s[0]:
            march[i] += 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):
from itertools import combinations
from collections import Counter
N = int(input())
ctr = Counter([input()[0] for i in range(N)])

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

Solution (Python):
from collections import Counter
from itertools import combinations
N = int(input())
S = [input()[0]  for i in range(N)]
dic ={'M':S.count('M'),'A':S.count('A'),'R':S.count('R'),'C':S.count('C'),'H':S.count('H')}
cnt=0
for i,j,k in combinations(dic.values(),3):
    cnt+=i*j*k
print(cnt)

Solution (Python):
def combination_list(data, r):
    if r == 0 or r > len(data):
        return []

    result = []
    _combination_list(data, r, 0, [], result)
    return result


def _combination_list(data, r, start, progress, result):
    if r == 0:
        result.append(progress)
        return

    for i in range(start, len(data)):
        _combination_list(data, r - 1, i + 1, progress + [data[i]], result)


n = int(input())

names = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for _ in range(n):
    name = str(input())[0]
    if name in names.keys():
        names[name] += 1



l = list(names.values())


combis = combination_list(l, 3)

count = 0
for combi in combis:
    val = 1
    for i in combi:
        val *= i

    count += val

print(count)