Problem:
 Score : 300 points    Problem Statement There are N people. The name of the i -th person is S_i .  We would like to choose three people so that the following conditions are met:   The name of every chosen person begins with M , A , R , C or H .  There are no multiple people whose names begin with the same letter.   How many such ways are there to choose three people, disregarding order?  Note that the answer may not fit into a 32 -bit integer type.      Constraints  1 \leq N \leq 10^5  S_i consists of uppercase English letters.  1 \leq |S_i| \leq 10  S_i \neq S_j (i \neq j)         Input Input is given from Standard Input in the following format:  N  S_1  :  S_N       Output If there are x ways to choose three people so that the given conditions are met, print x .        Sample Input 1 5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI      Sample Output 1 2  We can choose three people with the following names:    MASHIKE , RUMOI , HABORO    MASHIKE , RUMOI , HOROKANAI    Thus, we have two ways.       Sample Input 2 4
ZZ
ZZZ
Z
ZZZZZZZZZZ      Sample Output 2 0  Note that there may be no ways to choose three people so that the given conditions are met.       Sample Input 3 5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO      Sample Output 3 7

Solution (Python):
import re

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

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

for i in S:
    M = re.match("M",i)
    A = re.match("A",i)
    R = re.match("R",i)
    C = re.match("C",i)
    H = re.match("H",i)

    if M:
        m += 1
    if A:
        a += 1
    if R:
        r += 1
    if C:
        c += 1
    if 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 ="MARCH"
S2 = [0]*len(S)
n=0

for i in range(N):
    s = input()
    for k, j in enumerate(S):
        if s[0] == j:
            S2[k]+=1
            
for i in range(len(S2)):
    for j in range(i+1,len(S2)):
        for k in range(j+1,len(S2)):
            n +=S2[i]*S2[j]*S2[k]
    
print(n)

Solution (Python):
N = int(raw_input())
Names = []
n_M, n_A, n_R, n_C, n_H = 0,0,0,0,0
for i in range(N):
	Name = raw_input()
	if Name[0] == "M":
		n_M += 1
	if Name[0] == "A":
		n_A += 1
	if Name[0] == "R":
		n_R += 1
	if Name[0] == "C":
		n_C += 1
	if Name[0] == "H":
		n_H += 1

C = (n_M * n_A * n_R + 
	n_M * n_A * n_C +
	n_M * n_A * n_H +
	n_M * n_R * n_C +
	n_M * n_R * n_H +
	n_M * n_C * n_H +
	n_A * n_R * n_C +
	n_A * n_R * n_H +
	n_A * n_C * n_H +
	n_R * n_C * n_H
	)

print C

Solution (Python):
import itertools

n = int(input())

T = 'MARCH'
ct = [0 for _ in range(5)]
for _ in range(n):
    s = input()
    if s[0] not in T:
        continue
    ct[T.find(s[0])] += 1

ans = 0
for x,y,z in itertools.combinations(ct,3):
    ans += x*y*z
print(ans)

Solution (Python):
from itertools import combinations
N = int(input())
march = ['M','A','R','C','H']
dic = {}
for i in range(N):
	s = input()
	if s[0] in march:
		if s[0] in dic:
			dic[s[0]] += 1
		else:
			dic[s[0]] = 1

ans = 0
if len(dic.keys()) < 3:
	print(0)
else:
	for tup in combinations(dic.values(),3):
		
		ans += (tup[0] * tup[1] * tup[2])

	print(ans)

Solution (Python):
import itertools

N = int(input())
key = "MARCH"
S = [x for x in [input() for i in range(N)] if x[0] in key]
march = {}
for x in S:
    march.setdefault(x[0], []).append(x)

sizes = [len(x) for x in march.values()]
print(sum([a*b*c for a, b, c in itertools.combinations(sizes, 3)]))

Solution (Python):
import itertools
import sys

N = int(input())
key = "MARCH"
S = [x for x in [input() for i in range(N)] if x[0] in key]
march = {}
for x in S:
    march.setdefault(x[0], []).append(x)

if len(march) < 3:
    print(0)
    sys.exit()
    
sizes = [len(x) for x in march.values()]
print(sum([a*b*c for a, b, c in itertools.combinations(sizes, 3)]))

Solution (Python):
import itertools
import sys

N = int(input())
key = ["M", "A", "R", "C", "H"]
S = [x for x in [input() for i in range(N)] if x[0] in key]
march = {}
for x in S:
    march.setdefault(x[0], []).append(x)

if len(march) < 3:
    print(0)
    sys.exit()

sizes = [len(x) for x in march.values()]

print(sum([a*b*c for a, b, c in itertools.combinations(sizes, 3)]))

Solution (Python):
from itertools import combinations as c
from operator import mul
d = {k: 0 for k in 'MARCH'}
for _ in xrange(input()):
    n = raw_input()[0]
    if n in 'MARCH':
        d[n] += 1
r = [k for k, v in d.iteritems() if v]
print sum([reduce(mul, [d[k] for k in _]) for _ in c(r, 3)])

Solution (Python):
import math
import numpy as np
from operator import mul





























N = int(input())


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


headers = [0,0,0,0,0]


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 i in range(N):
    if S[i] == 'M':
        headers[0] += 1
    if S[i] == 'A':
        headers[1] += 1
    if S[i] == 'R':
        headers[2] += 1
    if S[i] == 'C':
        headers[3] += 1
    if S[i] == 'H':
        headers[4] += 1

count = 0

for i in range(10):
    count += headers[P[i]] * headers[Q[i]] * headers[R[i]]

print(count)

Solution (Python):
import math
def kumi(s, n):
    count = 1
    for x in range(s, s - n, -1):
        count *= x
    ret = count // math.factorial(n)
    return ret

def main():
    N = int(input().strip())
    S = []
    D = {}
    for _ in range(N):
        in_s = (input().strip())[0]
        if in_s in ['M','A','R','C','H']:
            S.append(in_s)
            D[in_s] = D.get(in_s, 0) + 1

    if not S or len(D.keys()) < 3:
        return 0

    
    
    count = kumi(len(S), 3)
    
    for v in D.values():
        if v < 2:
            continue
        elif v == 2:
            count -= len(S) - v
        else:
            count -= kumi(v, 2) * (len(S) - v)
            count -= kumi(v, 3)
    return count

if __name__ == '__main__':
    print(main())

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

Solution (Python):
import itertools
def main():
    n = int(input())
    A = [0 for i in range(5)]
    for _ in range(n):
        s = input()
        if s[0] in "MARCH":
            A["MARCH".index(s[0])] += 1
    ans = 0
    for i, j, k in itertools.combinations(range(5), 3):
        ans += A[i] * A[j] * A[k]
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import itertools
def main():
    n = int(input())
    A = [0 for i in range(5)]
    for _ in range(n):
        s = input()
        if s[0] in "MARCH":
            A["MARCH".index(s[0])] += 1
    ans = 0
    for i, j, k in itertools.combinations(range(5), 3):
        ans += A[i] * A[j] * A[k]
    print(ans)



if __name__ == "__main__":
    main()

Solution (Python):
import itertools
def main():
    n = int(input())
    
    m = 0
    a = 0
    r = 0
    c = 0
    h = 0
    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

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

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

if __name__ == "__main__":
    main()

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

march = [0, 0, 0, 0, 0]

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

result = 0
result += march[0] * march[1] * march[2]
result += march[0] * march[1] * march[3]
result += march[0] * march[1] * march[4]

result += march[0] * march[2] * march[3]
result += march[0] * march[2] * march[4]

result += march[0] * march[3] * march[4]

result += march[1] * march[2] * march[3]
result += march[1] * march[2] * march[4]

result += march[1] * march[3] * march[4]

result += march[2] * march[3] * march[4]

print(result)

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

array = []
dict = {}
dict["M"] = dict["A"] = dict["R"] = dict["C"] = dict["H"] = 0
for i in range(n):
    tmp = input()
    dict[tmp[0]] = dict.get(tmp[0], 0) + 1

m = dict["M"]
a = dict["A"]
r = dict["R"]
c = dict["C"]
h = dict["H"]
print(m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+
      a*r*c+a*r*h+a*c*h+r*c*h)

Solution (Python):
N = int(input())
M=0
A=0
R=0
C=0
H=0
namelist=[]
for _ in range(N):
    namelist.append(str(input()))
for i in range(N):
    if namelist[i][0] == "M":
      M += 1
    elif namelist[i][0] == "A":
      A += 1
    elif namelist[i][0] == "R":
      R += 1
    elif namelist[i][0] == "C":
      C += 1
    elif namelist[i][0] == "H":
      H += 1
    else:
       pass
num= 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(num)

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

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

Solution (Python):
import itertools
n=int(input())
data=[0,0,0,0,0]
for i in range(n):
    s=input()
    if(s[0]=='M'):
        data[0]+=1
    if(s[0]=='A'):
        data[1]+=1
    if(s[0]=='R'):
        data[2]+=1
    if(s[0]=='C'):
        data[3]+=1
    if(s[0]=='H'):
        data[4]+=1
ans=0
for x,y,z in itertools.combinations(range(5),3):
    ans+=data[x]*data[y]*data[z]
print(ans)

Solution (Python):
n=int(input())
U=list()
for i in range(n):
	i=input()
	U.append(i)
m=a=r=c=h=0
for x in U:
	if x[0]=='M':
		m+=1
	if x[0]=='A':
		a+=1
	if x[0]=='R':
		r+=1
	if x[0]=='C':
		c+=1
	if x[0]=='H':
		h+=1
sig=(m+a+r)*c*h+m*a*(r+c+h)+(m+a)*r*(c+h)
print(sig)

Solution (Python):
def kaijou(a):
    kai = 1
    for i in range(a):
        kai = kai * (i+1)
    return kai

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

    count = [0,0,0,0,0]
    initial = "MARCH"

    for i in range(5):
        for s in S:
            if s[0] == initial[i]:
                count[i] += 1

    k = 3
    kumiawase = 0
    for i in range(len(initial)-(k-1)):
        for j in range(i+1, len(initial)-1):
            kumiawase += count[i]*count[j]*sum(count[j+1:])

    return int(kumiawase)

if __name__ == "__main__":
    print(main())

Solution (Python):
N=int(input())
s=['M','A','R','C','H']
a=[]
b=[]
ans=0
for i in range(N):
    buf=str(input())
    a.append(buf[0])

for i in s:
    b.append(a.count(i))

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

print(ans)

Solution (Python):
N = int(input())
march_count = [0 for i in range(5)]
march_dict = {'M': 0, 'A': 1, 'R': 2, 'C': 3, 'H': 4}


for i in range(N):
    c = input()[0]
    if c in march_dict:
        march_count[march_dict[c]] += 1

count = 0


def calc(a, b, c):
    return march_count[a] * march_count[b] * march_count[c]


count = calc(0, 1, 2) + calc(0, 1, 3) + calc(0, 1, 4) \
    + calc(0, 2, 3) + calc(0, 2, 4) + calc(0, 3, 4) \
    + calc(1, 2, 3) + calc(1, 2, 4) + calc(1, 3, 4) \
    + calc(2, 3, 4)

print(count)

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

line = ['a' for i in range(N)]

lis = [ 0 for i in range(5)]

for i in range(N):
    lit = raw_input()
    if lit[0] == 'M':
        lis[0] += 1
    elif lit[0] == 'A':
        lis[1] += 1
    elif lit[0] == 'R':
        lis[2] += 1
    elif lit[0] == 'C':
        lis[3] += 1
    elif lit[0] == 'H':
        lis[4] += 1

tot = (lis[0] * lis[1] * (lis[2] + lis[3] + lis[4]) + lis[0] * lis[2] * (lis[3] + lis[4]) + lis[0] * lis[3] * lis[4] + 
       lis[1] * lis[2] * (lis[3] + lis[4]) + lis[1] * lis[3] * lis[4] + lis[2] * lis[3] * lis[4])

print tot

Solution (Python):
N = int(input())
S = [input() for i in range(N)]
L = [[],[],[],[],[]]
for i in S:
    if i[0]=="M":
        L[0].append(i)
    elif i[0]=="A":
        L[1].append(i)
    elif i[0]=="R":
        L[2].append(i)
    elif i[0]=="C":
        L[3].append(i)
    elif i[0]=="H":
        L[4].append(i)
import itertools
a = [i for i in range(5)]
T = list(itertools.combinations(a,3))
M = 0
for k in T:
    M += len(L[k[0]])*len(L[k[1]])*len(L[k[2]])
print(M)

Solution (Python):
import itertools
import collections
n = int(input())
c = collections.Counter([input()[0] for i in range(n)])
s = [c[x] for x in 'MARCH']

cnt = 0
for x in itertools.combinations(s, 3):
    cnt += x[0] * x[1] * x[2]
print(cnt)

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

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

count = [0] * 5
for i, c in enumerate("MARCH"):
    count[i] = len(list(filter(lambda n: n[0] == c, S_row)))

print(sum(map(lambda x: reduce(mul, x), combinations(count, 3))))

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

ans=0

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

Solution (Python):
N=int(input())
S=[input() for i in range(N)]
m=len([s for s in S if s[0]=='M'])
a=len([s for s in S if s[0]=='A'])
r=len([s for s in S if s[0]=='R'])
c=len([s for s in S if s[0]=='C'])
h=len([s for s in S if s[0]=='H'])
count=0
march=[m,a,r,c,h]
for x in range(0,3):
    for y in range(x+1,4):
          for z in range(y+1,5):
                count+=march[x]*march[y]*march[z]
print(count)

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

for i in range(N):
    name = input()
    try:
        relevant[name[0]] += 1
    except:
        pass

chars = [key for key in relevant.keys() if relevant[key] != 0]
ans = 0
for i in range(len(chars)):
    for j in range(i+1,len(chars)):
        for k in range(j+1,len(chars)):
            ans += relevant[chars[i]] * relevant[chars[j]] * relevant[chars[k]]
print(ans)

Solution (Python):
from collections import defaultdict                              

n = int(input())
name_count_dic = defaultdict(int)

for i in range(n):
    name = input()
    if name.startswith('M'):
        name_count_dic['M'] += 1
    elif name.startswith('A'):
        name_count_dic['A'] += 1
    elif name.startswith('R'):
        name_count_dic['R'] += 1
    elif name.startswith('C'):
        name_count_dic['C'] += 1
    elif name.startswith('H'):
        name_count_dic['H'] += 1

count_list = list(name_count_dic.values())
char_num = len(count_list)
if char_num < 3:
    num = 0 
else:
    num = 0 
    for i in range(char_num - 2): 
        for j in range(i + 1, char_num - 1): 
            for k in range(j + 1, char_num):
                num += count_list[i] * count_list[j] * count_list[k]

print(num)

Solution (Python):
n = int(input())
d = {}
for _ in range(n):
    h = input()[0]
    if h in 'MARCH':
        d[h] = d.get(h, 0) + 1
a = list(d.values())
r = 0
for i in range(len(a)):
    for j in range(i+1, len(a)):
        for k in range(j+1, len(a)):
            r += a[i]*a[j]*a[k]
print(r)

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

n = int(input())
l = Counter(input()[0] for _ in range(n))
con = [l[c] for c in 'MARCH' if c in l]
print(sum(a * b * c for a, b, c in combinations(con, 3)))

Solution (Python):
n = int(input().strip())
s = [input().strip() for _ in range(n)]
num = [0 for _ in range(5)]
num[0] = len([True for _s in s if _s[0] == "M"])
num[1] = len([True for _s in s if _s[0] == "A"])
num[2] = len([True for _s in s if _s[0] == "R"])
num[3] = len([True for _s in s if _s[0] == "C"])
num[4] = len([True for _s in s if _s[0] == "H"])
ans = 0
for i in range(5):
    for j in range(i + 1, 5):
        for k in range(j + 1, 5):
            ans += num[i] * num[j] * num[k]
print(ans)

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

nM = 0
nA = 0
nR = 0
nC = 0
nH = 0
Ans = 0

for i in range(N):
    S = input()
    Word = S[0]
    
    if Word =='M':
        nM += 1 
    elif Word =='A':
        nA += 1 
    elif Word =='R':
        nR += 1 
    elif Word =='C':
        nC += 1 
    elif Word =='H':
        nH += 1 

Ans = nM * (nA * (nR + nC + nH) + nR * (nC + nH) + nC * nH) + nA * (nR * (nC + nH) + nC * nH) + nR * nC * nH

print(Ans)

Solution (Python):
import itertools

n = int(raw_input())
li = list()
for m in range(0,n):
    li.append(raw_input())

m = len(filter(lambda x: x[0]=="M" ,li))
a = len(filter(lambda x: x[0]=="A" ,li))
r = len(filter(lambda x: x[0]=="R" ,li))
c = len(filter(lambda x: x[0]=="C" ,li))
h = len(filter(lambda x: x[0]=="H" ,li))

con = [m, a, r, c, h]
print sum(map(lambda x: x[0]*x[1]*x[2] , list(itertools.combinations(con, 3))))

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

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

xs = Counter(s[0] for s in S)

print(sum(xs[a] * xs[b] * xs[c] for a, b, c in combinations("MARCH", 3)))

Solution (Python):
n=int(input())
s=[input()for i in range(n)]
count_m=count_a=count_r=count_c=count_h=0
for i in s:
    if i[0]=="M":
        count_m+=1
    if i[0]=="A":
        count_a+=1
    if i[0]=="R":
        count_r+=1
    if i[0]=="C":
        count_c+=1
    if i[0]=="H":
        count_h+=1
ans_1=count_m*count_a*count_r
ans_2=count_m*count_a*count_c
ans_3=count_m*count_a*count_h
ans_4=count_m*count_r*count_c
ans_5=count_m*count_r*count_h
ans_6=count_m*count_c*count_h
ans_7=count_a*count_r*count_c
ans_8=count_a*count_r*count_h
ans_9=count_a*count_c*count_h
ans_10=count_r*count_c*count_h
print(ans_1+ans_2+ans_3+ans_4+ans_5+ans_6+ans_7+ans_8+ans_9+ans_10)

Solution (Python):
import sys

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

m = 0
a = 0
r = 0
c = 0
h = 0
for i in range(N):
    tmp = input()
    if tmp[0:1] == "M": 
      m += 1
      S.append(tmp[0:1]) 
    elif tmp[0:1] == "A":
      a += 1
      S.append(tmp[0:1]) 
    elif tmp[0:1] == "R":
      r += 1
      S.append(tmp[0:1]) 
    elif tmp[0:1] == "C":
      c += 1
      S.append(tmp[0:1]) 
    elif tmp[0:1] == "H":
      h += 1
      S.append(tmp[0:1]) 


editedArray = list(set(S))

if len(editedArray) < 3:
  print(0)
  sys.exit()

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):
import functools

N = int(input())
march = ["M","A","R","C","H"]
S = {}
for m in march:
    S[m] = 0

for i in range(N):
    s = input()
    if s[0] in march:
        S[s[0]] += 1

aS = [s for s in S.values() if s != 0]

mul = functools.reduce(lambda a, x: a * x, aS, 1)
ans = 0
if len(aS) == 3:
    ans = mul
elif len(aS) == 4:
    ans = functools.reduce(lambda a, x: a + mul/x, aS, 0)
elif len(aS) == 5:
    for i in range(5):
        for j in range(i+1,5):
            ans = ans + mul / aS[i] / aS[j]
print(int(ans))

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

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

CHARS = "MARCH"

xs = defaultdict(int)

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

def calc(xs):
    return sum(xs[a] * xs[b] * xs[c] for a, b, c in combinations(CHARS, 3))

print(calc(xs))

Solution (Python):
from itertools import combinations

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

march = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
for name in names:
    if name[0] in march:
        march[name[0]] += 1

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

print(res)

Solution (Python):
n = int(input()) 
num = [0,0,0,0,0]

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

num_1 = num[0]*num[1]*num[2]
num_2 = num[0]*num[1]*num[3]
num_3 = num[0]*num[1]*num[4]
num_4 = num[1]*num[2]*num[3]
num_5 = num[1]*num[2]*num[4]
num_6 = num[2]*num[3]*num[4]
num_7 = num[0]*num[2]*num[3]
num_8 = num[0]*num[2]*num[4]
num_9 = num[0]*num[3]*num[4]
num_10 = num[1]*num[3]*num[4]

answer = num_1 + num_2 + num_3 + num_4 + num_5 + num_6 + num_7 + num_8 + num_9 + num_10
print(answer)

Solution (Python):
n = int(input())
 
M = 0
A = 0
R = 0
C = 0
H = 0
 
res = 0
 
for i in range(n):
    char = input()[0]
    if char == "M":
        M += 1
    elif char == "A":
        A += 1
    elif char == "R":
        R += 1
    elif char == "C":
        C += 1
    elif char == "H":
        H += 1

res += M * A * R;
res += M * A * C;
res += M * A * H;
res += M * R * C;
res += M * R * H;
res += M * C * H;
 
res += A * R * C;
res += A * R * H;
res += A * C * H;
 
res += R * C * H;
 
print(res)

Solution (Python):
m_count = 0
a_count = 0
r_count = 0
c_count = 0
h_count = 0

n = input()

for i in range(n):
    name = raw_input()
    if name[0] == 'M':
        m_count += 1
    elif name[0] == 'A':
        a_count += 1
    elif name[0] == 'R':
        r_count += 1
    elif name[0] == 'C':
        c_count += 1
    elif name[0] == 'H':
        h_count += 1

count = 0
count += m_count * a_count * r_count
count += m_count * r_count * c_count
count += m_count * c_count * h_count
count += a_count * r_count * c_count
count += a_count * c_count * h_count
count += r_count * c_count * h_count
count += m_count * a_count * c_count
count += m_count * a_count * h_count
count += m_count * r_count * h_count
count += a_count * r_count * h_count

print count

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


num_1 = num[0]*num[1]*num[2]
num_2 = num[0]*num[1]*num[3]
num_3 = num[0]*num[1]*num[4]
num_4 = num[1]*num[2]*num[3]
num_5 = num[1]*num[2]*num[4]
num_6 = num[2]*num[3]*num[4]
num_7 = num[0]*num[2]*num[3]
num_8 = num[0]*num[2]*num[4]
num_9 = num[0]*num[3]*num[4]
num_10 = num[1]*num[3]*num[4]

answer = num_1 + num_2 + num_3 + num_4 + num_5 + num_6 + num_7 + num_8 + num_9 + num_10

print(answer)

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

def qwe(y):
    m = 0
    a = 0
    r = 0
    c = 0
    h = 0
    for i in y:
        if i == 'M':
            m += 1
        elif i == 'A':
            a += 1
        elif i == 'R':
            r += 1
        elif i == 'C':
            c += 1
        elif i == 'H':
            h += 1
        else:
            pass
    q = [m,a,r,c,h]
    return q

def qwer(arr):
    count = 0
    for j in range(len(arr)):
        if arr[j] == 0:
            count += 1
            arr[j] = "D"
    while "D" in arr:
        arr.remove("D")
    if count == 5:
        return 0
    if count == 4:
        return 0
    if count == 3:
        return 0
    if count == 2:
        wer = arr[0] * arr[1] * arr[2]
        return wer
    if count == 1:
        asd_1 = arr[0]*arr[1]*arr[2]
        asd_2 = arr[0]*arr[1]*arr[3]
        asd_3 = arr[0]*arr[2]*arr[3]
        asd_4 = arr[1]*arr[2]*arr[3]
        asde = asd_1 + asd_2 + asd_3 + asd_4
        return asde
    if count == 0:
        asf_1 = arr[0]*arr[1]*arr[2]
        asf_2 = arr[0]*arr[1]*arr[3]
        asf_3 = arr[0]*arr[1]*arr[4]
        asf_4 = arr[0]*arr[2]*arr[3]
        asf_5 = arr[0]*arr[2]*arr[4]
        asf_6 = arr[0]*arr[3]*arr[4]
        asf_7 = arr[1]*arr[2]*arr[3]
        asf_8 = arr[1]*arr[2]*arr[4]
        asf_9 = arr[1]*arr[3]*arr[4]
        asf_10 = arr[2]*arr[3]*arr[4]
        asdf =  asf_1 + asf_2 + asf_3 + asf_4 + asf_5 + asf_6 + asf_7 + asf_8 + asf_9 + asf_10
        return asdf
v = qwe(s)
print(qwer(v))

Solution (Python):
import itertools

count = int(input())
ary = [input() for i in range(count)]
ary_abc = {'M': 0 ,'A': 0, 'R': 0, 'C':0, 'H':0}
for i in ary:
    for abc in ary_abc:
        if abc == i[0]:
            ary_abc[abc] = ary_abc[abc] + 1

ary_res = []

for n in ary_abc:
    if ary_abc[n] != 0:
        ary_res.append(ary_abc[n])




result = 0



result_rz = 1
for last_ary in itertools.combinations(ary_res, 3):
    for rz in last_ary:
        result_rz *= rz
    result += result_rz
    result_rz = 1
print(result)

Solution (Python):
from itertools import combinations

def main():
    N = int(input())
    S = tuple(input() for _ in [0] * N)

    name = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
    for s in S:
        if s[0] in 'MARCH':
            name[s[0]] += 1

    lst = [i for i in name.values() if i]
    n = len(lst)
    if n < 3:
        print(0)
        return

    i = 0
    for a, b, c in combinations(name.keys(), 3):
        if all((name[a], name[b], name[c])):
            i += name[a] * name[b] * name[c]

    print(i)

main()

Solution (Python):
N=int(input())
X=[0,0,0,0,0]
for I in range(N):
	L=input()
	if L[0]=='M':
		X[0]+=1
	elif L[0]=='A':
		X[1]+=1
	elif L[0]=='R':
		X[2]+=1
	elif L[0]=='C':
		X[3]+=1
	elif L[0]=='H':
		X[4]+=1
SUM=0
for J in range(3):
	for K in range(J+1,4):
		for M in range(K+1,5):
			if J!=K and K!=M and (X[J]!=0 or X[K]!=0 or X[M]!=0):
				SUM+=X[J]*X[K]*X[M]
print(SUM)

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

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

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

print(comNum)

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

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

n = 0
for n in range(N):
    X_n = list(input())
    
    if (X_n[0]) == "M":
        M += 1
    if (X_n[0]) == "A":
        A += 1
    if (X_n[0]) == "R":
        R += 1
    if (X_n[0]) == "C":
        C += 1
    if (X_n[0]) == "H":
        H += 1
    n += 1



lisofnum = [M, A, R, C, H]

k = 0
cou = 0
for k in range(len(lisofnum)):
    if lisofnum[k] != 0:
        cou += 1
    k += 1


if cou < 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):
from collections import Counter
from itertools import combinations
N = int(input())
S = [input()[0] for i in range(N)]
C = dict(Counter(S))

A = ["M", "A", "R", "C", "H"]
Z = []
for moji, num in C.items():
    if moji in A:
        Z.append(num)

ans = 0
if len(Z) < 3:
    print(0)
else:
    comb = list(combinations(Z, 3))
    for c in comb:
        ans += c[0] * c[1] * c[2]
    print(ans)

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



from collections import defaultdict
d = defaultdict(int)

for i in range(N):
	s = input()
	k = s[0]
	d[k] += 1



r = [ d['M'], d['A'], d['R'], d['C'], d['H'] ]




from itertools import combinations


ans=0
for l in list(combinations(r, 3)):
	ans += (l[0] * l[1] * l[2])

print(ans)

Solution (Python):
import itertools
import math

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

count_M = 0
count_A = 0
count_R = 0
count_C = 0
count_H = 0

for l in S_list:
    if l.startswith('M'):
        count_M += 1
    elif l.startswith('A'):
        count_A += 1
    elif l.startswith('R'):
        count_R += 1
    elif l.startswith('C'):
        count_C += 1
    elif l.startswith('H'):
        count_H += 1

count = [count_M,count_A,count_R,count_C,count_H]
c = list(itertools.combinations(count,3))
x = 0
for i in c:
    i_list = list(i)
    x += i_list[0]*i_list[1]*i_list[2]
print(x)

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
init_list = [m, a, r, c, h]
ans_list = []
for i in range(32):
    if bin(i).count("1") == 3:
        ans = 1
        for j in range(5):
            if i >> j & 1 == 1:
                ans *= init_list[j]
        ans_list.append(ans)
print(sum(ans_list))

Solution (Python):
import functools

N = int(input())
march = ["M","A","R","C","H"]
S = {}
for m in march:
    S[m] = 0

for i in range(N):
    s = input()
    if s[0] in march:
        S[s[0]] += 1

aS = []
for s in S.values():
    if s != 0:
        aS.append(s)

mul = 1
ans = 0
sum = 0
for s in aS:
    mul = mul * s
    sum += 1
if sum == 3:
    ans = mul
elif sum == 4:
    
    for s in aS:
        ans = ans + mul / s
elif sum == 5:
    
    for i in range(5):
        for j in range(i+1,5):
            ans = ans + mul / aS[i] / aS[j]
print(int(ans))

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

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

while 0 in march:
    march.remove(0)


rsl=0
cnt1=0
for c1 in march:
    cnt2=cnt1+1
    for c2 in march[cnt1+1:]:
        for c3 in march[cnt2+1:]:
            rsl+=c1*c2*c3

        cnt2+=1
    cnt1+=1

print(rsl)

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

m = S.count('M')
a = S.count('A')
r = S.count('R')
c = S.count('C')
h = S.count('H')

total = 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(total)

Solution (Python):
n = int(input())
ss = [input() for _ in range(n)]
mp = {c:0 for c in "MARCH"}
ans = 0

for i in range(n):
    if ss[i][0] in "MARCH":
        mp[ss[i][0]] += 1
for i in range(2**5):
    cnt = 0
    tmp = 1
    j = i
    for k in range(5):
        if j % 2 == 1:
            cnt += 1
            tmp *= mp["MARCH"[k]]
        j //= 2
    if cnt == 3:
        ans += tmp

print(ans)

Solution (Python):
import numpy as np

N = input()
l = [i for i in range(int(N))]
M = 0
A = 0
R = 0
C = 0
H = 0
for j in range(int(N)):
  l[j] = input()
  if l[j][0] =="M":
    M = M+1
  elif l[j][0] =="A":
    A = A+1
  elif l[j][0] =="R":
    R = R+1
  elif l[j][0] =="C":
    C = C+1
  elif l[j][0] =="H":
    H = H+1
  else: pass

a = np.array([M,A,R,C,H])
ch = np.nonzero(a)
ch = ch[0]
re = 0
if len(ch)<3:
  re = 0
else:
  re = M*A*R+M*A*C+M*A*H
  re = re + M*R*C+M*R*H
  re = re + M*C*H
  re = re + A*R*C+A*R*H+A*C*H
  re = re + R*C*H

print(re)

Solution (Python):
N = int(input())
S = []
for i in range(N):
    S.append(input())
md = {}
for i in S:
    if i[0] in ["M","A","R","C","H"]:
        md[i[0]] = md.get(i[0],0) + 1
v = 0
for i in ["MAR","MAC","MAH","MRC","MRH","MCH","ARC","ARH","ACH","RCH"]:
    v += md.get(i[0],0) * md.get(i[1],0) * md.get(i[2],0)
print(v)