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 itertools

s = ["M","A","R","C","H"]

p = list(itertools.combinations(s,3))

dict ={"M":0,"A":0,"R":0,"C":0,"H":0}
n = input()
n = int(n)
names = []
for i in range(n):
        names.append(input())
for i in range(n):
        if names[i][0] in s:
                dict[names[i][0]] += 1
total_sum = 0
for part in p:
        sum = 1
        for j in range(3):
                sum *= dict[part[j]]
        total_sum += sum
print(total_sum)

Solution (Python):
n = int(input().strip())
s = [input().strip() for _ in range(n)]
num_m = len([True for _s in s if _s[0] == "M"])
num_a = len([True for _s in s if _s[0] == "A"])
num_r = len([True for _s in s if _s[0] == "R"])
num_c = len([True for _s in s if _s[0] == "C"])
num_h = len([True for _s in s if _s[0] == "H"])
print(num_m * num_a * num_r + num_m * num_a * num_c + num_m * num_a * num_h + num_m * num_r * num_c
      + num_m * num_r * num_h + num_m * num_c * num_h + num_a * num_r * num_c +
      num_a * num_r * num_h + num_a * num_c * num_h + num_r * num_c * num_h)

Solution (Python):
import itertools

N = int(input())

Ss = ['M', 'A', 'R', 'C', 'H']
I = set(['M', 'A', 'R', 'C', 'H'])
D = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
l = []
for i in range(N):
    S = str(input())
    s = S[0]
    if (s in I):
        D[s] = D[s]+1

cmbs = itertools.combinations(Ss, 3)

p = 0
for cmb in cmbs:
    i,j,k = cmb
    if (D[i] == 0 or D[j] == 0 or D[k] == 0):
        continue
    else:
        p += D[i] * D[j] * D[k]

k = 0
for _,j in D.items():
    if j != 0:
        k += 1

if k < 3:
    print(0)
else:
    print(int(p))

Solution (Python):
import sys
n=int(input())
s=[input()[0] for i in range(n)]
m,a,r,c,h=0,0,0,0,0
for i in range(n):
    if s[i]=="M": m+=1
    elif s[i]=="A": a+=1
    elif s[i]=="R": r+=1
    elif s[i]=="C": c+=1
    elif s[i]=="H": h+=1
t=sorted([m,a,r,c,h])
q,w,e,r,u=0,0,0,0,0
if t[2]==0:
    print(0)
    sys.exit()
if t[1]==0:
    print(t[2]*t[3]*t[4])
    sys.exit()
if t[0]==0:
    q,w,e,r=t[1],t[2],t[3],t[4]
    print(q*w*e+q*w*r+q*e*r+w*e*r)
    sys.exit()
else:
    q,w,e,r,u=t[0],t[1],t[2],t[3],t[4]
    x=q*w*e+q*w*r+q*w*u+q*e*r+q*e*u+q*r*u
    y=w*e*r+w*e*u+w*r*u+e*r*u
    print(x+y)

Solution (Python):

import itertools

def comb1(n, r):
    if n == 0 or r == 0: return 1
    return comb1(n, r-1) * (n-r+1) / r

a = int(input())

m_members = []
a_members = []
r_members = []
c_members = []
h_members = []

for i in range(a):
    member = input()
    if(member[0:1] == 'M'):
        m_members.append(member)
    elif(member[0:1] == 'A'):
        a_members.append(member)
    elif(member[0:1] == 'R'):
        r_members.append(member)
    elif(member[0:1] == 'C'):
        c_members.append(member)
    elif(member[0:1] == 'H'):
        h_members.append(member)

member_info = []
count = 0
result = 0

if(len(m_members) != 0):
    member_info.append(len(m_members))
    count += 1
if(len(a_members) != 0):
    member_info.append(len(a_members))
    count += 1
if(len(r_members) != 0):
    member_info.append(len(r_members))
    count += 1
if(len(c_members) != 0):
    member_info.append(len(c_members))
    count += 1
if(len(h_members) != 0):
    member_info.append(len(h_members))
    count += 1

if(count >= 3):
    for i in (list(itertools.combinations(member_info, 3))):
        result += i[0] * i[1] * i[2]
    print(result)
else:
    print(0)

Solution (Python):
import itertools
N = int(input())
out = 0
num = [0, 0, 0, 0, 0]
for i in range(N):
    name = list(input())
    if name[0] == "M":
        num[0] = num[0] + 1
    elif name[0] == "A":
        num[1] = num[1] + 1
    elif name[0] == "R":
        num[2] = num[2] + 1
    elif name[0] == "C":
        num[3] = num[3] + 1
    elif name[0] == "H":
        num[4] = num[4] + 1
b = 0
e = ()
for n in range(5):
    if num[n] == 0:
        b +=1
    else:
        e += (n,)
if  b >= 3:
    print(0)
else:
    combi = list(itertools.combinations(e,3))
    for c in combi:
        out += num[c[0]]*num[c[1]]*num[c[2]]
    print(out)

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

nm = 0
na = 0
nr = 0
nc = 0
nh = 0

for i in range(n):
    a = input()
    for j in a:
        b = j
        break
    if b == "M":
        nm += 1
    elif b == "A":
        na += 1
    elif b == "R":
        nr += 1
    elif b == "C":
        nc += 1
    elif b == "H":
        nh += 1

count = 0

count += nm * na * nr
count += nm * na * nc
count += nm * na * nh
count += nm * nr * nc
count += nm * nr * nh
count += nm * nc * nh
count += na * nr * nc
count += na * nr * nh
count += na * nc * nh
count += nr * nc * nh

print(count)

Solution (Python):
import itertools
n = int(input())
s = []
c=0
for i in range(n):
    s.append(input()[0])
seq = list(itertools.combinations(["M","A","R","C","H"],3))
for l in seq:
    c += s.count(l[0])*s.count(l[1])*s.count(l[2])
print(c)

Solution (Python):
def conb(a, b):
    ans = 1
    for i in range(b):
        ans *= (a - i)
        ans /= (i + 1)
    return ans
    
A = {"M":0, "A":0, "R":0, "C":0, "H":0}
N = int(input())
S = [input() for i in range(N)]
S = [c for c in S if c[0] in A]
for c in S:
    A[c[0]] += 1

N = len(S)
if N >= 3:
    zen = conb(N , 3)
    for a in A:
        a = A[a]
        if a > 2:
            zen -= (conb(a, 3) + conb(a, 2) * (N - a))
        elif a > 1:
            zen -= (N - a)
else:
    zen = 0
print(int(zen))

Solution (Python):
N = int(input())
S = [str(input()) for i in range(N)]
S_head = []
for i in S:
    S_head.append(i[:1])
M_num = S_head.count("M")
A_num = S_head.count("A")
R_num = S_head.count("R")
C_num = S_head.count("C")
H_num = S_head.count("H")
ans = M_num*A_num*R_num + M_num*A_num*C_num + M_num*A_num*H_num +\
      M_num*R_num*C_num + M_num*R_num*H_num + M_num*C_num*H_num +\
      A_num*R_num*C_num + A_num*R_num*H_num + A_num*C_num*H_num +\
      R_num*C_num*H_num
print(ans)

Solution (Python):
from math import *
from itertools import combinations

n = int(input())
s = [input() for _ in range(n)]
s = list(map(lambda x: x[0], s))
s = list(filter(lambda x: x in 'MARCH', s))
t = {}
for x in range(len(s)):
  if s[x] in t: t[s[x]] += 1
  else: t[s[x]] = 1
t = list(t.values())
a = 0
for c in combinations(t, 3):
  m = 1
  for e in c:
    m *= e
  a += m
print(a)

Solution (Python):
N=int(input())
M=[]
A=[]
R=[]
C=[]
H=[]
for i in range(N):
  s=input()
  if s[0]=='M':
    M.append(s)
  elif s[0]=='A':
    A.append(s)
  elif s[0]=='R':
    R.append(s)
  elif s[0]=='C':
    C.append(s)
  elif s[0]=='H':
    H.append(s)
cnt=[len(M),len(A),len(R),len(C),len(H)]
res=sum(cnt)
res=int(res*(res-1)*(res-2)/6)

def dif(n):
  if cnt[n]==0 or cnt[n]==1:
    return 0
  else:
    a=0
    for i in range(5):
      if i!=n:
        a+=cnt[i]
  if cnt[n]==2:
    return a
  else:
    b=cnt[n]*(cnt[n]-1)*(cnt[n]-2)/6
    d=cnt[n]*(cnt[n]-1)/2
    d*=a
    return int(d+b)
for i in range(5):
  res-=dif(i)
c=0
for j in range(5):
  if cnt[j]==0:
    c+=1
if c>2:
  print(0)
else:
  print(res)

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

m = [[] for _ in range(5)]
for i in range(n):
    if s[i][:1] == "M":
        m[0].append(s[i])
    elif s[i][:1] == "A":
        m[1].append(s[i])
    elif s[i][:1] == "R":
        m[2].append(s[i])
    elif s[i][:1] == "C":
        m[3].append(s[i])
    elif s[i][:1] == "H":
        m[4].append(s[i])
    else:
        pass
    
for i in range(5):
    m[i] = len(list(set(m[i])))

print(m[0] * m[1] * m[2] + m[0] * m[1] * m[3] + m[0] * m[1] * m[4] + m[0] * m[2] * m[3] + m[0] * m[2] * m[4] + m[0] * m[3] * m[4] + m[1] * m[2] * m[3] + m[1] * m[2] * m[4] + m[1] * m[3] * m[4] + m[2] * m[3] * m[4])

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

ans = 0
for i in range(5):
    for j in range(5):
        if(i == j):
            break
        for k in range(5):
            if(j == k):
                break
            ans += s[i] * s[j] * s[k]
print(ans)

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

M = 0
A = 0
R = 0
C = 0
H = 0
res = 0
for s in S:
    if s[0] == 'M':
        M += 1
    elif s[0] == 'A':
        A += 1
    elif s[0] == 'R':
        R += 1
    elif s[0] == 'C':
        C += 1
    elif s[0] == 'H':
        H += 1

for m in range(2):
    for a in range(2):
        for r in range(2):
            for c in range(2):
                for h in range(2):
                    if m+a+r+c+h == 3:
                        temp = 1
                        if m == 1:
                            temp *= M
                        if a == 1:
                            temp *= A
                        if r == 1:
                            temp *= R
                        if c == 1:
                            temp *= C
                        if h == 1:
                            temp *= H
                        res += temp
                            
print(res)

Solution (Python):
from collections import Counter
from math import factorial
N = int(input())
S = [input()[0:1:] for i in range(N)]

march = ["M","A","R","C","H"]
list = []
c = Counter(S)
for k,v in c.items():
    if k in march:
        list.append(v)

ans = 0
if len(list) >= 3:
    for i in range(len(list)):
        for j in range(len(list)-1):
            for k in range(len(list)-2):
                if (i != j+1) and (j+1 != k+2) and (k+2 != i) and (i<j+1) and (j<k+1):
                    ans += list[i] * list[j+1] * list[k+2]

print(ans)

Solution (Python):

"""
C - March
https://beta.atcoder.jp/contests/abc089/tasks/abc089_c

"""
import sys
from sys import stdin
from itertools import combinations
input = stdin.readline


def main(args):
    N = int(input())
    names = dict()
    for _ in range(N):
        tmp = input().strip()
        if not tmp in names:
            if tmp[0] in 'MARCH':
                names[tmp] = 1

    m_names = [0] * 5
    for k, v in names.items():
        if k[0] == 'M':
            m_names[0] += 1
        elif k[0] == 'A':
            m_names[1] += 1
        elif k[0] == 'R':
            m_names[2] += 1
        elif k[0] == 'C':
            m_names[3] += 1
        elif k[0] == 'H':
            m_names[4] += 1

    if len(names) < 3:
        print(0)
    else:
        ans = 0
        for c in combinations(m_names, 3):
            t = c[0] * c[1] * c[2]
            ans += t
        print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):
from collections import Counter
N=int(input())
X=[]
for i in range(N):
    X.append(input())
Y=[X[i][0] for i in range(N)]
c = Counter(Y)
count=0
count=c.get('M',0)*c.get('A',0)*c.get('R',0)+ c.get('M',0)*c.get('A',0)*c.get('C',0)+ c.get('M',0)*c.get('A',0)*c.get('H',0)+ c.get('M',0)*c.get('R',0)*c.get('C',0)+\
      c.get('M',0)*c.get('R',0)*c.get('H',0)+ c.get('M',0)*c.get('C',0)*c.get('H',0)+ c.get('A',0)*c.get('R',0)*c.get('C',0)+ c.get('A',0)*c.get('R',0)*c.get('H',0)+\
      c.get('A',0)*c.get('C',0)*c.get('H',0)+ c.get('R',0)*c.get('C',0)*c.get('H',0)
print(count)

Solution (Python):
N = int(input())
S = []
for i in range(N):
    S.append(str(input()))
    
from collections import Counter
import numpy as np
import itertools
initial = np.array([list(i)[0] for i in S])

counter = Counter(initial)
iflist = np.array(["M","A","R","C","H"])
num = []
for word, cnt in counter.most_common():
    if any(word == iflist):
        num.append(cnt)
        
ans = 0
for i in itertools.combinations(num,3):
    ans += np.array(i).prod()
    
print(ans)

Solution (Python):



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

Solution (Python):
from collections import Counter
import itertools
n = int(input())
march = Counter()
is_march = ['M', 'A', 'R', 'C', 'H']
for i in range(n):
    head = input()[0]
    if head in is_march:
        march[head] += 1
ans = 0
for c in itertools.combinations(march.keys(), 3):
    t = 1
    for x in c:
        t *= march[x]
    ans += t
print(int(ans))

Solution (Python):
import sys

N=int(raw_input())
list_S=[raw_input() for i in range(N)]

list_MARCH=["M", "A", "R", "C", "H"]
list_only_MARCH=[i for i in list_S if i[0] in list_MARCH]

num_MARCH=len(list_only_MARCH)
list_num=[0, 0, 0, 0, 0]
for i in list_only_MARCH:
  if   i[0]=="M": list_num[0]=list_num[0]+1
  elif i[0]=="A": list_num[1]=list_num[1]+1
  elif i[0]=="R": list_num[2]=list_num[2]+1
  elif i[0]=="C": list_num[3]=list_num[3]+1
  elif i[0]=="H": list_num[4]=list_num[4]+1

ans_num=num_MARCH*(num_MARCH-1)*(num_MARCH-2)/6
if ans_num==0:
  print 0
  sys.exit()

for i in list_num:
  if i==2: ans_num=ans_num-(num_MARCH-2)
  elif i>=3:
    ans_num=ans_num-(i*(i-1)*(i-2)/6)
    ans_num=ans_num-((num_MARCH-i)*i*(i-1)/2)

print ans_num

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

list_pop = [0] * 5
for i in range(N):
    s = input()
    if list(s)[0] == 'M':
        list_pop[0] += 1
    if list(s)[0] == 'A':
        list_pop[1] += 1
    if list(s)[0] == 'R':
        list_pop[2] += 1
    if list(s)[0] == 'C':
        list_pop[3] += 1
    if list(s)[0] == 'H':
        list_pop[4] += 1




answer = 0
for i in range(3):
    for j in range(4)[i+1:]:
        for k in range(5)[j+1:]:
            answer += list_pop[i] * list_pop[j] * list_pop[k]
    
    
print(int(answer))

Solution (Python):
import itertools
import operator

def product(iterable):
    return reduce(operator.mul, iterable, 1)

def main():
    n = int(raw_input())
    table = dict((c, 0) for c in 'MARCH')

    for _ in xrange(n):
        s = raw_input()
        if s[0] in table:
            table[s[0]] += 1

    m = 0
    for comb in itertools.combinations('MARCH', 3):
        m += product(table[c] for c in comb)
    print m

main()

Solution (Python):
import itertools
from collections import Counter

L=['M','A','R','C','H']
N=int(input())
a =[input()[0] for i in range(N)]
A=dict(Counter([x for x in a if x in L]))

res = list(map(dict, itertools.combinations(A.items(), 3)))

ans=0
for r in res:
	tmp=1
	for k in r.values():
		tmp*=k
	ans+=tmp
print(ans)

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

print(S["M"] * S["A"] * (S["R"] + S["C"] + S["H"])
      + S["M"] * S["R"] * (S["C"] + S["H"])
      + S["M"] * S["C"] * S["H"]
      + S["A"] * S["R"] * (S["C"] + S["H"])
      + S["A"] * S["C"] * S["H"]
      + S["R"] * S["C"] * S["H"])

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

name_capital = {
    'M': 0,
    'A': 0,
    'R': 0,
    'C': 0,
    'H': 0,
}
name_list = ['M', 'A', 'R', 'C', 'H']
for _ in range(N):
    name = input()
    for word in name_list:
        if name[0] == word:
            name_capital[word] += 1
            break

nv = list(name_capital.values())
N2 = len(nv)
answer = 0
for i in range(N2-2):
    for j in range(i+1, N2-1):
        for k in range(j+1, N2):
            answer += nv[i] * nv[j] * nv[k]

print(answer)

Solution (Python):
import numpy as np
num=int(input())

arr=np.zeros(5)


for i in range(num):
    chara=list(input())[0]
    if chara == "M":
        arr[0]+=1
    if chara == "A":
        arr[1]+=1
    if chara == "R":
        arr[2]+=1
    if chara == "C":
        arr[3]+=1
    if chara == "H":
        arr[4]+=1

ans=0
for i in range(3):
    for k in range(3-i):
        for j in range(3-k-i):
            ans+=arr[i]*arr[1+i+k]*arr[2+i+k+j]
            
print(int(ans))

Solution (Python):
def ACBC_089_C():
    _num = int(input())
    _namelist = []
    _countM = 0
    _countA = 0
    _countR = 0
    _countC = 0
    _countH = 0

    for i in range(0, _num):
        _name = str(input())
        _namelist.append(_name)
        if _name[0] == "M":
            _countM += 1
        elif _name[0] == "A":
            _countA += 1
        elif _name[0] == "R":
            _countR += 1
        elif _name[0] == "C":
            _countC += 1
        elif _name[0] == "H":
            _countH += 1
    print(_countM * _countA * _countR + \
          _countM * _countA * _countC + \
          _countM * _countA * _countH + \
          _countM * _countR * _countC + \
          _countM * _countR * _countH + \
          _countM * _countC * _countH + \
          _countA * _countR * _countC + \
          _countA * _countR * _countH + \
          _countA * _countC * _countH + \
          _countR * _countC * _countH)


ACBC_089_C()

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

Solution (Python):
import numpy as np
import scipy as sp
from collections import Counter

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

a = Counter(S)

num = list(a.values())

l = len(num)
s = 0
for i in range(l-2):
    for j in range(i+1,l-1):
        for k in range(j+1,l):
            s += num[i] * num[j] * num[k]
print(s)

Solution (Python):
import itertools

N = int(input())

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

vs = num.values()

ans = 0
for a, b, c in itertools.combinations(vs, 3):
    ans += a * b * c

print(ans)

Solution (Python):



import collections
import itertools


def solve(names):
    ctr = collections.Counter(name[0] for name in names)
    res = 0
    for x, y, z in itertools.combinations("MARCH", 3):
        res += ctr[x] * ctr[y] * ctr[z]
    return res


def main():
    names = [input() for _ in range(int(input()))]
    print(solve(names))


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
b = []
c = []
answer = 0
for i in range(0,5):
    c.append(int(0))
for i in range(0,n):
    b.append(input())
for i in range(0,n):
    if b[i][0] == 'M':
        c[0] += 1
    else:
        if b[i][0] == 'A':
            c[1] += 1
        else:
            if b[i][0] == 'R':
                c[2] += 1
            else:
                if b[i][0] == 'C':
                    c[3] += 1
                else:
                    if b[i][0] == 'H':
                        c[4] += 1
for i in range(0,3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            answer += c[i]*c[j]*c[k]
print(answer)

Solution (Python):
N=int(input())
M,A,R,C,H=0,0,0,0,0
S=""
for i in range(N):
    S=input()
    if S[0]=="M":
        M+=1
        continue
    if S[0]=="A":
        A+=1
        continue
    if S[0]=="R":
        R+=1
        continue
    if S[0]=="C":
        C+=1
        continue
    if S[0]=="H":
        H+=1
        continue
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 sys
import os
import time
import re
from pydoc import help
import string
import math
import numpy as np
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools
sys.setrecursionlimit(10**7)
inf = 10**20
gosa = 1.0 / 10**10
mod = 10**9+7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]



def solve():
    N = int(input())

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

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

    print(res)

if __name__ == "__main__":
    solve()

Solution (Python):
def c_march(N, S):
    from collections import defaultdict
    from itertools import combinations
    import math
    count = defaultdict(int)
    for s in S:
        if s[0] in 'MARCH':
            count[s[0]] += 1
    kind = len(count)
    ans = 0
    if len(count) <= 2:
        return 0
    else:
        ans = 0
        s = ''
        for k, v in count.items():
            s += k
        string = combinations(s, 3)
        for s in string:
            tmp = 1
            for c in s:
                tmp *= count[c]
            ans += tmp
    return ans

N = int(input())
S = [input().strip() for _ in range(N)]
print(c_march(N, S))

Solution (Python):
import sys,collections;sys.setrecursionlimit(10**7)
import itertools
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

n = I()
d = collections.defaultdict(int)
for _ in range(n):
    s = S()[0]
    if list("MARCH").count(s) > 0:
        d[s] += 1
if len(d) < 3:
    print(0)
    exit()
c = list(itertools.combinations(d.items(),3))
sum = 0
for e in c:
    sum += e[0][1]*e[1][1]*e[2][1]
print(sum)

Solution (Python):
from collections import defaultdict
if __name__ == "__main__":
    dic = defaultdict(int)
    N = int(input())
    for i in range(N):
        S = input()
        if S[0] in "M A R C H":
            dic[S[0]] += 1
    res = []
    if len(dic) < 3:
        print(0)
        exit(0)
    value = 1
    for key in dic:
        val = dic[key]
        res.append(val)
        value *= val
    if len(dic) == 3:
        print(value)
        exit(0)
    result = 0
    if len(dic) == 4:
        for i in res:
            result += value // i
    if len(dic) == 5:
        for i in range(len(res)):
            for j in range(i + 1, len(res)):
                result += value // (res[i] * res[j])
    print(result)

Solution (Python):
import itertools

def name_count(names):
    counter = [0,0,0,0,0]
    capitals = ["M", "A", "R", "C", "H"]
    for name in names:
        for i in range(5):
            if name[0] == capitals[i]:
                counter[i] += 1
    return counter
    
n = int(input())

names = [""  for i in range(n)]
for i in range(n):
    names[i] = input()

name_counter = name_count(names)

cnt = 0
for comb in itertools.combinations(range(5), 3):
    temp = 1
    for i in comb:
        temp *= name_counter[i]
    cnt += temp

print(cnt)

Solution (Python):
n = int(input())
h = [0 for _ in range(5)]

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

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

print(ans)

Solution (Python):
if __name__ == "__main__":
    N = int(input())
    M = []
    A = []
    R = []
    C = []
    H = []
    for i in range(N):
        buf = str(input())
        if buf[0] == 'M':
            M.append(buf)
        elif buf[0] == 'A':
            A.append(buf)
        elif buf[0] == 'R':
            R.append(buf)
        elif buf[0] == 'C':
            C.append(buf)
        elif buf[0] == 'H':
            H.append(buf)
    M_cnt = len(M)
    A_cnt = len(A)
    R_cnt = len(R)
    C_cnt = len(C)
    H_cnt = len(H)

    cnt =  M_cnt * A_cnt * R_cnt + \
           M_cnt * A_cnt * C_cnt + \
           M_cnt * A_cnt * H_cnt + \
           M_cnt * R_cnt * C_cnt + \
           M_cnt * R_cnt * H_cnt + \
           M_cnt * C_cnt * H_cnt + \
           A_cnt * R_cnt * C_cnt + \
           A_cnt * R_cnt * H_cnt + \
           A_cnt * C_cnt * H_cnt + \
           R_cnt * C_cnt * H_cnt
    print(cnt)

Solution (Python):

N = int(input())

ans = 0
m = 0
a = 0
r = 0
c = 0
h = 0
mb = False
ab = False
rb = False
cb = False
hb = False

for i in range(N):
    s = input()
    if s[0] == 'M':
        m += 1
        mb = True
    if s[0] == 'A':
        a += 1
        ab = True
    if s[0] == 'R':
        r += 1
        rb = True
    if s[0] == 'C':
        c += 1
        cb = True
    if s[0] == 'H':
        h += 1
        hb = True

num = 0
if mb:
    num += 1
if ab:
    num += 1
if rb:
    num += 1
if cb:
    num += 1
if hb:
    num += 1

if num < 3:
    print(0)
else:
    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*c*h
    ans += a * r * h
    ans += r*c*h

    print(ans)

Solution (Python):
import itertools
from collections import defaultdict

if __name__ == '__main__':
    n = int(input())
    names = [input() for _ in range(n)]

    first_char_dict = defaultdict(int)
    for name in names:
        if name[0] not in set("MARCH"):
            continue

        first_char_dict[name[0]] += 1

    chars = set(first_char_dict.keys())
    
    if len(chars) < 3:
        print(0)
        exit(0)

    n_combinations = 0
    for c in itertools.combinations(chars, 3):
        n_combinations += first_char_dict[c[0]] * first_char_dict[c[1]] * \
                          first_char_dict[c[2]]

    print(n_combinations)

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

List = []
indexList = ['M', 'A', 'R', 'C', 'H']
for index in indexList:
    temp = []
    for i in range(N):
        if S[i][0] == index:
            temp.append(S[i])
    List.append(temp)
ans = 0
ans += len(List[0])*len(List[1])*len(List[2])
ans += len(List[0])*len(List[1])*len(List[3])
ans += len(List[0])*len(List[1])*len(List[4])
ans += len(List[0])*len(List[2])*len(List[3])
ans += len(List[0])*len(List[2])*len(List[4])
ans += len(List[0])*len(List[3])*len(List[4])
ans += len(List[1])*len(List[2])*len(List[3])
ans += len(List[1])*len(List[2])*len(List[4])
ans += len(List[1])*len(List[3])*len(List[4])
ans += len(List[2])*len(List[3])*len(List[4])
print(ans)

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

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

res = 0
res += cnt['M'] * cnt['A'] * cnt['R']
res += cnt['M'] * cnt['A'] * cnt['C']
res += cnt['M'] * cnt['A'] * cnt['H']
res += cnt['M'] * cnt['R'] * cnt['C']
res += cnt['M'] * cnt['R'] * cnt['H']
res += cnt['M'] * cnt['C'] * cnt['H']
res += cnt['A'] * cnt['R'] * cnt['C']
res += cnt['A'] * cnt['R'] * cnt['H']
res += cnt['A'] * cnt['C'] * cnt['H']
res += cnt['R'] * cnt['C'] * cnt['H']

print(res)

Solution (Python):
from collections import defaultdict
import itertools

N=input()
l=["M","A","R","C","H"]
C=defaultdict(lambda: 0)

for i in range(N):
	S=raw_input()
	if S[0] in l:
		C[S[0]]+=1

P=list(itertools.combinations(C.keys(),3))

ans=0
for x,y,z in P:
	ans+=C[x]*C[y]*C[z]

print ans

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

Solution (Python):
from itertools import combinations


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


letters = [_ for _ in 'MARCH' if cnt[_]>0]
if len(letters)<3:
    print(0)
    exit()


ans = 0
for combi in combinations(letters, 3):
    tmp = 1
    for i in combi:
        tmp *= cnt[i]
    ans += tmp


print(ans)

Solution (Python):
N = int(input())
S = []
M_num = 0
A_num = 0
R_num = 0
C_num = 0
H_num = 0
ans = 0
for i in range(N):
    S.append(input())


for i in range(N):
    temp = str(S[i])
    if temp[0] == "M":
        M_num += 1
    elif temp[0] == "A":
        A_num += 1
    elif temp[0] == "R":
        R_num += 1
    elif temp[0] == "C":
        C_num += 1
    elif temp[0] == "H":
        H_num += 1
ans += M_num*A_num*R_num
ans += M_num*A_num*C_num
ans += M_num*A_num*H_num

ans += A_num*R_num*C_num
ans += A_num*R_num*H_num

ans += R_num*C_num*H_num
ans += M_num *C_num*H_num
ans += M_num*R_num*C_num

ans += A_num * C_num * H_num
ans += M_num * R_num * H_num
print(ans)

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

counts = [0] * 5
for i, c in enumerate('MARCH'):
    counts[i] = len([s for s in S if s[0] == c])

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

print(count)

Solution (Python):
n=int(input())
M=set();A=set();R=set();C=set();H=set()
for i in range(n):
    a=input()
    if a.startswith("M"):
        M.add(a)
    elif a.startswith("A"):
        A.add(a)
    elif a.startswith("R"):
        R.add(a)
    elif a.startswith("C"):
        C.add(a)
    elif a.startswith("H"):
        H.add(a)
m=len(M);a=len(A);r=len(R);c=len(C);h=len(H)
print(m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h)

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

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

L = [0, 0, 0, 0, 0]

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

pattern = 0

for i in range(5):
	for j in range(5):
		for k in range(5):
			if i < j < k:
				pattern += L[i] * L[j] * L[k]

print(pattern)