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())
d = [0] * 5
for i in range(n):
    s = input()
    if s[0] == "M":
        d[0] += 1
    if s[0] == "A":
        d[1] += 1
    if s[0] == "R":
        d[2] += 1
    if s[0] == "C":
        d[3] += 1
    if s[0] == "H":
        d[4] += 1
import itertools
res = 0
for x  in list(itertools.combinations([0,1,2,3,4], 3)):
    res += d[x[0]] * d[x[1]] * d[x[2]]
print(res)

Solution (Python):
import itertools as ite
N=int(input())
C=[0]*6
J="MARCH"
for i in range(N):
    C[J.find(input()[0])]+=1
ans=0
for i,j,k in list(ite.combinations(range(5),3)):
    ans+=C[i]*C[j]*C[k]
print(ans)

Solution (Python):
N=int(input())
C=[0,0,0,0,0,0]
J="MARCH"
for i in range(N):
    C[J.find(input()[0])]+=1
ans=0
ans+=C[0]*C[1]*C[2]
ans+=C[0]*C[1]*C[3]
ans+=C[0]*C[1]*C[4]
ans+=C[0]*C[2]*C[3]
ans+=C[0]*C[2]*C[4]
ans+=C[0]*C[3]*C[4]
ans+=C[1]*C[2]*C[3]
ans+=C[1]*C[2]*C[4]
ans+=C[1]*C[3]*C[4]
ans+=C[2]*C[3]*C[4]
print(ans)

Solution (Python):
n = int(input())
m = 0
a = 0
r = 0
c = 0
h = 0
cnt = 0
for i in range(n):
  p = input()
  if p[0] == "M":
    m += 1
  if p[0] == "A":
    a += 1
  if p[0] == "R":
    r += 1
  if p[0] == "C":
    c += 1
  if p[0] == "H":
    h += 1
if m > 0:
  cnt += 1
if a > 0:
  cnt += 1
if r > 0:
  cnt += 1
if c > 0:
  cnt += 1
if h > 0:
  cnt += 1
  
if cnt < 3:
  print(0)
else:
  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()[0] for _ in range(n)]

from collections import Counter

cnt = Counter(s)

from itertools import combinations

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

lss = [cnt["M"],cnt["A"],cnt["R"],cnt["C"],cnt["H"]]

ans = 0
for i in list(combinations(ls,3)):
    ans += lss[i[0]]*lss[i[1]]*lss[i[2]]
print(ans)

Solution (Python):
n=int(input())
m=0
a=0
r=0
c=0
h=0
for i in range(n):
  w=input()
  if w[0]=="M":
    m+=1
  elif w[0]=="A":
    a+=1
  elif w[0]=="R":
    r+=1
  elif w[0]=="C":
    c+=1
  elif w[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())
s = []

for i in range(n):
    s.append(input())

l = [s[i][0] for i in range(n)]

m = l.count('M')
a = l.count('A')
r = l.count('R')
c = l.count('C')
h = l.count('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):
l = input().split()
N = int(l[0])
S = []
for i in range(N):
    l = input().split()
    S.append(l[0])



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

for s in S:
    h = s[0]
    if h in names:
        names[h] += 1

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



ans = 0

for i in range(5):
    for j in range(i + 1, 5):
        for k in range(j + 1, 5):
            
            
            ni = names[table[i]]
            nj = names[table[j]]
            nk = names[table[k]]
            if ni == 0 or nj == 0 or nk == 0:
                continue
            ans += ni*nj*nk

print(ans)

Solution (Python):



import sys
import itertools

input = sys.stdin.readline

def main():
    N = int(input())
    S = [input().strip() for _ in range(N)]

    cnt = [0 for _ in range(5)]
    for s in S:
        if s[0] == "M":
            cnt[0] += 1
        if s[0] == "A":
            cnt[1] += 1
        if s[0] == "R":
            cnt[2] += 1
        if s[0] == "C":
            cnt[3] += 1
        if s[0] == "H":
            cnt[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]

    n = 0
    for i in range(10):
        n += cnt[p[i]] * cnt[q[i]] * cnt[r[i]]
    print(n)

main()

Solution (Python):
import itertools
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
K = list(itertools.combinations(L,3))
ans = 0
for i in range(len(K)):
  ans += K[i][0]*K[i][1]*K[i][2]
print(ans)

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


n = int(input())
lst_s = [input()[0] for _ in range(n)]
lst_march = [s for s in lst_s if s in "MARCH"]
cnt_s = Counter(lst_march)
lst_num = list(cnt_s.values())
cmb_num = list(combinations(lst_num, 3))
ans = sum(c[0] * c[1] * c[2] for c in cmb_num)
print(ans)

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


n = int(input())
lst_s = [input()[0] for _ in range(n)]
lst_march = [s for s in lst_s if s in "MARCH"]
cnt_s = Counter(lst_march)
lst_num = list(cnt_s.values())
cmb_num = list(combinations(lst_num, 3))
ans = sum(c[0] * c[1] * c[2] for c in cmb_num)
print(ans)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  la=['M','A','R','C','H']
  lb=[0]*5

  for _ in range(n):
    s=S()
    if la.count(s[0])>0:
      lb[la.index(s[0])]+=1

  sm=0

  for x in list(itertools.combinations(la,3)):
    sm+=lb[la.index(x[0])]*lb[la.index(x[1])]*lb[la.index(x[2])]

  return sm

print(main())

Solution (Python):
from functools import reduce
import math
import collections
import itertools
def main():
    
    
    
    

    
    
    
    
    
    

    
    

    
    
    
    
    
    
    
    
    
    INF = float("inf")

    
    MOD = 10**9+7
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
    
    
    
    N = int(input())
    d = collections.defaultdict(int)
    for _ in range(N):
        S = input()
        d[S[0]] += 1
    seq = ('M','A','R','C','H')
    ans = 0
    for i in list(itertools.combinations(seq,3)):
        ans += d[i[0]] * d[i[1]] * d[i[2]]
    print(ans)
    
if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
name = [input() for i in range(N)]
dic = {"M":0,"A":0,"R":0,"C":0,"H":0}
for i in name :
    if i[0] in dic.keys():
        dic[i[0]] += 1
    else : pass
ans = 0

head_name = ["M","A","R","C","H"]
for i in head_name:
    for j in head_name:
        for k in head_name:
            if i != j and j!= k and i != k :
                ans += dic[i]*dic[j]*dic[k]

print("{}".format(ans//(3*2*1)))

Solution (Python):
n=int(input())
m,a,r,c,h=0,0,0,0,0
for i in range(n):
  name=input()
  init=name[0]
  if init =="M":
    m+=1
  elif init =="A":
    a+=1
  elif init =="R":
    r+=1
  elif init =="C":
    c+=1
  elif init =="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):
from itertools import combinations

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

res = 0
for value in combinations(cnt_dict.values(), 3):
    res += (value[0]*value[1]*value[2])

print(res)

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

S = [0] * N

S_dic = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
for i in range(N):
    S[i] = str(input())
    if S[i][0] in S_dic.keys():
        S_dic[S[i][0]] += 1

zero_count = 0
for value in S_dic.values():
    if value == 0:
        zero_count += 1
if zero_count >= 3:
    print(0)
    sys.exit()

total = 0
for item in list(combinations(S_dic.keys(), 3)):
    total += (S_dic[item[0]] * S_dic[item[1]] * S_dic[item[2]])
print(total)

Solution (Python):
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
    elif s[0] == 'A':
        a += 1
    elif s[0] == 'R':
        r += 1
    elif s[0] == 'C':
        c += 1
    elif s[0] == 'H':
        h += 1

if m == 0 and a == 0 and r == 0 and c == 0 and h == 0:
    print(0)
    exit()

ans = 0
l = [m, a, r, c, h]
for i in range(len(l)):
    for j in range(i+1, len(l)):
        for k in range(j+1, len(l)):
            ans += (l[i] * l[j] * l[k])
print(ans)

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

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

Solution (Python):

import sys
input = sys.stdin.readline

from itertools import combinations

n = int(input())
lst = [input().rstrip() for _ in range(n)]
cond = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for i in lst:
    if i[0] in "MARCH":
        cond[i[0]] += 1
ans = 0
for x, y, z in combinations("MARCH", 3):
    ans += cond[x] * cond[y] * cond[z]
print(ans)

Solution (Python):
import sys
from collections import Counter as ct
import itertools
fastinput = sys.stdin.readline
N=int(input())
name=[fastinput() for i in range(N)]
MARCH=[sum([n.startswith(k) for n in name]) for k in ("MARCH")]
ans=0
for a,b,c in itertools.combinations([1,2,3,4,0],3):
    ans += MARCH[a]*MARCH[b]*MARCH[c]
print(ans)

Solution (Python):

import sys
from collections import defaultdict


def solve(N: int, S: "List[str]"):
    ndic = defaultdict(int)

    for s in S:
        ndic[s[0]] += 1

    M = [m for m in "MARCH" if ndic[m] > 0]

    res = 0
    for i in range(len(M)-2):
        for j in range(i+1,len(M)-1):
            for k in range(j+1,len(M)):
                res += ndic[M[i]] * ndic[M[j]] * ndic[M[k]] 
    print(res)





def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    S = [ next(tokens) for _ in range(N) ]  
    solve(N, S)

if __name__ == '__main__':
    main()

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

N = int(input())
Ns = defaultdict(int)
for _ in range(N):
    n = input()
    if n[0] in 'MARCH':
        Ns[n[0]] += 1

if len(Ns.keys()) < 3:
    print(0)
    quit()

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

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

Solution (Python):
n=int(input())
s=[input() for i in range(n)]
m,a,r,c,h=0,0,0,0,0
for i in range(len(s)):
    x=s[i][0]
    if x=="M":m+=1
    elif x=="A":a+=1
    elif x=="R":r+=1
    elif x=="C":c+=1
    elif x=="H":h+=1
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 _ in range(N)]

I = ["M", "A", "R", "C", "H"]
L = [0] * 5

for i in S:
  for j in range(5):
    if i[0] == I[j]:
      L[j] += 1

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

print(ans)

Solution (Python):
import itertools
n = int(input())
m = []
a = []
r = []
c = []
h = []
for i in range(n):
    t = input()
    if t[0] == 'M':
        m.append(t)
    elif t[0] == 'A':
        a.append(t)
    elif t[0] == 'R':
        r.append(t)
    elif t[0] == 'C':
        c.append(t)
    elif t[0] == 'H':
        h.append(t)
seq = (len(m), len(a), len(r), len(c), len(h))
t3 = list(itertools.combinations(seq, 3))
out = 0
for j in t3:
    out += j[0]*j[1]*j[2]
print(out)

Solution (Python):
import itertools
combi = itertools.combinations([0,1,2,3,4], 3)
n = int(input())
num = [0,0,0,0,0]
count = 0

for _ in range(n):
    tmp = input()
    if tmp[0] =="M":
        num[0] +=1
    elif tmp[0] == "A":
        num[1] += 1
    elif tmp[0] == "R":
        num[2] += 1
    elif tmp[0] == "C":
        num[3] += 1
    elif tmp[0] == "H":
        num[4] += 1
    else:
        continue

for i in combi:
    count += num[list(i)[0]] * num[list(i)[1]] * num[list(i)[2]]
print(count)

Solution (Python):
import itertools

def marchcount(a):
	if a == "M":
		march_list[0] += 1
	elif a == "A":
		march_list[1] += 1
	elif a == "R":
		march_list[2] += 1
	elif a == "C":
		march_list[3] += 1
	elif a == "H":
		march_list[4] += 1
	return


n = int(input())
march_list = [0 for i in range(5)] 
for i in range(n):
	marchcount(input()[0])

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

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

N = int(input())
S = [input()[0] for _ in range(N)]
counts = Counter([c for c in S if c in "MARCH"])
ans = 0
if counts:
    for c in combinations("MARCH", 3):
        ans += counts[c[0]] * counts[c[1]] * counts[c[2]]
print(ans)

Solution (Python):
import itertools as ite

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

ans=0
for i in list(ite.combinations(range(5),3)):
    pattern=1
    for j in i:
        pattern*=count[j]
    ans+=pattern
print(ans)

Solution (Python):
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
    elif s[0] == 'A':
        a += 1
    elif s[0] == 'R':
        r += 1
    elif s[0] == 'C':
        c += 1
    elif s[0] == 'H':
        h += 1

if m == 0 and a == 0 and r == 0 and c == 0 and h == 0:
    print(0)
    exit()

ans = 0
l = [m, a, r, c, h]
for i in range(len(l)):
    for j in range(i+1, len(l)):
        for k in range(j+1, len(l)):
            ans += (l[i] * l[j] * l[k])
print(ans)

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

s = "MARCH"
counter_arr = [0] * 5

for i in range(N):
    tmp = input()
    for j in range(len(s)):
        if tmp[0] == s[j]:
            counter_arr[j] += 1
            break

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

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

m_arr = []
a_arr = []
r_arr = []
c_arr = []
h_arr = []

for i in range(N):
    tmp = input()
    if tmp[0] == 'M':
        m_arr.append(tmp)
    elif tmp[0] == 'A':
        a_arr.append(tmp)
    elif tmp[0] == 'R':
        r_arr.append(tmp)
    elif tmp[0] == 'C':
        c_arr.append(tmp)
    elif tmp[0] == 'H':
        h_arr.append(tmp)
ans = 0

ans += len(m_arr) * len(a_arr) * len(r_arr)
ans += len(m_arr) * len(a_arr) * len(c_arr)
ans += len(m_arr) * len(a_arr) * len(h_arr)
ans += len(m_arr) * len(r_arr) * len(c_arr)
ans += len(m_arr) * len(r_arr) * len(h_arr)
ans += len(m_arr) * len(c_arr) * len(h_arr)
ans += len(a_arr) * len(r_arr) * len(c_arr)
ans += len(a_arr) * len(r_arr) * len(h_arr)
ans += len(a_arr) * len(c_arr) * len(h_arr)
ans += len(r_arr) * len(c_arr) * len(h_arr)
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

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):
marchlist = ['M', 'A', 'R', 'C', 'H']
N = int(input())
namelist = [[], [], [], [], []]
for i in range(0, N):
	s = input()
	for j in range(0, 5):
		if s[0] == marchlist[j]:
			namelist[j].append(s)
sum = 0
for i in range(0, 3):
	for j in range(i+1, 4):
		for k in range(j+1, 5):
			sum += len(namelist[i])*len(namelist[j])*len(namelist[k])
print(sum)

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

for i in range(N):
    S = list(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

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
from collections import Counter

n = int(input())
S = Counter()
for i in range(n):
  S[input()[0]] +=  1 
  
print(sum([S[a]*S[b]*S[c] for a, b, c in combinations("MARCH", 3)]))

Solution (Python):
N = int(input())
lst = []
for _ in range(N):
    lst += str(input())[:1]







lst2 = []
for i in 'MARCH':
    lst2 += [lst.count(i)]


ans = 0
for i in range(5):
    for j in range(5):
        for k in range(5):
            if i < j and j < k:
                ans += lst2[i] * lst2[j] * lst2[k]

print (ans)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  ml=[]
  al=[]
  rl=[]
  cl=[]
  hl=[]

  n=I()
  for _ in range(n):
    s=S()
    if s[0]=='M':
      ml.append(s)
    elif s[0]=='A':
      al.append(s)
    elif s[0]=='R':
      rl.append(s)
    elif s[0]=='C':
      cl.append(s)
    elif s[0]=='H':
      hl.append(s)

  l=[len(ml),len(al),len(rl),len(cl),len(hl)]
  sm=0

  for i in range(2):
    for j in range(2):
      for k in range(2):
        for m in range(2):
          for n in range(2):
            lx=[i,j,k,m,n]
            if lx.count(1)==3:
              _s=1
              for x in range(len(lx)):
                if lx[x]==1:
                  _s*=l[x]
              sm+=_s

  return sm

print(main())

Solution (Python):
from itertools import combinations

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

Solution (Python):
num = int(input())
m=0
a=0
r=0
c=0
h=0
for _ in range(num):
  w = input()
  if w[0] == "M":
    m = m+1  
  elif w[0] == "A":
    a = a+1    
  elif w[0] == "R":
    r = r+1
  elif w[0] == "C":
    c = c+1
  elif w[0] == "H":
    h = h+1
  else:
    None
k = 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(k)

Solution (Python):
N=int(input())
from collections import defaultdict
data=defaultdict(int)
for i in range(N):
    s=input()
    data[s[0]]+=1
S="MARCH"
ans=0
for x in range(3):
    for y in range(x+1,4):
        for z in range(y+1,5):
            ans+=data[S[x]]*data[S[y]]*data[S[z]]
print(ans)

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

ans_list = [0 for i in range(5)]
carList = ['M', 'A', 'R', 'C', 'H']
for s in S:
    for i, c in enumerate(carList):
        if s[0] == c:
            ans_list[i] += 1

ans_list = [a for a in ans_list if a != 0]
ans = 1
for i, v in enumerate(ans_list):
    ans *= v

if len(ans_list) < 3:
    print(0)
elif len(ans_list) == 3:
    print(ans_list[0]*ans_list[1]*ans_list[2])
elif len(ans_list) == 4:
    tmp = 0
    for i, v in enumerate(ans_list):
        tmp += ans // v
    print(tmp)
else:
    tmp = 0
    for i in range(5):
        for j in range(5):
            if i != j:
                tmp += ans // (ans_list[i]*ans_list[j])
    print(tmp//2)

Solution (Python):
from math import factorial
import itertools
N = int(input())
ML = 0
AL = 0
RL = 0
CL = 0
HL = 0
for i in range(N):
  x = input()[0]
  if x == 'M':
    ML += 1
  elif x == 'A':
    AL += 1
  elif x == 'R':
    RL += 1
  elif x == 'C':
    CL += 1
  elif x == 'H':
    HL += 1

num = 0

for x in itertools.combinations([('M',ML),('A',AL),('R',RL),('C',CL),('H',HL)],3):
  X = x[0][1]
  Y = x[1][1]
  Z = x[2][1]
  num += X*Y*Z
print(num)

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

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

m = {}

for v in L:
    if m.get(v[0]) == None:
        m[v[0]] = 0
    m[v[0]] += 1
    
l = [v for v in m.items() if v[0] in list("MARCH")]
    
ans = 0
for v in itertools.combinations(l, 3):
    ans += v[0][1] * v[1][1] * v[2][1]
    
print(ans)

Solution (Python):
from itertools import combinations
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
a=['M','A','R','C','H']
s=combinations(a,3)
cnt=0
for x in s:
     cnt+=d[x[0]]*d[x[1]]*d[x[2]]
print(cnt)

Solution (Python):
from itertools import combinations
 
n = int(input())
 
count = {x:0 for x in "MARCH"}
 
for _ in range(n):
  s = input()[0]
  if s in count:
    count[s] += 1
 
sum_count = 0
for a, b, c in combinations("MARCH", 3):
  sum_count += count[a] * count[b] * count[c]
 
print(sum_count)

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

count={}
for i in range(N):
    c = input()[0]
    count[c] = count.get(c, 0)+1
s = 0
for a,b,c in itertools.combinations("MARCH", 3):
    s += count.get(a,0)*count.get(b,0)*count.get(c,0)
print(s)

Solution (Python):
N=int(input())
S=list(input()[0] for _ 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+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())
S = [input() for _ in range(N)]
M,A,R,C,H = 0,0,0,0,0
ans = 0
for s in S:
    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

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

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

for i in range(5):
    for j in range(5):
        for k in range(5):
            if i<j<k:
                ans+=c[i]*c[j]*c[k]
print(ans)

Solution (Python):
from itertools import combinations

N = int(input())
S = [input() for _ in range(N)]
MARCH = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for s in S:
    for m in MARCH:
        if s[0] == m:
            MARCH[m] += 1
ans = 0
for i, j, k in combinations(MARCH, 3):
    ans += MARCH[i] * MARCH[j] * MARCH[k]
print(ans)

Solution (Python):

import sys


def solve(N: int, S: "List[str]"):
    count = [0] * 5
    for s in S:
        if s[0] in 'MARCH':
            idx = 'MARCH'.find(s[0])
            count[idx] += 1
    ret = 0
    for i1 in range(5):
        for i2 in range(i1 + 1, 5):
            for i3 in range(i2 + 1, 5):
                ret += count[i1] * count[i2] * count[i3]
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    S = [ next(tokens) for _ in range(N) ]  
    solve(N, S)

if __name__ == '__main__':
    main()

Solution (Python):

from collections import defaultdict
from math import factorial
import itertools



def main():
    num = int(input())
    data = defaultdict(int)
    for i in range(num):
        a = input()[0]
        if a in ['M', 'A', 'R', 'C', 'H']:
            data[a] += 1

    ans = 0
    if len(data) >= 3:
        for now_data in list(itertools.combinations(data.values(),3)):
            ans += now_data[0] * now_data[1] * now_data[2]
    print(ans)




if __name__ == '__main__':
    main()

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

N = int(input())
cnt = Counter([input()[0] for _ in range(N)])
ans = sum(cnt[i] * cnt[j] * cnt[k] for i, j, k in combinations('MARCH', 3))
print(ans)

Solution (Python):
from itertools import combinations

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

cnt = [sum(v[0] == c for v in s) for c in 'MARCH']
ans = sum(cnt[i] * cnt[j] * cnt[k] for i, j, k in combinations(range(5), 3))
print(ans)

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

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

for s in S:
    if s[0] in initial_dict:
        initial_dict[s[0]] += 1

keys = list(initial_dict.keys())
ans = 0
for i in range(5):
    for j in range(i+1, 5):
        for k in range(j+1, 5):
            ans += initial_dict[keys[i]] * initial_dict[keys[j]] * initial_dict[keys[k]]

print(ans)

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

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

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

for i in l:
    if i[0] == 'M':
        m.append(i)
    if i[0] == 'A':
        a.append(i)
    if i[0] == 'R':
        r.append(i)
    if i[0] == 'C':
        c.append(i)
    if i[0] == 'H':
        h.append(i)
        
m = len(m)
a = len(a)
r = len(r)
c = len(c)
h = len(h)

cnt = 0

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

print(cnt)

Solution (Python):
N=int(input())
S=[input() for i in range(N)]
c=[0,0,0,0,0]
for i in S:
    if i[0]=='M':
        c[0]+=1
    elif i[0]=='A':
        c[1]+=1
    elif i[0]=='R':
        c[2]+=1
    elif i[0]=='C':
        c[3]+=1
    elif i[0]=='H':
        c[4]+=1
ans=0
ans+=c[0]*(c[1]*(c[2]+c[3]+c[4])+c[2]*(c[3]+c[4])+c[3]*c[4])
ans+=c[1]*(c[2]*(c[3]+c[4])+c[3]*c[4])
ans+=c[2]*c[3]*c[4]
print(ans)

Solution (Python):
import itertools
n=int(input())
dic={'M':0,'A':0,'R':0,'C':0,'H':0}
l=dic.keys()
for _ in range(n):
	s=input()
	if s[0] in l:dic[s[0]]+=1
l=[x for x in dic.values() if x>0]
if len(l)<3:print(0)
else:
	ans=0
	for t in itertools.combinations(range(len(l)),3):
		k=1
		for i in t:
			k*=l[i]
		ans+=k
	print(ans)

Solution (Python):
from itertools import combinations
from collections import Counter
N = int(input())
s = [input()[0] for i in range(N)]
cnt = {k:v for k,v in Counter(s).items()}
ans = 0
for x,y,z in [c for c in combinations('MARCH',3)]:
    try:
        ans += cnt[x]*cnt[y]*cnt[z]
    except:
        pass
print(ans)

Solution (Python):


from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


class UnionFind:

    def __init__(self, n):
        self.parent = [i for i in range(n)]

    def root(self, i):
        if self.parent[i] == i:
            return i
        self.parent[i] = self.root(self.parent[i])
        return self.parent[i]

    def unite(self, i, j):
        rooti = self.root(i)
        rootj = self.root(j)
        if rooti == rootj:
            return
        if rooti < rootj:
            self.parent[rootj] = rooti
        else:
            self.parent[rooti] = rootj

    def same(self, i, j):
        return self.root(i) == self.root(j)





def main():
    n = intin()
    slist = [input() for _ in range(n)]

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

    for s in slist:
        if s[0] in count:
            count[s[0]] += 1

    patterns = [
        ['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'],
    ]

    ans = 0

    for p in patterns:
        ans += count[p[0]] * count[p[1]] * count[p[2]]

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
S=[]
M=[]
A=[]
R=[]
C=[]
H=[]
for s in range(N):
    name = input()
    S.append(name)
for s in S:
    first=s[0]
    if first == "M":
        M.append(s)
    if first == "A":
        A.append(s)
    if first == "R":
        R.append(s)
    if first == "C":
        C.append(s)
    if first == "H":
        H.append(s)
m=len(M)
a=len(A)
r=len(R)
c=len(C)
h=len(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)