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):
num = int(input())

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

P1 = [0 ,0 ,0 ,0 ,0 ,0 ,1 ,1 ,1 ,2]
P2 = [1 ,1 ,1 ,2 ,2 ,3 ,2 ,2 ,3 ,3]
P3 = [2 ,3 ,4 ,3 ,4 ,4 ,3 ,4 ,4 ,4]


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

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

sum = 0
for d in range(10):
    sum += D[P1[d]] * D[P2[d]] * D[P3[d]]

print(sum)

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

num = [0] * 5
for s in S:
    if s[0] == "M":
        num[0] += 1
    elif s[0] == "A":
        num[1] += 1
    elif s[0] == "R":
        num[2] += 1
    elif s[0] == "C":
        num[3] += 1
    elif s[0] == "H":
        num[4] += 1
non_zero = []
for n in num:
    if n != 0:
        non_zero.append(n)
if len(non_zero) < 3:
    print(0)
    exit()
ans = 0
for i in range(len(non_zero)):
    for j in range(i + 1, len(non_zero)):
        for k in range(j+1, len(non_zero)):
            ans += non_zero[i] * non_zero[j] * non_zero[k]
print(ans)

Solution (Python):
N=int(input())
dic={"M":0,"A":1,"R":2,"C":3,"H":4}
S=[0,0,0,0,0]

for i in range(N):
    si=str(input())
    if si[0] in dic:
        S[dic[si[0]]]+=1
result=S[0]*S[1]*S[2]+S[0]*S[1]*S[3]+S[0]*S[1]*S[4]+S[0]*S[2]*S[3]+S[0]*S[2]*S[4]+S[0]*S[3]*S[4]+\
    S[1]*S[2]*S[3]+S[1]*S[2]*S[4]+S[1]*S[3]*S[4]+S[2]*S[3]*S[4]

print(result)

Solution (Python):
N = int(input())
S = [input() for i in range(N)]
MARCH = ['M', 'A', 'R', 'C', 'H']
p = {i:0 for i in MARCH}

for i in range(N):
    if S[i][0] in MARCH:
        p[S[i][0]] += 1

from itertools import combinations
ans = 0
for t in combinations(MARCH, 3):
    ans += p[t[0]] * p[t[1]] * p[t[2]]

print(ans)

Solution (Python):
N = int(input())
cntM, cntA, cntR, cntC, cntH = 0, 0, 0, 0, 0
for i in range(N):
    s = input()
    if s[0] == "M":
        cntM += 1
    elif s[0] == "A":
        cntA += 1
    elif s[0] == "R":
        cntR += 1
    elif s[0] == "C":
        cntC += 1
    elif s[0] == "H":
        cntH += 1
Names = [cntM,cntA,cntR,cntC,cntH]
ans = 0
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            if k <= 4:
                ans += Names[i]*Names[j]*Names[k]
print(ans)

Solution (Python):
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 'MARCH':
        d[s[0]]+=1

v = list(d.values())
ans = 0

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

print(ans)

Solution (Python):
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 'MARCH':
        d[s[0]] += 1
v = list(d.values())
ans = 0
for i in range(5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            ans += v[i]*v[j]*v[k]
print(ans)

Solution (Python):
from collections import Counter
import itertools
 
N = int(input())
src = [input() for i in range(N)]
 
ctr = Counter()
for s in src:
    ctr.update(s[0])
 
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 collections import defaultdict
from itertools import combinations

D = defaultdict(list)
N = int(input())
for i in range(N):
    s = input().strip()
    if s[0] in 'MARCH':
        D[s[0]].append(s)

if len(D.keys()) < 3:
    print(0)
    exit()

C = combinations(list(D.keys()), 3)

ans = 0
for c in C:
    ans += len(D[c[0]]) * len(D[c[1]]) * len(D[c[2]])

print(ans)

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

D = defaultdict(list)
N = int(input())
for i in range(N):
    s = input().strip()
    if s[0] in ('M', 'A', 'R', 'C', 'H'):
        D[s[0]].append(s)

if len(D.keys()) < 3:
    print(0)
    exit()

C = combinations(list(D.keys()), 3)

ans = 0
for c in C:
    ans += len(D[c[0]]) * len(D[c[1]]) * len(D[c[2]])

print(ans)

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

D = defaultdict(list)
N = int(input())
for i in range(N):
    s = input().strip()
    if s[0] in ('M', 'A', 'R', 'C', 'H'):
        D[s[0]].append(s)

if len(D.keys()) < 3:
    print(0)
    exit()

C = combinations(list(D.keys()), 3)

ans = 0
for c in C:
    ans += len(D[c[0]]) * len(D[c[1]]) * len(D[c[2]])

print(ans)

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

A=[]
A.append(S.count("M"))
A.append(S.count("A"))
A.append(S.count("R"))
A.append(S.count("C"))
A.append(S.count("H"))
ans=0

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

Solution (Python):
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)
args = sys.argv


def dump_impl(*objects):
    print(*objects, file=sys.stderr)


def dump_dummy(*objects):
    pass


dump = dump_impl if len(args) == 2 and args[1] == "DEBUG" else dump_dummy
N = int(input())
S = [input() for i in range(N)]

D = {'M': [], 'A': [], 'R': [], 'C': [], 'H': []}
for Si in S:
    if Si[0] in D:
        D[Si[0]].append(Si)

dump(D)

ans = 0
for x in it.combinations("MARCH", 3):
    x0, x1, x2 = x
    dump(x0, x1, x2)
    ans += len(D[x0])*len(D[x1])*len(D[x2])
print(ans)

Solution (Python):
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)
args = sys.argv


def dump_impl(*objects):
    print(*objects, file=sys.stderr)


def dump_dummy(*objects):
    pass


dump = dump_impl if len(args) == 2 and args[1] == "DEBUG" else dump_dummy
N = int(input())
S = [input() for i in range(N)]

D = {'M': [], 'A': [], 'R': [], 'C': [], 'H': []}
for Si in S:
    if Si[0] in D:
        D[Si[0]].append(Si)

dump(D)

ans = 0
for x in it.combinations("MARCH", 3):
    x0, x1, x2 = x
    dump(x0, x1, x2)
    ans += len(D[x0])*len(D[x1])*len(D[x2])
print(ans)

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

n = int(input())

mydict = defaultdict(lambda: 0)
s = []
for i in range(n):
	s.append(input())


for word in s:
	mydict[word[0]] += 1

ways = list(combinations("MARCH", 3))

total = 0
for way in ways:
	temp = mydict[way[0]]*mydict[way[1]]*mydict[way[2]]
	
	total += temp

print(total)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
S = [input() for _ in range(N)]

count = defaultdict(int)

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

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

Solution (Python):
n = int(input())
m = 0
a = 0
r = 0
c = 0
h = 0
for i in range(n):
  name = input()
  if name[0]=='M':
    m+=1
  elif name[0]=='A':
    a+=1
  elif name[0]=='R':
    r+=1
  elif name[0]=='C':
    c+=1
  elif name[0]=='H':
    h+=1
  else:
    pass
  
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 as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)
args = sys.argv


def dump_impl(*objects):
    print(*objects, file=sys.stderr)
def dump_dummy(*objects):
    print(*objects, file=sys.stderr)
    
dump = dump_impl if len(args) == 2 and args[1] == "DEBUG" else dump_dummy

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

D={'M':[],'A':[],'R':[],'C':[],'H':[]}
for Si in S:
    if Si[0] in D:
        D[Si[0]].append(Si)

dump(D)

ans=0
for x in it.combinations("MARCH", 3):
    x0,x1,x2=x
    dump(x0,x1,x2)
    ans += len(D[x0])*len(D[x1])*len(D[x2])
print(ans)

Solution (Python):
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)
args = sys.argv


def dump_impl(*objects):
    print(*objects, file=sys.stderr)
def dump_dummy(*objects):
    print(*objects, file=sys.stderr)
    
dump = dump_impl if len(args) == 2 and args[1] == "DEBUG" else dump_dummy

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

D={'M':[],'A':[],'R':[],'C':[],'H':[]}
for Si in S:
    if Si[0] in D:
        D[Si[0]].append(Si)

dump(D)

ans=0
for x in it.combinations("MARCH", 3):
    x0,x1,x2=x
    dump(x0,x1,x2)
    ans += len(D[x0])*len(D[x1])*len(D[x2])
print(ans)

Solution (Python):
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)
args = sys.argv


def dump(*objects):
    if len(args) == 2 and args[1] == "DEBUG":
        print(*objects, file=sys.stderr)

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

D={'M':[],'A':[],'R':[],'C':[],'H':[]}
for Si in S:
    if Si[0] in D:
        D[Si[0]].append(Si)

dump(D)

ans=0
for x in it.combinations("MARCH", 3):
    x0,x1,x2=x
    dump(x0,x1,x2)
    ans += len(D[x0])*len(D[x1])*len(D[x2])
print(ans)

Solution (Python):
import itertools
import numpy as np

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

seq = ('m', 'a', 'r', 'c', 'h')

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

for i in Names:
    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
        
Seq=[M,A,R,C,H]
Combi=list(itertools.combinations(Seq,3)) 

Ans=0
for i in Combi:
    Ans+=np.prod(i)
print(Ans)

Solution (Python):
n = int(input())
s = "MARCH"
d = { i:0 for i in s }
for _ in range(n):
  f =  input()[0]
  if f in s:
    d[f] += 1
ans = 0
for i in range(3):
  for j in range(i+1, 4):
    for k in range(j+1, 5):
      ans += d[s[i]]*d[s[j]]*d[s[k]]
print(ans)

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

MARCH = ["M", "A", "R", "C", "H"]
S = dict()
for i in range(N):
    tmp = input()
    if tmp[0] in S:
        S[tmp[0]] += 1
    elif tmp[0] in MARCH:
        S[tmp[0]] = 1
    else:
        pass
    
S_values = []
for value in S.values():
    S_values.append(value)
        
if len(S) == 3:
    ans = 1
    for i in range(len(S)):
        ans *= S_values[i]
elif len(S) == 4:
    ans = 0
    ans += S_values[0] * S_values[1] * S_values[2]
    ans += S_values[0] * S_values[1] * S_values[3]
    ans += S_values[1] * S_values[2] * S_values[3]
    ans += S_values[0] * S_values[2] * S_values[3]
elif len(S) ==  5:
    ans = 0
    ans += S_values[0] * S_values[1] * S_values[2]
    ans += S_values[0] * S_values[2] * S_values[3]
    ans += S_values[0] * S_values[3] * S_values[4]
    ans += S_values[0] * S_values[1] * S_values[3]
    ans += S_values[0] * S_values[1] * S_values[4]
    ans += S_values[0] * S_values[2] * S_values[4]
    ans += S_values[1] * S_values[2] * S_values[3]
    ans += S_values[1] * S_values[3] * S_values[4]
    ans += S_values[1] * S_values[2] * S_values[4]
    ans += S_values[2] * S_values[3] * S_values[4]
else:
    print(0)
    exit()





print(ans)

Solution (Python):
import itertools

n = int(input())
s = [input() for _ in range(n)]
m = a = r = c = h = 0
ans = 0

for name in s:
    if name[0] == 'M':
        m += 1

    elif name[0] == 'A':
        a += 1

    elif name[0] == 'R':
        r += 1

    elif name[0] == 'C':
        c += 1

    elif name[0] == 'H':
        h += 1

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

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

print(ans)

Solution (Python):

import collections
import itertools

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

counted = collections.Counter(S_list)
char_comb_list = list(itertools.combinations(["M","A","R","C","H"],3))

ans = 0

for char_comb in char_comb_list:
    ans += counted[char_comb[0]] * counted[char_comb[1]] * counted[char_comb[2]]
    
print(ans)

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

dic = {"M":[], "R":[], "A":[], "C":[], "H":[]}

for _ in range(n):
    s = input()
    if s[0] in dic:
        dic[s[0]].append(s)


import itertools
a = [i for i in range(5)]
per = list(itertools.combinations(a, 3))

ans = 0
for a,b,c in per:
    aa = ["M", "R", "A", "C", "H"]
    ans += len(set(dic[aa[a]])) * len(set(dic[aa[b]])) * len(set(dic[aa[c]]))
print(ans)

Solution (Python):
from itertools import combinations
N=int(input())
L = [str(input()) for i in range(N)]
count_M=0
count_A=0
count_R=0
count_C=0
count_H=0
for i in L:
    if i[0]=='M':count_M+=1
    elif i[0]=='A':count_A+=1
    elif i[0]=='R':count_R+=1
    elif i[0]=='C':count_C+=1
    elif i[0]=='H':count_H+=1
name_list=[count_M,count_A,count_R,count_C,count_H]
sum_list=list(combinations(name_list,3))
s_list=[i[0]*i[1]*i[2] for i in sum_list]
print(sum(s_list))

Solution (Python):
N = int(input())
X = {c:0 for c in 'MARCH'}
for _ in range(N):
    c = input()[0]
    if c in X: X[c]+=1

ans = 0
for i1 in range(5):
    for i2 in range(i1+1,5):
        for i3 in range(i2+1,5):
            ans += X['MARCH'[i1]]*X['MARCH'[i2]]*X['MARCH'[i3]]
print(ans)

Solution (Python):
def examC():
    N = I()
    St = [S() for _ in range(N)]
    d = defaultdict(int)
    ans = 0
    march = ["M","A","R","C","H"]
    for s in St:
        if s[0] in march:
            d[s[0]] +=1
    if len(d)>=3:
        for comb in itertools.permutations(march):
            ans += d[comb[0]]*d[comb[1]]*d[comb[2]]
        ans //=12
    print(ans)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

Solution (Python):
N = int(input())
name = [input() for i in range(N)]
nameList = [0 for i in range(5)]

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]

for n in name:
  if n[0] == 'M':
    nameList[0] += 1
  elif n[0] == 'A':
    nameList[1] += 1
  elif n[0] == 'R':
    nameList[2] += 1
  elif n[0] == 'C':
    nameList[3] += 1
  elif n[0] == 'H':
    nameList[4] += 1

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

Solution (Python):
from math import factorial as fac
from itertools import combinations as comb

n = int(input())
x = ["M", "A", "R", "C", "H"]
x_l = [[], [], [], [], []]
l = [ input() for i in range(n)]

for s in l:
  if s[0] in x:
    x_l[x.index(s[0])].append(s)
    
    
x_l = [len(x_l[i]) for i in range(5) if len(x_l[i]) != 0]
leng = len(x_l)


if leng < 3:
  print(0)
else:
  ans = 0
  for number in comb([ i for i in range(leng)], 3):
    ans += x_l[number[0]]*x_l[number[1]]*x_l[number[2]]
  print(ans)

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

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

values = [v for k, v in initial.items()]
ans = 0
for i in range(3):
    for j in range(i+1, 4):
        for k in range(j+1, 5):
            ans += values[i] * values[j] * values[k]

print(ans)

Solution (Python):
N = int(input())
Sset = set()
str_dict = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for _ in range(N):
    S = input()
    if S in Sset:
        continue
    if S[0] in {"M", "A", "R", "C", "H"}:
        Sset.add(S)
        str_dict[S[0]] += 1

non0 = []
for item in str_dict.items():
    if item[1] > 0:
        non0.append(item[0])

num = 0
from itertools import combinations
for comb in combinations(non0, 3):
    num += str_dict[comb[0]] * str_dict[comb[1]] * str_dict[comb[2]]

print(num)

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

n = int(stdin.readline().rstrip())
li = [stdin.readline().rstrip() for _ in range(n)]

lin = [0]*5

for i in range(len(li)):
    if li[i][0] == "M":
        lin[0] += 1
    elif li[i][0] == "A":
        lin[1] += 1
    elif li[i][0] == "R":
        lin[2] += 1
    elif li[i][0] == "C":
        lin[3] += 1
    elif li[i][0] == "H":
        lin[4] += 1
        
lis = list(combinations(lin, 3))

point = 0
for i in lis:
    point += i[0]*i[1]*i[2]

print(point)

Solution (Python):
import sys

readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def main():
    N = int(readline())
    S = list(map(lambda x: x.decode("UTF-8"), readlines()))
    S = list(map(lambda x: x.rstrip('\n'), S))
    march = list("MARCH")

    cnt = [0] * 5
    for i in range(N):
        for j in range(5):
            if S[i][0] == march[j]:
                cnt[j] += 1

    ans = 0

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

        print(ans)


main()

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

s = [m, a, r, c, h]
x = [0, 0, 0, 0, 0, 0, 1, 1, 1, 2]
y = [1, 1, 1, 2, 2, 3, 2, 2, 3, 3]
z = [2, 3, 4, 3, 4, 4, 3, 4, 4, 4]

cnt = 0
for i in range(10):
    cnt += (s[x[i]] * s[y[i]] * s[z[i]])
print(cnt)

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

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

D={}
D["M"]=0
D["A"]=0
D["R"]=0
D["C"]=0
D["H"]=0

for i in range(N):
    S=input()
    if S[0]=="M":
        D["M"]+=1
    elif S[0]=="A":
        D["A"]+=1
    elif S[0]=="R":
        D["R"]+=1
    elif S[0]=="C":
        D["C"]+=1
    elif S[0]=="H":
        D["H"]+=1

import itertools
l=["M","A","R","C","H"]
a=list(itertools.combinations(l,3)) 

ANS=0
for i in range(len(a)):
    ANS+=(D[a[i][0]]*D[a[i][1]]*D[a[i][2]])
print(ANS)

Solution (Python):
import itertools


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

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

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

head_l = [m, a, r, c, h]
comb_l = list(itertools.combinations(head_l, 3))
ans = 0
for comb in comb_l:
    pat = comb[0]
    for i in range(1, len(comb)):
        pat *= comb[i]
    ans += pat
        
print(ans)

Solution (Python):
from collections import defaultdict
import itertools

d = defaultdict(int)

N = int(input())
for _ in range(N):
    s = input()
    if s.startswith('M'):
        d['M'] += 1
    elif s.startswith('A'):
        d['A'] += 1
    elif s.startswith('R'):
        d['R'] += 1
    elif s.startswith('C'):
        d['C'] += 1
    elif s.startswith('H'):
        d['H'] += 1

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

Solution (Python):
N = int(input())
li = [input() for i in range(N)]
liM = []
liA = []
liR = []
liC = []
liH = []
for i in range(N):
  if li[i][0] == 'M':
    liM.append(li[i])
  elif li[i][0] == 'A':
    liA.append(li[i])
  elif li[i][0] == 'R':
    liR.append(li[i])
  elif li[i][0] == 'C':
    liC.append(li[i])
  elif li[i][0] == 'H':
    liH.append(li[i])
M = len(liM)
A = len(liA)
R = len(liR)
C = len(liC)
H = len(liH)
ans = M*(A*(R+C+H)+R*(C+H)+C*H) + A*(R*(C+H)+C*H) + R*C*H
print(ans)

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

march = 'MARCH'
dic = {c:0 for c in march}
for i in range(n):  
  s = input()
  if s[0] in march:
    dic[s[0]] += 1

c = combinations(march,3)    
ans = 0
for v1,v2,v3 in c:
  ans += dic[v1]*dic[v2]*dic[v3]  

print(ans)

Solution (Python):
n = int(input())
ss = "MARCH"
c = [0 for i in range(5)]
for i in range(n):
	s = input()
	for j in range(5):
		if s[0] == ss[j]:
			c[j] += 1
ans = 0
for i in range(5):
	for j in range(i+1,5):
		for k in range(j+1,5):
			ans += c[i]*c[j]*c[k]
print (ans)

Solution (Python):
lists=[0 for i in range(5)]
mar=["M","A","R","C","H"]
n=int(input())
for i in range(n):
    s=input()
    a=s[0]
    for i in range(5):
        if a==mar[i]:
            lists[i]+=1
answer=0
for i in range(5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            answer+=lists[i]*lists[j]*lists[k]
print(answer)

Solution (Python):
from itertools import*
N,*S=open(0)
print(sum(a*b*c for a,b,c in combinations([sum(1 for s in S if s[0]==c) for c in "MARCH"],3)))

Solution (Python):
import itertools
n = int(input())
list_march = ["M", "A", "R", "C", "H"]
num_march = [0 for i in range(5)]
for i in range(n):
  s = input()
  if s[0] in list_march:
    num_march[list_march.index(s[0])] += 1

if num_march.count(0) >= 3:
  print(0)
else:
  cand = list(itertools.combinations([0, 1, 2, 3, 4], 3))
  result = 0
  for a, b, c in cand:
    result += num_march[a] * num_march[b] * num_march[c]
  print(result)

Solution (Python):
import collections
N = int(input())
S = [input() for i in range(N)]
SI = [S[i][0] for i in range(N)]
cnt = collections.Counter(SI)
n = [cnt["M"],cnt["A"],cnt["R"],cnt["C"],cnt["H"]]
ans = 0
for i in range(3):
    for j in range(i+1,5):
        for k in range(j+1,5):
            ans += n[i]*n[j]*n[k]
print(ans)

Solution (Python):
from collections import defaultdict
import itertools
N = int(input())
d = defaultdict(int)
for _ in range(N):
  s = input()
  if s[0] in 'MARCH':
    d[s[0]] += 1

ans = 0
if len(d.keys()) >= 3:
  for c in itertools.combinations(d.values(), 3):
    ans += c[0] * c[1] * c[2]

print(ans)

Solution (Python):
n = int(input())
s = [input() for _ in range(n)]
M = A = R = C = H = 0
for i in range(len(s)):
    if s[i][0] == 'M':
        M += 1
    if s[i][0] == 'A':
        A += 1
    if s[i][0] == 'R':
        R += 1
    if s[i][0] == 'C':
        C += 1
    if s[i][0] == 'H':
        H += 1
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())
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):
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1

def main():
    n=int(input())
    cc=[0]*5
    for _ in range(n):
        c=input()[0]
        if c=="M":cc[0]+=1
        if c == "A": cc[1] += 1
        if c == "R": cc[2] += 1
        if c == "C": cc[3] += 1
        if c == "H": cc[4] += 1
    ans=0
    for k in range(5):
        for j in range(k):
            for i in range(j):
                ans+=cc[i]*cc[j]*cc[k]
    print(ans)

main()

Solution (Python):

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

import collections
name_frq_dict = collections.defaultdict(int)
for s in S:
    if s[0] in ['M', 'A', 'R', 'C', 'H']:
        name_frq_dict[s[0]] += 1


len_name_frq_dict = len(name_frq_dict)

if len_name_frq_dict < 3:
    print(0)
else:
    import itertools

    ans = 0
    names = list(name_frq_dict.keys())
    for part_names in itertools.permutations(names, 3):
        a = 1
        for n in part_names:
            a *= name_frq_dict[n]
        ans += a

    print(ans//6)

Solution (Python):

from itertools import combinations
n = int(input())
names = [0 for _ in range(5)]
for _ in range(n):
    start = input()[0]
    if start == 'M':
        names[0] += 1
    if start == 'A':
        names[1] += 1
    if start == 'R':
        names[2] += 1
    if start == 'C':
        names[3] += 1
    if start == 'H':
        names[4] += 1
comb = combinations(names, 3)
total = 0
for c in comb:
    total += c[0]*c[1]*c[2]
print(total)

Solution (Python):
N = int(input())
Dict={}
for i in range(N):
    T=input()
    if Dict.get(T[0],None)==None:
        Dict[T[0]]=1
    else:
        Dict[T[0]]+=1

L=[]
if Dict.get("M",None)!=None:
    L.append(Dict["M"])
if Dict.get("R",None)!=None:
    L.append(Dict["R"])
if Dict.get("A",None)!=None:
    L.append(Dict["A"])
if Dict.get("C",None)!=None:
    L.append(Dict["C"])
if Dict.get("H",None)!=None:
    L.append(Dict["H"])
if(len(L)<3):
    print(0)
    exit()


S=0
for i in range(len(L)):
    for j in range(len(L)):
        if(i==j):break
        for k in range(len(L)):
            if(i==k):break
            if(j==k):break
            S+=L[i]*L[j]*L[k]
print(S)

Solution (Python):
X = [0] * 5
D = {"M": 0, "A": 1, "R": 2, "C": 3, "H": 4}
N = int(input())
for _ in range(N):
    s = input()[0]
    if s in D:
        X[D[s]] += 1

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

Solution (Python):


import sys





import itertools








def main():
    n = int(sys.stdin.readline().rstrip())
    march = {l: 0 for l in 'MARCH'}

    for i in range(n):
        initial = sys.stdin.readline()[0]
        if initial in march:
            march[initial] += 1


    march = {k: v for k, v in march.items() if v != 0}
    
    if len(march) < 2:
        print(0)
        exit()
    
    total_cmb = 0
    for cmb in itertools.combinations(march.values(), 3):
        total_cmb += cmb[0] * cmb[1] * cmb[2]
    
    print(total_cmb)
        
if __name__ == "__main__":
    
    main()

Solution (Python):
N=int(input())
S= list(str(input()) for i in range(N))
count_M = 0
count_R = 0
count_A = 0
count_C = 0
count_H = 0
for i in range(N):
  if S[i][0] =='M':
    count_M +=1
  if S[i][0] =='R':
    count_R +=1
  if S[i][0] =='C':
    count_C +=1
  if S[i][0] =='H':
    count_H +=1
  if S[i][0] =='A':
    count_A +=1
print(count_M*count_A*count_R+count_M*count_A*count_C+count_M*count_A*count_H+count_M*count_R*count_C+count_M*count_R*count_H+count_M*count_C*count_H+count_A*count_R*count_C+count_A*count_R*count_H+count_R*count_C*count_H+count_A*count_C*count_H)

Solution (Python):
n=int(input())
s=[]
for i in range(n):
  s.append(input())
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
    
ans=m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*c*h+a*r*h+r*c*h

print(ans)

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

for _ in range(N):
	S = str(input())
	if S[0] in ["M", "A", "R", "C", "H"]:
		if S[0] in dic:
			dic[S[0]] += 1
		else:
			dic[S[0]] = 1

ans = 0

A = list(dic.values())
for i in range(len(A) - 2):
	for j in range(i + 1, len(A) - 1):
		for k in range(j + 1, len(A)):
			ans += A[i] * A[j] * A[k]
print(ans)

Solution (Python):
N=int(input())
D="MARCH"
cnt=[0]*5
for i in range(N):
  s=input()[0]
  if s in D:
    cnt[D.index(s)]+=1

pat=[None]*10
pati=0
for a in range(5):
  for b in range(a+1,5):
    for c in range(b+1,5):
      pat[pati]=[a,b,c]
      pati+=1

ans=0
for p in pat:
  ans+=cnt[p[0]]*cnt[p[1]]*cnt[p[2]]
  
print(ans)

Solution (Python):
N=int(input())
S=[""]*N
for i in range(N):
  S[i]=input()
D="MARCH"
cnt=[0]*5
for s in S:
  if s[0] in D:
    cnt[D.index(s[0])]+=1
    
pat=[None]*10
pati=0
for a in range(5):
  for b in range(a+1,5):
    for c in range(b+1,5):
      pat[pati]=[a,b,c]
      pati+=1

ans=0
for p in pat:
  ans+=cnt[p[0]]*cnt[p[1]]*cnt[p[2]]
  
print(ans)

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

    dict = {'M': [],
    'A': [],
    'R': [],
    'C': [],
    'H': []}

    for i in range(N):
        name = input()
        if name[0] in list(dict.keys()):
            dict[name[0]].append(name)
    
    comb = itertools.combinations(dict.keys(), 3)
    count = 0
    for c in comb:
        count += len(dict[c[0]])*len(dict[c[1]])*len(dict[c[2]])
    
    print(count)

if __name__ == '__main__':
    solve()

Solution (Python):
import sys
import collections
import itertools
sys.setrecursionlimit(10 ** 7)


def main():
    N = int(input())
    S = []
    for _ in range(N):
        x = input()
        if x.startswith(("M", "A", "R", "C", "H")):
            S.append(x[0])

    c = collections.Counter(S)
    ans = 0
    for x, y, z in itertools.combinations(["M", "A", "R", "C", "H"], 3):
        ans += c[x] * c[y] * c[z]
    print(ans)


if __name__ == '__main__':
    main()

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

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

dic = defaultdict(int)
for s in S:
    dic[s[0]] += 1

comb = combinations("MARCH", 3)

ans = 0
for x1,x2,x3 in comb:
    ans += dic[x1]*dic[x2]*dic[x3]

print(ans)

Solution (Python):
import itertools
n = int(input())
s = [input()[0] for _ in range(n)]
c = list(itertools.combinations(set(filter(lambda x: x in "MARCH", s)), 3))

ans = 0
for _c in c:
    ans += s.count(_c[0])*s.count(_c[1])*s.count(_c[2])
print(ans)

Solution (Python):
N=int(input())
M,A,R,C,H=0,0,0,0,0
for i 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

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=0
a=0
r=0
c=0
h=0
for i 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
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 collections
import itertools

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