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


from itertools import combinations

def main():
    march = list("MARCH")
    di = {c: 0 for c in march}
    n = int(input())
    for i in range(n):
        s = input()
        c = s[0]
        if c in march:
            di[c] += 1
    res = 0
    for com in combinations(march, 3):
        x, y, z = com
        res += di[x] * di[y] * di[z]
    print(res)

main()

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


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

m = len([cand for cand in S if ((cand[0] == 'M')) ])
a = len([cand for cand in S if ((cand[0] == 'A')) ])
r = len([cand for cand in S if ((cand[0] == 'R')) ])
c = len([cand for cand in S if ((cand[0] == 'C')) ])
h = len([cand for cand in S if ((cand[0] == 'H')) ])



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

print(comb)

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

countM=0
countA=0
countR=0
countC=0
countH=0

for i in range(n):
  if s[i][0]=="M":
    countM+=1
  if s[i][0]=="A":
    countA+=1
  if s[i][0]=="R":
    countR+=1
  if s[i][0]=="C":
    countC+=1
  if s[i][0]=="H":
    countH+=1
ans = countM*countA*countR + countM*countA*countC + countM*countA*countH 
ans = ans + countM*countR*countC + countM*countR*countH +countM*countC*countH
ans = ans + countA*countR*countC +countA*countR*countH + countA*countC*countH + countR*countC*countH
print(ans)

Solution (Python):
from itertools import combinations
N = int(input())
names = {}
for _ in range(N):
    S = input()
    if S[0] in 'MARCH':
        if S[0] not in names:
            names[S[0]] = 1
        else:
            names[S[0]] += 1
comb = len(names)
if comb <= 2:
    print(0)
elif comb == 3:
    ret = 1
    for v in names.values():
        ret *= v
    print(ret)
elif comb == 4:
    tmp = 1
    for v in names.values():
        tmp *= v
    ret = 0
    for v in names.values():
        ret += tmp // v
    print(ret)
else:
    ret = 0
    for comb in combinations('MARCH', 3):
        tmp = 1
        for c in comb:
            tmp *= names[c]
        ret += tmp
    print(ret)

Solution (Python):
from collections import Counter
n = int(input())
A = [input()[0] for i in range(n)]

A = Counter(A)
m = A['M']
a = A['A']
r = A['R']
c = A['C']
h = A['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 math
a, b = map(str, input().split())
j = int(a + b)
if math.sqrt(j).is_integer():
    print("Yes")
else:
    print("No")
"""


"""
ans = ["Positive","Negative"]
a, b = map(int, input().split())
if 0 < a:
    print("Positive")
elif b >= 0:
    print("Zero")
else:
    print(ans[(b-a)%2-1])
"""


import itertools
n = int(input())
MARCH = ["M", "A", "R", "C", "H"]
march = [0 for _ in range(5)]
for i in range(n):
    s = input()
    if s[0] in MARCH:
        march[MARCH.index(s[0])] += 1
num = list(range(5))
a = list(itertools.combinations(num, 3))
ans = 0
for i in a:
    bf = 1
    for k in i:
        bf *= march[k]
    ans += bf
print(ans)

Solution (Python):

from collections import defaultdict
import math
def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
mod = 1000000007


"""
a,b = LS()
c = int(a+b)
for i in range(1,1000):
    if i * i == c:
        print("Yes")
        quit()
print("No")
"""


"""
a,b = LI()
if a*b <= 0:
    print("Zero")
else:
    if b < 0:
        if (a-b) %2 == 1:
            print("Positive")
        else:
            print("Negative")
    else:
        print("Positive")
"""


n = II()
s = SR(n)
march = [[] for i in range(5)]
ch = list("MARCH")
for i in s:
    for j in range(5):
        if i[0] == ch[j]:
            march[j].append(i)
ans = 0
for i in range(5):
    for j in range(i):
        for k in range(j):
            if len(march[i])*len(march[j])*len(march[k]) == 0:
                break
            ans += len(march[i])*len(march[j])*len(march[k])
print(ans)

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

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

for i in range(N):
    if names[i][0]=='M':
        M+=1
    elif names[i][0]=='A':
        A+=1
    elif names[i][0]=='R':
        R+=1
    elif names[i][0]=='C':
        C+=1
    elif names[i][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 = [input() for _ in range(N)]

from itertools import combinations
c = list(combinations([i for i in range(5)],3))

cnt = [0]*6
for i in range(N):
    cnt["MARCH".find(S[i][0])] += 1

ans = 0
for (i,j,k) in c:
    ans += cnt[i]*cnt[j]*cnt[k]

print(ans)

Solution (Python):
import collections, itertools

n = int(input())
counter = collections.defaultdict(int)
for _ in range(n):
    s = input()
    counter[s[0]] += 1

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

print(ans)

Solution (Python):


from collections import Counter, defaultdict
import itertools


II = lambda: int(input())
MI = lambda: map(int, input().split())


def main():
    cnt = Counter()
    N = II()
    for _ in range(N):
        cnt[input()[0]] += 1

    ans = 0
    for c1, c2, c3 in itertools.combinations("MARCH", 3):
        ans += cnt[c1] * cnt[c2] * cnt[c3]
    return ans


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

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

dic={'M':0,'A':0,'R':0,'C':0,'H':0}
k = dic.keys()

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

from itertools import combinations

ans=0
for p,q,r in combinations(k,3):
    ans+=dic[p]*dic[q]*dic[r]

print(ans)

Solution (Python):
import itertools
import collections

n = int(input())
name = []
for i in range(n):
    a = input()
    if a[0] in 'MARCH':
        name.append(a[0])

b = collections.Counter(name)
d = []
for v in b.values():
    d.append(v)

c = list(itertools.combinations(list(range(len(b))), 3))

total = 0
for tap in c:
    total += d[tap[0]] * d[tap[1]] * d[tap[2]]
print(total)

Solution (Python):
import itertools
N=int(input())
S=[input() for _ in range(N)]
M=0
A=0
R=0
C=0
H=0
alives=0
march=['M','A','R','C','H']
for i in S:
    if i.startswith('M'):
        M+=1
    elif i.startswith('A'):
        A+=1
    elif i.startswith('R'):
        R+=1
    elif i.startswith('C'):
        C+=1
    elif i.startswith('H'):
        H+=1

if M==0:
    march.pop(march.index('M'))
if A==0:
    march.pop(march.index('A'))
if R==0:
    march.pop(march.index('R'))
if C==0:
    march.pop(march.index('C'))
if H==0:
    march.pop(march.index('H'))

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

seq=list(itertools.combinations(march,3))

ans=0
for i in seq:
    temp=1
    for ch in i:
        if ch=='M':
            temp*=M
        if ch=='A':
            temp*=A
        if ch=='R':
            temp*=R
        if ch=='C':
            temp*=C
        if ch=='H':
            temp*=H
    ans+=temp

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
alives=0
march=['M','A','R','C','H']
for i in S:
    if i.startswith('M'):
        M+=1
    elif i.startswith('A'):
        A+=1
    elif i.startswith('R'):
        R+=1
    elif i.startswith('C'):
        C+=1
    elif i.startswith('H'):
        H+=1

if M==0:
    march.pop(march.index('M'))
if A==0:
    march.pop(march.index('A'))
if R==0:
    march.pop(march.index('R'))
if C==0:
    march.pop(march.index('C'))
if H==0:
    march.pop(march.index('H'))

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

seq=list(itertools.combinations(march,3))

ans=0
for i in seq:
    temp=1
    for ch in i:
        if ch=='M':
            temp*=M
        if ch=='A':
            temp*=A
        if ch=='R':
            temp*=R
        if ch=='C':
            temp*=C
        if ch=='H':
            temp*=H
    ans+=temp

print(ans)

Solution (Python):
from collections import Counter
from itertools import combinations
N = int(input())
S = [input()[0] for _ in range(N)]
cnt = Counter(S)
ans = 0
for elem in combinations('MARCH', 3):
    ans += cnt[elem[0]]*cnt[elem[1]]*cnt[elem[2]]
print(ans)

Solution (Python):
import collections
def a():return input()
def ai():return int(input())
def ma():return map(int, input().split())
def ms():return map(str, input().split())
def lma():return list(map(int, input().split()))
def lms():return list(map(str, input().split()))
k= []
l = []
f = 0
def say(i):return print("Yes" if i == 0 else "No")
def Say(i):return print("YES" if i == 0 else "NO")

def addarray(k,l):
    for i in range(n):
        a ,b = map(int,input().split())
        w.append(b)
        v.append(a)
        
a = ai()
for i in range(a):
    b = input()
    if b[0] in ["M","A","R","C","H"]:
        k.append(b[0])
q = collections.Counter(k)
p = list(q.values())
if len(p)==3:
    print(p[0]*p[1]*p[2])
elif len(p)==4:
    print(p[0]*p[1]*p[2]+p[0]*p[1]*p[3]+p[0]*p[3]*p[2]+p[3]*p[1]*p[2])
elif len(p)==5:
    print(p[0]*p[1]*p[2]+p[0]*p[1]*p[3]+p[0]*p[1]*p[4]+p[0]*p[2]*p[3]
          +p[3]*p[0]*p[4]+p[1]*p[2]*p[3]+p[4]*p[1]*p[2]+p[3]*p[1]*p[4]
          +p[2]*p[3]*p[4]+p[0]*p[2]*p[4])
else:print(0)

Solution (Python):
import itertools

seq = ('M','A','R','C','H')
p = list(itertools.combinations(seq,3))
data = {'M':0,'A':0,'R':0,'C':0,'H':0}
sum = 0

N = int(input())
for i in range(N):
    a = input()
    if a[0] in data:
        data[a[0]] += 1


for i in p:
    sum += data[i[0]]*data[i[1]]*data[i[2]]

print(sum)

Solution (Python):


def main():
    N = int(input())
    MARCH = 'MARCH'
    count = [0 for i in range(5)]
    for i in range(N):
        s = input()
        if s[0] in MARCH:
            idx = MARCH.index(s[0])
            count[idx] += 1

    total = 0
    for i in range(5):
        for j in range(i + 1, 5):
            for k in range(j + 1, 5):
                total += count[i] * count[j] * count[k]

    print(total)


if __name__ == '__main__':
    main()

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())
m = 0
a = 0
r = 0
c = 0
h = 0
for i in range(N):
    s = list(str(input()))
    if s[0] == "M":
        m+=1
    elif s[0] == "A":
        a+=1
    elif s[0] == "R":
        r+=1
    elif s[0] == "C":
        c+=1
    elif s[0] == "H":
        h+=1
    else:
        pass
print(m*a*r+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())

l_march = [0] * 5
for _ in range(n):
    lin = input()
    initial = lin[0]
    if initial == 'M':
        l_march[0] += 1
    elif initial == 'A':
        l_march[1] += 1
    elif initial == 'R':
        l_march[2] += 1
    elif initial == 'C':
        l_march[3] += 1
    elif initial == 'H':
        l_march[4] += 1

l_march = (list)(filter(lambda x: x > 0, l_march))

len_l = len(l_march)
ans = 0


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

print(ans)

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

for i in range(n):
    S += input()[0]
    
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):
N = int(input())
S = []

m = a = r = c = h = 0
for _ in range(N):
    s = input()[0]

    if s == "M":
        m += 1
    elif s == "A":
        a += 1
    elif s == "R":
        r += 1
    elif s == "C":
        c += 1
    elif s == "H":
        h += 1
ans = 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())
m,a,r,c,h = 0,0,0,0,0
for i in range(n):
  o = input()[0]
  if o == "M":
    m += 1
  elif o == "A":
    a += 1
  elif o == "R":
    r += 1
  elif o == "C":
    c += 1
  elif o == "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):
import sys

N = int(input())



MARCH = ["M","A","R","C","H"]
MARCHn = {"M":0,"A":0,"R":0,"C":0,"H":0}
S = [0]*N
s = set()
n = 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):
    S[i] = str(input())
    initi = S[i][0]
    if(initi in MARCH):
        MARCHn[initi] = MARCHn[initi]+1
ans = 0
for i in range(10):
    ans += MARCHn[MARCH[P[i]]]*MARCHn[MARCH[Q[i]]]*MARCHn[MARCH[R[i]]]
print(ans)

Solution (Python):
n = int(input())
S = []
A = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}

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

for i in range(n):
    if S[i][0] in A:
        A[S[i][0]] += 1

m = A['M']
a = A['A']
r = A['R']
c = A['C']
h = A['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 = [0] * N
ans = 0
for i in range(N):
    s = input()
    if s[0] in ['M', 'A', 'R', 'C', 'H']:
        S[i] = s
S = list(set(S))
if 0 in S:
    S.remove(0)
march = [0] * 5
for i in S:
    if i[0] == 'M':
        march[0] += 1
    elif i[0] == 'A':
        march[1] += 1
    elif i[0] == 'R':
        march[2] += 1
    elif i[0] == 'C':
        march[3] += 1
    else:
        march[4] += 1

for i, j, k in list(itertools.combinations([0, 1, 2, 3, 4], 3)):
    ans += march[i] * march[j] * march[k]
print(ans)

Solution (Python):
n = int(input())
s = []
for i in range(n):
    s.append(input())
tmp_nums = {"M":0, "A":0, "R":0, "C":0, "H":0}
for i in range(n):
    if s[i][0] in tmp_nums.keys():
        tmp_nums[s[i][0]] += 1
nums=[]
for i in tmp_nums.values():
    nums.append(i)
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]
sum = 0
for i in range(10):
    sum += nums[p[i]]*nums[q[i]]*nums[r[i]]
print(sum)

Solution (Python):
n = input()
s = [raw_input().strip() for _ in xrange(n)]
dic = {'M':0,'A':0,'R':0,'C':0,'H':0}
for i in s:
	if i[0] in "MARCH":
		dic[i[0]] += 1
key = "MARCH"
ans = 0
for i in range(5):
	for j in range(i+1,5):
		for k in range(j+1,5):
			ans += (dic[key[i]]*dic[key[j]]*dic[key[k]])
print ans

Solution (Python):
n = int(input())
A = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}

for i in range(n):
    name = input()
    if name[0] in A:
        A[name[0]] += 1

m = A['M']
a = A['A']
r = A['R']
c = A['C']
h = A['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())
marchd = {'M':set(), 'A':set(), 'R':set(), 'C':set(), 'H':set(),}
for _ in range(N):
  s = input().strip()
  if s[0] in marchd:
    marchd[s[0]].add(s)

print(len(marchd['M'])*len(marchd['A'])*len(marchd['R']) +
      len(marchd['M'])*len(marchd['A'])*len(marchd['C']) +
      len(marchd['M'])*len(marchd['A'])*len(marchd['H']) +
      len(marchd['M'])*len(marchd['R'])*len(marchd['C']) +
      len(marchd['M'])*len(marchd['R'])*len(marchd['H']) +
      len(marchd['M'])*len(marchd['C'])*len(marchd['H']) +
      len(marchd['A'])*len(marchd['R'])*len(marchd['C']) +
      len(marchd['A'])*len(marchd['R'])*len(marchd['H']) +
      len(marchd['A'])*len(marchd['C'])*len(marchd['H']) +
      len(marchd['R'])*len(marchd['C'])*len(marchd['H']))

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

for i in range(n):
    a = input()
    A += a[0]

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

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

Solution (Python):
from itertools import combinations
n = int(input())
march = dict()
for i in "MARCH":
    march[i] = 0
for i in range(n):
    s = input()[0]
    if s in march:
        march[s] += 1


ans = 0
for v in combinations(list("MARCH"), 3):
    tmp = 1
    for c in v:
        tmp *= march[c]
    ans += tmp

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
sum_ = 0
sum_ += m*a*r
sum_ += m*a*c
sum_ += m*a*h
sum_ += m*r*c
sum_ += m*r*h
sum_ += m*c*h
sum_ += a*r*c
sum_ += a*r*h
sum_ += a*c*h
sum_ += r*c*h
print(sum_)

Solution (Python):
n = int(input())
count = [0 for _ in range(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

sum = 0
for i in range(5):
    for j in range(5):
        for k in range(5):
            if i==j or j==k or k==i:
                continue
            elif i < j and j < k:
                sum += count[i]*count[j]*count[k]

print(sum)

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

for i in range(N):
    if S[i][0] == "M":
        march[0] += 1
    if S[i][0] == "A":
        march[1] += 1
    if S[i][0] == "R":
        march[2] += 1
    if S[i][0] == "C":
        march[3] += 1
    if S[i][0] == "H":
        march[4] += 1
ans = 0
for i in range(5):
    for j in range(i+1, 5):
        for k in range(j+1, 5):
            ans += march[i] * march[j] * march[k]
print(ans)

Solution (Python):
import itertools
N = input()
S = [raw_input() for _ in range(N)]
nums = {}
for s in S:
    initial = s[0]
    if not initial in nums:
        nums[initial] = 1
    else:
        nums[initial] += 1

res = 0
for a, b, c in itertools.combinations('MARCH', 3):
    if a not in nums or b not in nums or c not in nums:
        continue
    res += nums[a] * nums[b] * nums[c]
print res

Solution (Python):


import itertools
from collections import defaultdict


N = int(input())

D = defaultdict(int)
for _ in range(N):
    S = input()[0]
    D[S] += 1

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

print(ans)

Solution (Python):
def main():
    n = int(input())
    to_i = {c: i for i, c in enumerate('MARCH')}
    counts = [0] * 5
    for _ in range(n):
        c = input()[0]
        if c in to_i:
            counts[to_i[c]] += 1
    res = 0
    for i in range(0, 5):
        for j in range(i + 1, 5):
            for k in range(j + 1, 5):
                res += counts[i] * counts[j] * counts[k]
    print(res)


if __name__ == '__main__':
    main()

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

Solution (Python):

import itertools
ans=0
n=int(input())
ls=["M","A","R","C","H"]

S = [input() for _ in range(n)]




march={i:0 for i in ls}
for s in S:
  if s[0] in ls:
    march[s[0]]+=1


for i,j,k in itertools.combinations(ls,3):
  ans+=march[i]*march[j]*march[k]
print(ans)

Solution (Python):
from collections import Counter
import itertools
ans=0
n=int(input())
ls=["M","A","R","C","H"]
S=Counter([i for i in list(map(lambda x:x[0] ,[input() for i in range(n)])) if i in ls])

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

Solution (Python):
n=int(input())
a=[0]*5
for i in range(n):
    d=input()
    if d[0] == 'M':
        a[0] += 1
    elif d[0] == 'A':
        a[1] += 1
    elif d[0] == 'R':
        a[2] += 1
    elif d[0] == 'C':
        a[3] += 1
    elif d[0] == 'H':
        a[4] += 1
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):
N=int(input())
A=""
for i in range(N):
    k=input()
    A+=k[0]
m=A.count("M")
a=A.count("A")
r=A.count("R")
c=A.count("C")
h=A.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):
n = int(input())
l_ = [["M", 0], ["A", 0], ["R", 0], ["C", 0], ["H", 0]]
l = []

for i in range(n):
    s = input()

    for j in l_:
        if s[0] == j[0]:
            j[1] += 1
            break

for i in l_:
    if i[1] != 0:
        l.append(i[1])

k = len(l)
r = 0

if k < 3:
    r = 0
elif k == 3:
    r = l[0] * l[1] * l[2]
elif k == 4:
    for i in range(1,5):
        r += l[i%4] * l[i%3] * l[i%2]
elif k == 5:
    p = 1
    for i in range(5):
        p *= l[i]
    for i in range(4, -1, -1):
        for j in range(5):
            if i == j:
                break
            r += p / (l[i] * l[j])

print(int(r))

Solution (Python):
import itertools


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

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

Solution (Python):
N = int(input())
name = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
for i in range(N):
  S = input()
  if S[0] in 'MARCH':
    name[S[0]] += 1
cnt = 0
for k1, v1 in name.items():
  for k2, v2 in name.items():
    for k3, v3 in name.items():
      if k1 != k2 and k2 != k3 and k3 != k1:
        cnt += v1 * v2 * v3
print(cnt // 6)

Solution (Python):
import itertools as it
def main() :
    N = int(input())
    S_list = [input() for s in range(N)]
    dic_counts = {"M" : 0, "A" : 0, "R" : 0, "C" : 0, "H" : 0}
    li = ["M","A","R","C","H"]
    combi = list(it.combinations(li,3))

    for s in S_list :
        for key in dic_counts.keys() :
            if (s[0] == key) :
                dic_counts[key] += 1

    sum = 0
    for item in combi :
        sum += dic_counts[item[0]] * dic_counts[item[1]] * dic_counts[item[2]]
    
    print(sum)


main()

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

Solution (Python):
import itertools

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

march = {i: 0 for i in H}
for s in S:
    if s[0] in H:
        march[s[0]] += 1

ans = 0
for i, j, k in itertools.combinations(H, 3):
    ans += march[i] * march[j] * march[k]

print(ans)

Solution (Python):

n = int(input())
s = []
for i in range(n):
    s.append(input()[0])
li = ['M', 'A', 'R', 'C', 'H']
ans = 0
for _ in range(5):
    a = li.pop()
    li2 = li.copy()
    if a in s:
        for _ in range(len(li)):
            b = li2.pop()
            if b in s:
                for c in li2:
                    ans += s.count(a) * s.count(b) * s.count(c)
print(ans)

Solution (Python):
N = int(input())
S = [0,0,0,0,0]
for i in range(N):
    st = input()
    if st[0] == "M":
        S[0] += 1
        continue
    elif st[0] == "A":
        S[1] += 1
        continue
    elif st[0] == "R":
        S[2] += 1
        continue
    elif st[0] == "C":
        S[3] += 1
        continue
    elif st[0] == "H":
        S[4] += 1
        continue

L = [(0,1,2),(0,1,3),(0,1,4),(0,2,3),(0,2,4),(0,3,4),(1,2,3),(1,2,4),(1,3,4),(2,3,4)]
res = 0
for i,j,k in L:
    res += S[i]* S[j] *S[k]

print(res)

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

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

Solution (Python):
import itertools

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

answer = 0
for a,b,c in itertools.combinations(list('MARCH'), 3):
  answer += cnts[a] * cnts[b] * cnts[c]

print(answer)

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

Solution (Python):
from collections import defaultdict
nametag = defaultdict(lambda: 0)
N = int(input())
for _ in range(N):
    s = input()
    if s[0] == 'M':
        nametag['M'] += 1
    if s[0] == 'A':
        nametag['A'] += 1
    if s[0] == 'R':
        nametag['R'] += 1
    if s[0] == 'C':
        nametag['C'] += 1
    if s[0] == 'H':
        nametag['H'] += 1
ans = 0
march = list(nametag.keys())
for i in march:
    for j in march:
        for k in march:
            if i == k or j == k or i == j:
                continue
            ans += nametag[i]*nametag[j]*nametag[k]
print(ans//6)

Solution (Python):
n = int(input())
arr = []
for i in range(n):
    arr += [list(input())]

MARCH = [0] * 5    
    
for j in range(n):
    if arr[j][0] == 'M':
        MARCH[0] += 1
    elif arr[j][0] == 'A':
        MARCH[1] += 1
    elif arr[j][0] == 'R':
        MARCH[2] += 1
    elif arr[j][0] == 'C':
        MARCH[3] += 1
    elif arr[j][0] == 'H':
        MARCH[4] += 1

def C(a,b):
    aa = 1
    bb = 1
    for k in range(a-b+1, a+1):
        aa *= k
    for l in range(1, b+1):
        bb *= l
    return int(aa/bb)
        
ans = C(sum(MARCH), 3)

for m in range(5):
    if MARCH[m] == 2:
        ans -= C(sum(MARCH)-MARCH[m],1)
    elif MARCH[m] >= 3:
        ans -= C(MARCH[m],2) * C(sum(MARCH)-MARCH[m],1)
        ans -= C(MARCH[m],3)

print(ans)

Solution (Python):
n = int(input())
a = [input() for i in range(n)]
d = {"M": [], "A": [], "R":[], "C":[], "H":[]}
for i in range(n):
    if a[i][0] in ("M", "A", "R", "C", "H"):
        d[a[i][0]].append(a[i])
n1 = len(d["M"])
n2 = len(d["A"])
n3 = len(d["R"])
n4 = len(d["C"])
n5 = len(d["H"])
print(n1*n2*(n3+n4+n5) + n1*n3*(n4+n5) + n1*n4*n5 + n2*n3*(n4+n5) + n2*n4*n5 + n3*n4*n5)

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

print(ans)

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

M_list = []
A_list = []
R_list = []
C_list = []
H_list = []

for name in name_list:
    if name[0:1] == 'M':
        M_list.append(name)
    elif name[0:1] == 'A':
        A_list.append(name)
    elif name[0:1] == 'R':
        R_list.append(name)
    elif name[0:1] == 'C':
        C_list.append(name)
    elif name[0:1] == 'H':
        H_list.append(name)

M = len(M_list)
A = len(A_list)
R = len(R_list)
C = len(C_list)
H = len(H_list)

def cal(x,y,z):
    return x*y*z

print(cal(M,A,R)+cal(M,A,C)+
      cal(M,A,H)+cal(M,R,C)+
      cal(M,R,H)+cal(M,C,H)+
      cal(A,R,C)+cal(A,R,H)+
      cal(A,C,H)+cal(R,C,H))

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

M_list = []
A_list = []
R_list = []
C_list = []
H_list = []

for name in name_list:
    if name[0:1] == 'M':
        M_list.append(name)
    elif name[0:1] == 'A':
        A_list.append(name)
    elif name[0:1] == 'R':
        R_list.append(name)
    elif name[0:1] == 'C':
        C_list.append(name)
    elif name[0:1] == 'H':
        H_list.append(name)

M = len(M_list)
A = len(A_list)
R = len(R_list)
C = len(C_list)
H = len(H_list)

def cal(x,y,z):
    return x*y*z

print(cal(M,A,R)+cal(M,A,C)+
      cal(M,A,H)+cal(M,R,C)+
      cal(M,R,H)+cal(M,C,H)+
      cal(A,R,C)+cal(A,R,H)+
      cal(A,C,H)+cal(R,C,H))

Solution (Python):
import itertools
N = int(input())
a = [0] * 5
for _ in range(N):
    s = input()[0]
    if s == 'M':
        a[0] += 1
    elif s == 'A':
        a[1] += 1
    elif s == 'R':
        a[2] += 1
    elif s == 'C':
        a[3] += 1
    elif s == 'H':
        a[4] += 1
count = 0
for i, j, k in itertools.combinations(range(5), 3):
    count += a[i] * a[j] * a[k]
print(count)

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

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

print(res)

Solution (Python):
N = int(input())
S = [input() for _ in range(N)]
array1 = ['M', 'A', 'R', 'C', 'H']
array2 = [[] for _ in range(5)]

for i in S:
    if i[0] in array1:
        array2[array1.index(i[0])].append(i)

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

print(result)

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

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

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