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())
dic = {}
list1 = ['M','A','R','C','H']
list2 = [0,0,0,0,0]
for i in range(N):
  s = list(input())
  s = s[0]
  for j in range(5):
   if(s == list1[j]):
    list2[j] += 1

a,b,c,d,e = list2[0],list2[1],list2[2],list2[3],list2[4]
ans = a*b*c + a*b*d + a*b*e + a*c*d + a*c*e + a*d*e
ans += b*c*d + b*c*e + b*d*e 
ans += c*d*e
print(ans)

Solution (Python):
from itertools import*;s,*_=zip(*open(0));print(sum(p*q*r for p,q,r in combinations(map(s.count,'MARCH'),3)))

Solution (Python):
import itertools
n = int(input())
L = [[]for i in range(5)]
for i in range(n):
    s = str(input())
    if s[0] == "M":
        L[0].append(s)
    elif s[0] == "A":
        L[1].append(s)
    elif s[0] == "R":
        L[2].append(s)
    elif s[0] == "C":
        L[3].append(s)
    elif s[0] == "H":
        L[4].append(s)
L = [ i for i in L if len(i) > 0]
ans = 0
for i in itertools.combinations(L, 3):
    ans += len(i[0])*len(i[1])*len(i[2])
print(ans)

Solution (Python):
import itertools
n = int(input())
M = []
A = []
R = []
C = []
H = []
for i in range(n):
    s = str(input())
    if s[0] == "M":
        M.append(s)
    elif s[0] == "A":
        A.append(s)
    elif s[0] == "R":
        R.append(s)
    elif s[0] == "C":
        C.append(s)
    elif s[0] == "H":
        H.append(s)
L = []
if len(M) > 0:
    L.append(M)
if len(A) > 0:
    L.append(A)
if len(R) > 0:
    L.append(R)
if len(C) > 0:
    L.append(C)
if len(H) > 0:
    L.append(H)
ans = 0
for i in itertools.combinations(L, 3):
    
    ans += len(i[0])*len(i[1])*len(i[2])

print(ans)

Solution (Python):
import itertools
n = int(input())
h_list = []
for i in range(n):
    h_list.append(input()[0])
MARCH = ['M', 'A', 'R', 'C', 'H']
b = []
for a in MARCH:
    b.append(h_list.count(a))
bc = itertools.combinations(b, 3)
count = 0
for v in bc:
    count += v[0] * v[1] * v[2]
print(count)

Solution (Python):
n = int(input())
march = [0] * 5
for i in range(n):
    s = input()
    if s[0] == "M":
        march[0] += 1
    elif s[0] == "A":
        march[1] += 1
    elif s[0] == "R":
        march[2] += 1
    elif s[0] == "C":
        march[3] += 1
    elif s[0] == "H":
        march[4] += 1
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]
res = 0
for i in range(10):
    res += march[P[i]] * march[Q[i]] * march[R[i]]
print(res)

Solution (Python):


import itertools

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

delete = []

for i in range(n):
    if s[i][0] == "M" or s[i][0] == "A" or s[i][0] == "R" or s[i][0] == "C" or s[i][0] == "H":
        pass
    else:
        delete.append(i)

diff = 0
for i in range(len(delete)):
    del s[delete[i] - diff]
    diff += 1

cand = [0,0,0,0,0]
for i in range(len(s)):
    if s[i][0] == "M":
        cand[0] += 1
    if s[i][0] == "A":
        cand[1] += 1
    if s[i][0] == "R":
        cand[2] += 1
    if s[i][0] == "C":
        cand[3] += 1
    if s[i][0] == "H":
        cand[4] += 1

ans = 0

for i in range(5):
    for j in range(5):
        if i == j:
            break
        for k in range(5):
            if i == k:
                break
            if j == k:
                break
            ans += int(cand[i] * cand[j] * cand[k])

print(ans)

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

from collections import Counter
c = Counter()
for S in Sn:
    c[S[0]] += 1

t = 0
d = ['M','A','R','C','H']
from itertools import combinations
for combi in combinations(d, 3):
    v = 1
    for k in combi:
        v *= c[k]
    t += v
print(t)

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

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

s = 0
for i in range(0, 5):
    for j in range(i + 1, 5):
        for k in range(j + 1, 5):
            s += c[march[i]] * c[march[j]] * c[march[k]]

print(s)

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

print(cnt)

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

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

for i in range(2):
	sum += count[i] * count[i+1] * count[i+3]
	sum += count[i] * count[i+2] * count[i+3]

for i in range(3):
		sum += count[0] * count[i+1] * count[4]
print(sum)

Solution (Python):
N = int(input())
march = 'MARCH'
l = [0] * len(march)
for i in range(N):
    S = input()
    for j in range(len(march)):
        if S[0] == march[j]:
            l[j] += 1


tmp = []
lenl = len(l)
for i in range(lenl):
    for j in range(i + 1, lenl):
        for k in range(j + 1, lenl):
           tmp.append(l[i]*l[j]*l[k])

print(sum(tmp))

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

N = int(input())
S = [input() for _ in range(N)]
MARCHcnt = [0]*5
ans = 0

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

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

print(ans)

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

counter = {}
for i in range(n):
  head = input()[0]
  if head not in counter:
    counter[head] = 1
  else:
    counter[head] += 1

char_num = 0
char_count = []
for c in "MARCH":
  if c in counter:
    char_num += 1
    char_count.append(counter[c])

ans = 0
if char_num < 3:
  print(0)
else:
  for a, b, c in itertools.combinations(char_count, 3):
    ans += a * b * c
  print(ans)

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

m, a, r, c, h = 0, 0, 0, 0, 0

for s in sn:
    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())
count = [0]*5
for i in range(n):
    s = input()
    if s[0] == "M":
        count[0] += 1
    if s[0] == "A":
        count[1] += 1
    if s[0] == "R":
        count[2] += 1
    if s[0] == "C":
        count[3] += 1
    if s[0] == "H":
        count[4] += 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())
stack=[0,0,0,0,0]
march=["M","A","R","C","H"]
for i in range(n):
  k=input()
  for j in range(5):
    if k[0]==march[j]:
      stack[j]+=1
      break
ans=0
for i in range(3):
  for j in range(i+1,4):
    for k in range(j+1,5):
      ans+=stack[i]*stack[j]*stack[k]
print(ans)

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


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

choices = combinations([x for x in s.keys() if x[0] in 'MARCH'], 3)

if not choices:
    print(0)
    exit()

ans = 0
for choice in choices:
    tmp = 1
    for key in choice:
        tmp *= s[key]
    ans += tmp

print(ans)

Solution (Python):
import itertools
N=int(input())
l=[]
for i in range(N):
    s=str(input())
    l.append(s[0])
m=0
a=0
r=0
c=0
h=0
for i in range(N):
    if l[i]=='M':
        m+=1
    elif l[i]=='A':
        a+=1
    elif l[i]=='R':
        r+=1
    elif l[i]=='C':
        c+=1
    elif l[i]=='H':
        h+=1
D=[0]*5
for i in range(5):
    D[0]=m
    D[1]=a
    D[2]=r
    D[3]=c
    D[4]=h

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

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

Solution (Python):
import collections
import itertools
n = int(input())
s = []
for _ in range(n):
    s.append(input())
s = [i[0] for i in s if i[0] in "MARCH"]
l = collections.Counter(s)
c = 0
for i,j,k in itertools.combinations(l.keys(), 3):
    c += l[i]*l[j]*l[k]
print(c)

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

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

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

D1 = [0,0,0,0,0,0,1,1,1,2]
D2 = [1,1,1,2,2,3,2,2,3,3]
D3 = [2,3,4,3,4,4,3,4,4,4]

ans = 0
for i in range(10):
    ans += A[D1[i]] * A[D2[i]] * A[D3[i]]

print(ans)

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

d = defaultdict(int)

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

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

counter = 0
for w in combinations(w, 3):
    counter += d[w[0]] * d[w[1]] * d[w[2]]

print(counter)

Solution (Python):
N = int(input())
S = [input()[0] for i in range(N)]
M = S.count("M")
A = S.count("A")
R = S.count("R")
C = S.count("C")
H = S.count("H")
print(M * (A * (R + C + H) + R * (C + H) + C * H) + A * (R * (C + H) + C * H) + R * C * H)

Solution (Python):
import itertools
seq = ('M', 'A', 'R', 'C', 'H')
li = list(itertools.combinations(seq, 3))
MARCH = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H':0}
N = int(input())
for i in range(N):
    top = input()[0]
    if top in 'MARCH':
        MARCH[top] += 1
ans = 0
for i in li:
    tmp = 1
    for j in i:
        tmp *= MARCH[j]
    ans += tmp
print(ans)

Solution (Python):
import collections
N=int(input())
S=[]
ans=-1
for i in range(N):
    s=input()
    if s[0] in 'MARCH':
        S.append(s[0])
L=list(collections.Counter(S).values())
if len(L)<3:
    ans=0
else:
    R=[L[i]*L[j]*L[k] for i in range(len(L)-2) for j in range(i+1,len(L)-1) for k in range(j+1,len(L))]
    ans=sum(R)
print(ans)

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

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






"""
countして、かけていく
"""
M, A, R, C, H  = 0,0,0,0,0

for s in S:
    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

l = [M,A,R,C,H]
result = 0
for i in range(len(l)-2):
    for j in range(i+1, len(l)-1):
        for k in range(j+1, len(l)):
            result += l[i]*l[j]*l[k]
print(result)

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

cnt = {}

for s in S:
  cnt[s[0]] = cnt.get(s[0], 0) +1

n = [cnt.get(x,0) for x in ['M','A','R','C','H']]

a = sum(n) **3 - 3*sum([v**2 for v in n])*sum(n) + 2*sum([v**3 for v in n])
print(a//6)

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

Solution (Python):
n = int(input())
s = [list(str(input())) for i in range(n)]
m,a,r,c,h = 0,0,0,0,0
for i in range(n):
    if s[i][0] == "M":
        m = m + 1
    elif s[i][0] == "A":
        a = a + 1
    elif s[i][0] == "R":
        r = r + 1
    elif s[i][0] == "C":
        c = c + 1
    elif s[i][0] == "H":
        h = h + 1

t = [m,a,r,c,h]
p = 0
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            p = p + t[i] * t[j] * t[k]

print(p)

Solution (Python):



import sys
 

Sn = {'M':0,'A':0,'R':0,'C':0,'H':0}
for i in range(int(input())):
  s = str(input())[0]
  if s in Sn:
    Sn[s] += 1

ans = 0
Sn = list(Sn.values())
for i in range(5):
  if Sn[i] == 0:
    continue
  for j in range(i+1,5):
    if Sn[j] == 0:
      continue
    for k in range(j+1,5):
      if Sn[k] == 0:
        continue
      ans += Sn[i]*Sn[j]*Sn[k]

print(ans)

Solution (Python):
import itertools
from collections import Counter
n=int(input())
S=[input()[0] for i in range(n)]
ls=["M","A","R","C","H"]
S=Counter([i for i in S if i in ls])
ans=0
for i,j,k in itertools.combinations(ls,3):
  ans+=S[i]*S[j]*S[k]
print(ans)

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

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)

L = [M,A,R,C,H]
L = list(map(len,L))
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):
MARCH = list("MARCH")
check = set(MARCH)
cand = [0] * 5
N = int(input())
for i in range(N):
    n = list(input())[0]
    for j in range(5):
        if n == MARCH[j]:
            cand[j] += 1

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

Solution (Python):
import itertools

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

member = {}
for m in ['M', 'A', 'R', 'C', 'H']:
    member[m] = len(list(filter(lambda x: x[0] == m, S)))



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

print(ans)

Solution (Python):
import sys

N=int(sys.stdin.readline().rstrip())
c={'M':0, 'A':0, 'R':0, 'C':0, 'H':0 }
for i in range(N):
    s=sys.stdin.readline().rstrip()
    try:
        c[s[0]] += 1
    except KeyError:
        c[s[0]] = 1
a='MARCH'
ans=0
for i1 in range(0,5):
    for i2 in range(i1+1,5):
        for i3 in range(i2+1,5):
            ans+=c[a[i1]]*c[a[i2]]*c[a[i3]]
print(ans)

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

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

cnt = [0,0,0,0,0]

for _ in range(n):
    s = input()
    for i in range(5):
        if s[0] == march[i]:
            cnt[i]+=1
            break

b = list(itertools.combinations(cnt,3))

res = 0
for l in b:
    res +=(l[0]*l[1]*l[2])
 
print(res)

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


def solve(string):
    n, *s = string.split()
    
    initial = "MARCH"
    num = [0 for _ in range(6)]
    for _s in s:
        i = initial.find(_s[0])
        num[i] += 1
    return str(sum([reduce(mul, n) for n in combinations(num[:5], 3)]))


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))

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


def solve(string):
    n, *s = string.split()
    
    initial = "MARCH"
    num = [0 for _ in enumerate(initial)]
    for _s in s:
        i = initial.find(_s[0])
        if i < 0:
            continue
        num[i] += 1
    return str(sum([reduce(mul, n) for n in combinations(num, 3)]))


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))

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


def solve(string):
    n, *s = string.split()
    num = [len([True for _s in s if _s[0] == _i]) for _i in "M A R C H".split()]
    num = [n for n in num if n > 0]
    return str(sum([reduce(mul, n) for n in combinations(num, 3)]))


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))

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


def solve(string):
    n, *s = string.split()
    num = [len([True for _s in s if _s[0] == _i]) for _i in "M A R C H".split()]
    return str(sum([reduce(mul, n) for n in combinations(num, 3)]))


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))

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


def solve(string):
    n, *s = string.split()
    num = [len([True for _s in s if _s[0] == _i]) for _i in "M A R C H".split()]
    ans = 0
    for n in combinations(num, 3):
        ans += reduce(mul, n)
    return str(ans)


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))

Solution (Python):
def solve(string):
    n, *s = string.split()
    num = [len([True for _s in s if _s[0] == _i]) for _i in "M A R C H".split()]
    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]
    return str(ans)


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n)+'\n'.join([input() for _ in range(n)])))

Solution (Python):
N = int(input())
s = 'MARCH'
c = [0] * 5
for i in range(N):
    S = input()
    for j in range(5):
        if S[0] == s[j]:
            c[j] += 1

ans = 0
for i in range(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):
from collections import defaultdict
N = int(input())
S = [input() for _ in range(N)]
d = defaultdict(list)
chars = ["M", "A", "R", "C", "H"]

for s in S:
    c = s[0]
    for cc in chars:
        if c == cc:
            d[c].append(s)
            break
len_list = []
for c in chars:
    l = d[c]
    len_list.append(len(l))

ans = 0
n_arr = [0, 0, 0, 0, 0]
for i in range(1, 32):
    n = i
    count = 0
    for j in range(0, 5):
        if n % 2 > 0:
            count += 1
            n_arr[j] = 1
        else:
            n_arr[j] = 0
        n = n // 2
    if count != 3:
        continue
    c = 1
    for j in range(0, 5):
        if n_arr[j] > 0:
            c *= len_list[j] * n_arr[j]
    ans += c
print(ans)

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

N = int(input())

ls = ['M', 'A', 'R', 'C', 'H']
d = defaultdict(int)
ans = 0

for i in range(N):
    a = input()
    if a[0] in ls:
        d[a[0]] += 1
        
if len(d) <= 2:
    print(0)
else:
    nl = []
    for j in d.values():
        nl.append(j)
    for x in list(combinations(nl, 3)):
        sum = 1
        for y in x:
            sum *= y
        ans += sum
    print(ans)

Solution (Python):
N=int(input())
chars=['M','A','R','C','H']
dict={}
for c in chars:
  dict[c]=0
  
ans=0
  
for i in range(N):
  s=input()
  if (s[0] in chars):
    dict[s[0]]+=1

L=list(dict.values())
    
for i in range(2**5):
  usedchars=[]
  for j in range(5):
    if i>>j&1==1:
      usedchars.append(L[j])
    
  if len(usedchars)==3:
    ans+=usedchars[0]*usedchars[1]*usedchars[2]

print(ans)

Solution (Python):
from collections import Counter
from itertools import combinations
march = list("MARCH")
march = dict(zip(march, march))
N = int(input())
S = [march.get(input()[0], -1) for _ in range(N)]
cnt = Counter(S)
ans = 0
for comb in combinations("MARCH", 3):
    tmp = 1
    for c in comb:
        tmp *= cnt[c]
    ans += tmp
print(ans)

Solution (Python):
n=int(input())
m=[]
a=[]
r=[]
c=[]
h=[]
for _ in range(n):
    x=input()
    if x[0]=="M":
        m.append(x)
    elif x[0]=="A":
        a.append(x)
    elif x[0]=="R":
        r.append(x)
    elif x[0]=="C":
        c.append(x)
    elif x[0]=="H":
        h.append(x)
l=[len(m),len(a),len(r),len(c),len(h)]
ans=0
for x in range(3):
    for y in range(x+1,4):
        for z in range(y+1,5):
            ans+=l[x]*l[y]*l[z]
print(ans)

Solution (Python):
one = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
n=int(input())
for i in range(n):
  c=input()[0]
  one[c] = one.get(c,0)+1
m,a,r,c,h=one['M'],one['A'],one['R'],one['C'],one['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())
S = ''.join([str(input())[0] for i in range(N)])
count = []
for char in 'MARCH':
    tmp = S.count(char)
    if tmp != 0:
        count.append(tmp)
ans = 0
for i in range(1<<len(count)):
    if bin(i).count('1') == 3:
        tmp = 1
        for j in range(len(count)):
            if i>>j & 1 == 1:
                tmp *= count[j]
        ans += tmp
print(ans)

Solution (Python):
N = int(input())
S = [str(input())[0] for i in range(N)]
S = ''.join(S)
count = []
for char in 'MARCH':
    tmp = S.count(char)
    if tmp != 0:
        count.append(tmp)
ans = 0
for i in range(1<<len(count)):
    if bin(i).count('1') == 3:
        tmp = 1
        for j in range(len(count)):
            if i>>j & 1 == 1:
                tmp *= count[j]
        ans += tmp
print(ans)

Solution (Python):
from itertools import combinations

MARCH = ['M', 'A', 'R', 'C', 'H']
counts = [0]*5
N = int(input())
for i in range(N):
    head = input()[0]
    if head in MARCH:
        counts[MARCH.index(head)] += 1
alist = [t for t in zip(MARCH, counts) if t[1] != 0]

if len(alist) > 2:
    ans = 0
    for combination in combinations(range(5), 3):
        i, j, k = combination
        ans += counts[i] * counts[j] * counts[k]
    print(ans)
else:
    print(0)

Solution (Python):
n = int(input())
S = [input() for i in range(n)]
a = 0
b = 0
c = 0
d = 0
e = 0
for s in S:
    if s[0]=='M':
        a += 1
    elif s[0]=='A':
        b += 1
    elif s[0]=='R':
        c += 1
    elif s[0]=='C':
        d += 1
    elif s[0]=='H':
        e += 1
print(a*b*c+a*b*d+a*b*e+b*c*d+b*c*e+c*d*e+a*c*d+a*c*e+a*d*e+b*d*e)

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

Solution (Python):


import itertools
import collections
import bisect

def main():
    N = int(input())
    A = {}
    for key in ['M', 'A', 'R', 'C', 'H']:
        A[key] = []
    for _ in range(N):
        a = input()
        if a[0] in ['M', 'A', 'R', 'C', 'H']:
            A[a[0]].append(a)

    
    ans = 0

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

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import itertools


def main():
    N = int(input())
    d = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
    for _ in range(N):
        S = input()
        if S[0] in d:
            d[S[0]] += 1
    print(sum(d[a] * d[b] * d[c]
              for a, b, c in itertools.combinations(d.keys(), 3)))


main()

Solution (Python):
import itertools


def main():
    N = int(input())
    d = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
    for _ in range(N):
        S = input()
        if S[0] in d:
            d[S[0]] += 1
    print(sum(d[a] * d[b] * d[c]
              for a, b, c in list(itertools.combinations(d.keys(), 3))))


main()

Solution (Python):
import itertools


def main():
    N = int(input())
    d = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
    for _ in range(N):
        S = input()
        if S[0] in d:
            d[S[0]] += 1
    ans = 0
    for a, b, c in list(itertools.combinations(d.keys(), 3)):
        ans += d[a] * d[b] * d[c]
    print(ans)


main()

Solution (Python):
from itertools import combinations

input = open(0).read

Sn = [i[0] for i in input().split() if i[0] in "MARCH"]
st = set(Sn)


def main():

    print(
        sum(x * y * z for x, y, z
            in combinations([Sn.count(s) for s in st], 3)))

    return


main()

Solution (Python):
from itertools import combinations

input = open(0).read

Sn = [i[0] for i in input().split() if i[0] in "MARCH"]


def main():

    print(
        sum(x * y * z for x, y, z
            in combinations([Sn.count(s) for s in "MARCH"], 3)))

    return


main()

Solution (Python):
input = open(0).read

N, *Sn = map(str, input().split())
N = int(N)


def main():
    M = {j for j in Sn if j[0] in "M"}
    A = {j for j in Sn if j[0] in "A"}
    R = {j for j in Sn if j[0] in "R"}
    C = {j for j in Sn if j[0] in "C"}
    H = {j for j in Sn if j[0] in "H"}

    m = len(M)
    a = len(A)
    r = len(R)
    c = len(C)
    h = len(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)

    return


main()

Solution (Python):
from itertools import combinations
n=int(input())
a=[input() for i in range(n)]
cnt=[0]*5
for ai in a:
    if ai[0]=='M':
        cnt[0]+=1
    if ai[0]=='A':
        cnt[1]+=1
    if ai[0]=='R':
        cnt[2]+=1
    if ai[0]=='C':
        cnt[3]+=1
    if ai[0]=='H':
        cnt[4]+=1
comb=combinations(cnt, 3)
ans=0
for c in comb:
    ans+=c[0]*c[1]*c[2]
print(ans)

Solution (Python):
N = int(input())
march = 'MARCH'
S = [0,0,0,0,0]
for i in range(N):
    s = input()
    for j in range(5):
        if s[0] == march[j]:
            S[j] += 1
ans = 0
for i in range(5):
    ans += S[0]*(S[1]*(S[2]+S[3]+S[4])+S[2]*(S[3]+S[4])+S[3]*S[4])
    S[0],S[1],S[2],S[3],S[4] = S[1],S[2],S[3],S[4],0

print(ans)

Solution (Python):
def march(N: int, S: list) -> int:
    d = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
    for s in S:
        k = ''
        if s.startswith('M'):
            k = 'M'
        elif s.startswith('A'):
            k = 'A'
        elif s.startswith('R'):
            k = 'R'
        elif s.startswith('C'):
            k = 'C'
        elif s.startswith('H'):
            k = 'H'
        else:
            continue
        d[k] += 1

    count = 0
    val = list(d.values())
    for i in range(5):
        for j in range(i + 1, 5):
            for k in range(j + 1, 5):
                count += val[i] * val[j] * val[k]

    return count


if __name__ == "__main__":
    N = int(input())
    S = [input() for _ in range(N)]
    ans = march(N, S)
    print(ans)

Solution (Python):
from collections import defaultdict
from itertools import combinations
march = ['M','A','R','C','H']
combi = combinations(march,3)
N = int(input())
dic = defaultdict(int)
for i in range(N):
    c = input()[0]
    if c in march:
        dic[c] += 1
ans = 0
for c1,c2,c3 in combi: ans += dic[c1]*dic[c2]*dic[c3]
print(ans)

Solution (Python):

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

cnt = [0]*5

for x in a:
    if x[0] == "M": cnt[0] += 1
    if x[0] == "A": cnt[1] += 1
    if x[0] == "R": cnt[2] += 1
    if x[0] == "C": cnt[3] += 1
    if x[0] == "H": cnt[4] += 1
    
count = 0
for i in range(3):
    for j in range(i+1, 4):
        for k in range(j+1,5):
            count += cnt[i]*cnt[j]*cnt[k]

print(count)

Solution (Python):
import collections
import itertools
N = int(input())
march = ['M','A','R','C','H'] 
lst = []
count = 0
for _ in range(N):
    s = input()
    if s[0] in march:
        lst.append(s[0])
        
c = collections.Counter(lst)  
lst2 = [ c[i] for i in march]
lst3 = list(itertools.combinations(lst2,3))
for l in lst3:
    count += l[0] * l[1] * l[2]
    
print(count)

Solution (Python):
import itertools
n = int(input())
s = [str(input()) for i in range(n)]
march = [0, 0, 0, 0, 0]
for i in range(n):
    if s[i].startswith("M"):
        march[0] += 1
    elif s[i].startswith("A"):
        march[1] += 1
    elif s[i].startswith("R"):
        march[2] += 1
    elif s[i].startswith("C"):
        march[3] += 1
    elif s[i].startswith("H"):
        march[4] += 1
match = list(itertools.combinations(march, 3))
ans = 0
for i in range(len(match)):
    ans += match[i][0] * match[i][1] * match[i][2]
print(ans)

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

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

Solution (Python):
import itertools
n=int(input())
m,a,r,c,h=[],[],[],[],[]
for i in range(n):
    s=input()
    start=s[0]
    if start=="M":
        m.append(s)
    elif start=="A":
        a.append(s)
    elif start=="R":
        r.append(s)
    elif start=="C":
        c.append(s)
    elif start=="H":
        h.append(s)
s=[]
if len(m)!=0:
    s.append(len(list(itertools.combinations(m,1))))
if len(a)!=0:
    s.append(len(list(itertools.combinations(a,1))))
if len(r)!=0:
    s.append(len(list(itertools.combinations(r,1))))
if len(c)!=0:
    s.append(len(list(itertools.combinations(c,1))))
if len(h)!=0:
    s.append(len(list(itertools.combinations(h,1))))
hoge=list(itertools.combinations(s,3))
num=len(hoge)
ans=0
for i in range(num):
    ans+=hoge[i][0]*hoge[i][1]*hoge[i][2]
print(ans)