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

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

num = {
    'M': 0,
    'A': 0,
    'R': 0,
    'C': 0,
    'H': 0,
}
for s_i in s:
    for x in 'MARCH':
        if s_i[0] == x:
            num[x] += 1
            break

ans = 0
for x1, x2, x3 in combinations('MARCH', 3):
    ans += num[x1] * num[x2] * num[x3]
print(ans)

Solution (Python):
N = int(input())
M = []
A = []
R = []
C = []
H = []

for i in range(N):
    temp = input()
    init_temp = list(temp)   
    if 'M' == init_temp[0]:
        M.append(temp)
    elif 'A' == init_temp[0]:
        A.append(temp)
    elif 'R' == init_temp[0]:
        R.append(temp)
    elif 'C' == init_temp[0]:
        C.append(temp)
    elif 'H' == init_temp[0]:
        H.append(temp)
    else:
        pass

M = len(list(set(M)))
A = len(list(set(A)))
R = len(list(set(R)))
C = len(list(set(C)))
H = len(list(set(H)))

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

A = [0, 0, 0, 0, 0, 0, 1, 1, 1, 2]
B = [1, 1, 1, 2, 2, 3, 2, 2, 3, 3]
C = [2, 3, 4, 3, 4, 4, 3, 4, 4, 4]

ans = 0

for i in range(10):
    ans += D[A[i]] * D[B[i]] * D[C[i]]

print(ans)

Solution (Python):
from functools import reduce
from operator import mul
import itertools
N = int(input())
x = [input() for _ in range(N)]
M = len([m for m in x if m.startswith('M')])
A = len([a for a in x if a.startswith('A')])
R = len([r for r in x if r.startswith('R')])
C = len([c for c in x if c.startswith('C')])
H = len([h for h in x if h.startswith('H')])
y = [M,A,R,C,H]
yy = [i for i in y if i > 0]
yl = len(yy)
s = 0
if yl < 3:
    print(0)
    exit()
else:
    for o in itertools.combinations(yy,3):
        s += reduce(mul,o)
    print(s)

Solution (Python):
n = int(input())
sd = {}
hl = ["M","A","R","C","H"]
for i in range(n):
    s = input()
    head = s[0]
    
    if not head in hl:
        continue
        
    if head in sd:
        sd[head] += 1
    else:
        sd[head] = 1
        
values = list(sd.values())

length = len(values)
counts = 0
if length < 3:
    print(0)
else:
    for i in range(length-2):
        for j in range(i+1,length-1):
            for k in range(j+1,length):

                counts += values[i]*values[j]*values[k]

    print(counts)

Solution (Python):
n=int(input())
m=['M','A','R','C','H']
d={}
for _ in range(n):
    s=input()[0]
    if s in m:
        if s in d:d[s]+=1
        else:d[s]=1
d=list(d.values())
r=0
l=len(d)
for i in range(l):
    for j in range(i+1,l):
        for k in range(j+1,l):
            r+=d[i]*d[j]*d[k]
print(r)

Solution (Python):
import itertools
from collections import Counter
N = int(input())
src = [input() for i in range(N)]
ctr = Counter([s[0] for s in src])

ans = 0
for ptn in itertools.combinations('MARCH',3):
    ans += ctr[ptn[0]]*ctr[ptn[1]]*ctr[ptn[2]]
print(ans)

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

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

def make_count_list(names):
    firsts = list(map(lambda x: x[0], names))
    counts = []
    for c in "MARCH":
        counts.append(firsts.count(c))
    return counts

def main():
    counts = make_count_list(S)
    comb_num = 3
    ans = 0
    for comb in combinations(counts, comb_num):
        ans += reduce(mul, comb)
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
import itertools

N = int(input())

S = []
for _ in range(N):
    S.append(input())
    
M, A, R, C, H = [], [], [], [], []

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

for s in S:
    top = s[0]
    if top in march:
        if top == "M":
            M.append(s)
        elif top == "A":
            A.append(s)
        elif top == "R":
            R.append(s)
        elif top == "C":
            C.append(s)
        elif top == "H":
            H.append(s)

MARCH = [len(M), len(A), len(R), len(C), len(H)]

if MARCH.count(0) >= 3:
    print(0)

else:
    x = 0
    pattern = list(itertools.combinations(MARCH, 3))
    for i in pattern:
        x += i[0]*i[1]*i[2]
    print(x)

Solution (Python):
from collections import Counter
N = int(input())
S = []
for i in range(N):
    s = input()
    if s[0] in ["M","A","R","C","H"]:
        S.append(s[0])
C = Counter(S).most_common()
lenC = len(C)
Ans = 0
for i in range(lenC):
    for j in range(i+1,lenC):
        for k in range(j+1,lenC):
            Ans += C[i][1]*C[j][1]*C[k][1]
print(Ans)

Solution (Python):
from itertools import groupby, combinations
N = int(input())
Names = [input()[0] for _ in range(N)]
Names.sort()
Initials = {k: len(list(g)) for k, g in groupby(Names) if k in ['M', 'A', 'R', 'C', 'H']}
L = combinations(Initials.keys(), 3)
cnt = 0
for c in L:
    cnt += Initials[c[0]] * Initials[c[1]] * Initials[c[2]]
print(cnt)

Solution (Python):
N = int(input())
text = list("MARCH")
dict = {}
for t in text:
    dict[t] = 0
for _ in range(N):
    x = input()[0]
    if x in text:
        dict[x] += 1

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

Solution (Python):
import itertools

N = int(input())
march_d = dict()
for c in "MARCH":
  march_d[c] = 0
for _ in range(N):
  name = input()
  if name[0] in "MARCH":
    march_d[name[0]] += 1
    

ans = 0
for n1, n2, n3 in itertools.combinations("MARCH", 3):
  ans += march_d[n1] * march_d[n2] * march_d[n3]

print(ans)

Solution (Python):
n = int(raw_input())
a = [0 for _ in range(5)]
for _ in range(n):
  s = raw_input()
  if s[0] == 'M':
    a[0] += 1
  elif s[0] == 'A':
    a[1] += 1
  elif s[0] == 'R':
    a[2] += 1
  elif s[0] == 'C':
    a[3] += 1
  elif s[0] == 'H':
    a[4] += 1
ct = 0
for i in range(5):
  for j in range(i+1,5):
    for k in range(j+1,5):
      ct += a[i] * a[j] * a[k]
print ct

Solution (Python):

"""
Created on Fri Mar  9 16:34:45 2018

@author: Narita
"""
import collections
import itertools

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

    
    result = 0
    match_str = "MARCH"
    combi_str = list(itertools.combinations(list(match_str), 3))

    initial_char = []
    for i in range(N):


        if(S[i][0] in match_str):
            initial_char.append(S[i][0])

    c = collections.Counter(initial_char)

    for li in combi_str:
        result += c[li[0]] * c[li[1]] * c[li[2]]
    print(result)
    
if __name__=="__main__":
    main()

Solution (Python):
import itertools
n = int(input())
l = []
counts = []
ans = 0
for i in range(5):
  l.append(set([]))

for i in range(n):
  temp = input()
  
  if temp[0] == 'M':
    l[0].add(temp)
  elif temp[0] == 'A':
    l[1].add(temp)
  elif temp[0] == 'R':
    l[2].add(temp)
  elif temp[0] == 'C':
    l[3].add(temp)
  elif temp[0] == 'H':
    l[4].add(temp)

for i in l:
  if not len(i) == 0:
    counts.append(len(i))

if len(counts) >= 3:
  for count in itertools.combinations(counts, 3):
    ans += count[0]*count[1]*count[2]

print(ans)

Solution (Python):
import itertools
n = int(input())
cnt = [0, 0, 0, 0, 0]
perm = [0, 1, 2, 3, 4]
for i in range(n):
    name = input()
    if name[0] == 'M':
        cnt[0] += 1
    elif name[0] == 'A':
        cnt[1] += 1
    elif name[0] == 'R':
        cnt[2] += 1
    elif name[0] == 'C':
        cnt[3] += 1
    elif name[0] == 'H':
        cnt[4] += 1
ans = 0
for i, j, k in itertools.combinations(perm, 3):
    ans += cnt[i] * cnt[j] * cnt[k]
print(ans)

Solution (Python):

from collections import Counter
from itertools import combinations

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

fl2c = Counter(s[0] for s in ss if s[0] in 'MARCH')
res = 0
for a, b, c in combinations(fl2c, 3):
    res += fl2c[a] * fl2c[b] * fl2c[c]
print(res)

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

lst = [0] * 5

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

count = 0

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

print(count)

Solution (Python):
n = int(input())
s = [input() for i in range(n)]
dict_s = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
str_s = "MARCH"
ans = 0

import re
for item in dict_s.keys():
    for word in s:
        if(re.match(item, word) != None):
            dict_s[item] += 1

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

Solution (Python):
n = int(input())
a = [input() for i in range(n)]
dict = {"M":0, "A":0, "R":0, "C":0, "H":0}
ans = 0
for c in a:
    if(c[0] in "MARCH"):
        dict[c[0]] += 1
for i in range(5):
    for j in range(i+1, 5):
        for k in range(j+1, 5):
            ans += dict["MARCH"[i]] * dict["MARCH"[j]] * dict["MARCH"[k]]
print(ans)

Solution (Python):
import itertools
n = int(input())
a = [input() for i in range(n)]
dict = {"M":0, "A":0, "R":0, "C":0, "H":0}
ans = 0
march = list(itertools.combinations("MARCH",3))
for c in a:
    if(c[0] in "MARCH"):
        dict[c[0]] += 1
for c in march:
    ans += dict[c[0]] * dict[c[1]] * dict[c[2]]
print(ans)

Solution (Python):
n = input()
keywords = list("MARCH")
m = len(keywords)
D = dict(zip(keywords, [0] * m))
for i in range(n):
    s = raw_input()
    c = s[0]
    if c in D:
        D[c] += 1
ans = 0
for i in range(m):
    for j in range(i+1, m):
        for k in range(j+1, m):
            ans += D[keywords[i]] * D[keywords[j]] * D[keywords[k]]
print ans

Solution (Python):
def ii():
    return int(input())


def lii():
    return list(map(int, input().split(' ')))


def lvi(N):
    l = []
    for _ in range(N):
        l.append(ii())
    return l


def lv(N):
    l = []
    for _ in range(N):
        l.append(input())
    return l


def C():
    N = ii()
    d = {'M': 0, 'A':0, 'R':0,'C':0,'H':0}
    for _ in range(N):
        s = input()
        if s[0] in d.keys():
            d[s[0]] += 1

    from itertools import combinations

    ans = 0
    for e1, e2, e3 in combinations(d.keys(), 3):
        ans += d[e1] * d[e2] * d[e3]

    print(ans)

if __name__ == '__main__':
    C()

Solution (Python):
from collections import defaultdict
import itertools

N = int(input())

P = defaultdict(int)
for i in range(N):
    s = input()
    if s[0] in "MARCH":
        P[s[0]] += 1

if len(P)<3:
    print(0)
else:
    ans = 0
    for a,b,c in itertools.combinations(P,3):
        ans += P[a]*P[b]*P[c]
    print(ans)

Solution (Python):

from collections import defaultdict
from itertools import combinations
N = int(input())
C = [0, 0, 0, 0, 0, 0]
D = defaultdict(int)
for i, m in enumerate("MARCH", start=1):
    D[m] = i

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

ans = 0
for a, b, c in combinations(range(1, 6), r=3):
    ans += C[a]*C[b]*C[c]
print(ans)

Solution (Python):

from itertools import combinations
N = int(input())
C = [0, 0, 0, 0, 0]
march = set(list("MARCH"))
for _ in range(N):
    S = input()[0]
    if S in march:
        C["MARCH".index(S)] += 1

ans = 0
for a, b, c in combinations(range(5), r=3):
    ans += C[a]*C[b]*C[c]
print(ans)

Solution (Python):
n=int(input())
s=[input()for i in range(n)]
m_cnt,a_cnt,r_cnt,c_cnt,h_cnt=0,0,0,0,0
import itertools
ans=0
for i in range(n):
    if s[i][0]=="M":
        m_cnt+=1
    elif s[i][0]=="A":
        a_cnt+=1
    elif s[i][0]=="R":
        r_cnt+=1
    elif s[i][0]=="C":
        c_cnt+=1
    elif s[i][0]=="H":
        h_cnt+=1
x=list(itertools.combinations((m_cnt,a_cnt,r_cnt,c_cnt,h_cnt),3))
for i in x:
    ans+=i[0]*i[1]*i[2]
print(ans)

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

numM, numA, numR, numC, numH = 0,0,0,0,0
ans=0

for i in range(N):
    if S[i][0]=='M':
        numM+=1
    elif S[i][0]=='A':
        numA+=1
    elif S[i][0]=='R':
        numR+=1
    elif S[i][0]=='C':
        numC+=1
    elif S[i][0]=='H':
        numH+=1

P=[0,0,0,0,0,0,1,1,1,2]
Q=[1,1,1,2,2,3,2,2,3,3]
R=[2,3,4,3,4,4,3,4,4,4]

D=list()
D.append(numM)
D.append(numA)
D.append(numR)
D.append(numC)
D.append(numH)

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

print(ans)

Solution (Python):
n = int(input())
ss = []
for _ in range(n):
    ss.append(input())
hs = dict()
keys = ['M', 'A', 'R', 'C', 'H']
for k in keys:
    hs[k] = 0
ss = sorted(ss)
for i, s in enumerate(ss, 0):
    c = s[0]
    if c in keys:
        if c in hs:
            hs[c] += 1
        else:
            hs[c] = 1
import itertools
combs = list(itertools.combinations(keys,3))
ans = 0
for comb in combs:
    ans += hs[comb[0]] * hs[comb[1]] * hs[comb[2]]
print(ans)

Solution (Python):
from itertools import combinations
N=int(input())
nums={}
for i in "MARCH":
    nums[i]=0
for i in range(N):
    s=input().strip()
    if s[0] in "MARCH":
        nums[s[0]]+=1
ct=0
for a,b,c in combinations("MARCH",3):
    ct+=nums[a]*nums[b]*nums[c]
print(ct)

Solution (Python):
from itertools import combinations

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

s_comb_list = list(combinations('MARCH', 3))
v = 0
for s_comb in s_comb_list:
    v += (d[s_comb[0]] * d[s_comb[1]] * d[s_comb[2]])
print(v)

Solution (Python):
import itertools

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

num = [0, 0, 0, 0, 0]
index = ['M', 'A', 'R', 'C', 'H']
for i in range(n):
    for j in range(5):
        if s[i][0] == index[j]:
            num[j] += 1
            pass

if num.count(0) >= 3:
    print(0)
    exit()

data = []
for i in range(5):
    if num[i] > 0:
        data.append(num[i])

if len(data) == 3:
    print(data[0] * data[1] * data[2])

elif len(data) == 4:
    print(data[0]*data[1]*data[2] + data[0]*data[1]*data[3] + data[0]*data[2]*data[3] + data[1]*data[2]*data[3])

else:
    print(data[0]*data[1]*data[2] + data[0]*data[1]*data[3] + data[0]*data[1]*data[4] + data[0]*data[2]*data[3] + data[0]*data[2]*data[4] + data[0]*data[3]*data[4] + data[1]*data[2]*data[3] + data[1]*data[2]*data[4] + data[1]*data[3]*data[4] + data[2]*data[3]*data[4])

Solution (Python):
n = int(input())
ss = []
for _ in range(n):
    ss.append(input())
hs = dict()

keys = ['M', 'A', 'R', 'C', 'H']
for k in keys:
    hs[k] = 0
ss = sorted(ss)
for i, s in enumerate(ss, 0):
    c = s[0]
    if c in keys:
        if c in hs:
            hs[c] += 1
        else:
            hs[c] = 1





import itertools
combs = list(itertools.combinations(keys,3))
ans = 0
for comb in combs:
    ans += hs[comb[0]] * hs[comb[1]] * hs[comb[2]]
print(ans)

Solution (Python):

N = int(input())

cnt = [0]*5

for i in range(N):
	name = input()
	if name[0] == 'M':
		cnt[0] += 1
	elif name[0] == 'A':
		cnt[1] += 1
	elif name[0] == 'R':
		cnt[2] += 1
	elif name[0] == 'C':
		cnt[3] += 1
	elif name[0] == 'H':
		cnt[4] += 1
ans = 0
for i in range(3):
	for j in range(i+1,4):
		for k in range(j+1,5):
			ans += cnt[i]*cnt[j]*cnt[k]
print(ans)

Solution (Python):
N = int(input())
S = []
march = [0, 0, 0, 0, 0]

for i in range(0, N):
    s = input()
    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



ans = 0

for i in range(2, 5):
    ans = ans + march[0] * march[1] * march[i]
for i in range(3, 5):
    ans = ans + march[0] * march[2] * march[i]

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

for i in range(3, 5):
    ans = ans + march[1] * march[2] * march[i]

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

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

print(ans)

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

print(ans)
"""

Solution (Python):
N = int(input())
S = [input() for i in range(N)]
a = [0 for _ in range (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
print (a[0]*a[1]*a[2]+a[1]*a[2]*a[3]+a[2]*a[3]*a[4]+a[0]*a[1]*a[3]+a[0]*a[1]*a[4]+a[0]*a[2]*a[3]+a[0]*a[2]*a[4]+a[1]*a[2]*a[4]+a[1]*a[3]*a[4]+a[0]*a[3]*a[4])

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

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

Solution (Python):
import numpy as np
N = int(input())
S = [None]*N
for i in range(N):
    S[i] = input()

S_M = [S[i] for i in range(N) if S[i][0] == 'M']
S_A = [S[i] for i in range(N) if S[i][0] == 'A']
S_R = [S[i] for i in range(N) if S[i][0] == 'R']
S_C = [S[i] for i in range(N) if S[i][0] == 'C']
S_H = [S[i] for i in range(N) if S[i][0] == 'H']

souwa = 0
kahi = [0]*5
kahi[0] = len(S_M)
kahi[1] = len(S_A)
kahi[2] = len(S_R)
kahi[3] = len(S_C)
kahi[4] = len(S_H)

for i in range(len(kahi)-2):
    for j in range(i+1, len(kahi)-1):
        for k in range(j+1, len(kahi)):
            souwa += kahi[i]*kahi[j]*kahi[k]
print(souwa)

Solution (Python):
N = int(input())
m, a, r, c, h = 0, 0, 0, 0, 0
for _ in range(N):
    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
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())
nli = []

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

for i in range(n):
    p = str(input())
    nli.append(p)
    q = list(p)
    po = q[0].upper()
    if po in nlid :
        nlid[po] = nlid[po] + 1
    else:
        None
    

count = nlid['M'] * nlid['A'] * nlid['R'] + nlid['M'] * nlid['A'] * nlid['C'] + nlid['M'] * nlid['A'] * nlid['H'] + nlid['M'] * nlid['R'] * nlid['C'] + nlid['M'] * nlid['R'] * nlid['H'] + nlid['M'] * nlid['C'] * nlid['H'] + nlid['A'] * nlid['R'] * nlid['C'] + nlid['A'] * nlid['R'] * nlid['H'] + nlid['A'] * nlid['C'] * nlid['H'] + nlid['R'] * nlid['C'] * nlid['H']
                
print(count)

Solution (Python):
n = int(input())
s =[input() for i in range(n)]
m,a,r,c,h=0,0,0,0,0
for A in s:
    if A[0]=='M':
        m+=1
    elif A[0]=='A':
        a+=1
    elif A[0]=='R':
        r+=1
    elif A[0]=='C':
        c+=1
    elif A[0]=='H':
        h+=1
x = []
for i in [m,a,r,c,h]:
    if i != 0:
        x.append(i)
if len(x)<3:
    print(0)
elif len(x)==3:
    print(x[0]*x[1]*x[2])
elif len(x)==4:
    print(x[0]*x[1]*x[2]+x[0]*x[1]*x[3]+x[0]*x[2]*x[3]+x[1]*x[2]*x[3])
else:
    print(x[0]*x[1]*x[2]+x[0]*x[1]*x[3]+x[0]*x[2]*x[3]+x[1]*x[2]*x[3]
         +x[0]*x[1]*x[4]+x[0]*x[2]*x[4]+x[1]*x[2]*x[4]
         +x[2]*x[3]*x[4]+x[1]*x[3]*x[4]+x[0]*x[3]*x[4])

Solution (Python):
n = int(input())
a = []
for i in range(n):
    a.append(input())
b = 0
c = 0
d = 0
e = 0
f = 0
for i in range(n):
    if a[i][0] =='M':
        b += 1
    elif a[i][0] =='A':
        c += 1
    elif a[i][0] =='R':
        d += 1
    elif a[i][0] =='C':
        e += 1
    elif a[i][0] =='H':
        f += 1
print(b*c*d+b*c*e+b*c*f+b*d*e+b*d*f+b*e*f+c*d*e+c*d*f+c*e*f+d*e*f)

Solution (Python):
from itertools import combinations

names = [input() for _ in range(int(input()))]
march = [list(filter(lambda x: x[0] == c, names)) for c in 'MARCH']
ways = 0
for combo in combinations(march, 3):
    ways += len(combo[0]) * len(combo[1]) * len(combo[2])
print(ways)

Solution (Python):


N=int(input())
ans=0
cnt=[0,0,0,0,0]

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

if cnt.count(0)<=2:
    for i in range(5):
        for j in range(i+1,5):
            for k in range(j+1,5):
                ans+=cnt[i]*cnt[j]*cnt[k]

print(ans)

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

d = {"M":0,"R":0,"A":0,"C":0,"H":0}
S = []
num = 0

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


for s in S:
    
    if s[0] in list(d.keys()):
        d[s[0]] += 1



for al1 in list(d.keys()):
    for al2 in list(d.keys()):
        for al3 in list(d.keys()):
            if al1 != al2 and al1 != al3 and al2 != al3:
                num += d[al1]*d[al2]*d[al3]

print(int(num/6))

Solution (Python):
N = int(input())
S = []
temp = 0

cnt = {"M":0, "R":0, "A":0, "C":0, "H":0}

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

for s in S:
    if s[0] in list(cnt.keys()):
        cnt[s[0]] += 1

for i in list(cnt.keys()):
    for j in list(cnt.keys()):
        for k in list(cnt.keys()):
            if i != j and j != k and i != k:
                temp += cnt[i]*cnt[j]*cnt[k]

print(int(temp/6))

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


if not c.count(0) >= 3:
  k += c[0] * c[1] * c[2] + c[0] * c[1] * c[3] + c[0] * c[1] * c[4] + c[0] * c[2] * c[3] + c[0] * c[2] * c[4] + c[0] * c[3] * c[4] + c[1] * c[2] * c[3] + c[1] * c[2] * c[4] + c[1] * c[3] * c[4] + c[2] * c[3] * c[4] 

print(k)

Solution (Python):
from itertools import combinations

n = int(input())
names = {"M":0, "A":0, "R":0, "C":0, "H":0}
for _ in range(n):
    name = input()
    if name[0] in names.keys():
        names[name[0]] += 1

patterns = list(combinations(names.keys(), 3))

count = 0
for pattern in patterns:
    count += names[pattern[0]] * names[pattern[1]] * names[pattern[2]]

print(count)

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

    dic = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
    for i in range(N):
        name = input()
        if name[0] in list('MARCH'):
            dic[name[0]] += 1
    ans = 0
    march = 'MARCH'
    for i in range(5):
        for j in range(i+1, 5):
            for k in range(j+1, 5):
                ans += dic[march[i]] * dic[march[j]] * dic[march[k]]
    print(ans)


solve()

Solution (Python):
N= int(input())
M=0
A=0
R=0
C=0
H=0
for i in range (N):
    a=(input())
    a_split=list(a)
    if a_split[0]=='M':
        M=M+1
    elif a_split[0]=='A':
        A=A+1
    elif a_split[0]=='R':
        R=R+1
    elif a_split[0]=='C':
        C=C+1
    elif a_split[0]=='H':
        H=H+1

count=0

count=count+M*A*R
count=count+M*A*C
count=count+M*A*H


count=count+M*R*C
count=count+M*R*H
count=count+M*C*H

count=count+A*R*C
count=count+A*R*H
count=count+A*C*H

count=count+R*C*H

print (count)

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

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

for i in range(n):
    s = input()
    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

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

print(c)

Solution (Python):
import itertools as it

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

HeadCharCnt = [0 for i in range(5)]
MARCH = 'MARCH'

for i in range(N):
    whichChar = MARCH.find(S[i][0])
    if whichChar != -1:
        HeadCharCnt[whichChar] = HeadCharCnt[whichChar] + 1

HeadCharCntPos = []
for j in HeadCharCnt:
    if j > 0:
        HeadCharCntPos.append(j)
validComb = list(it.combinations(HeadCharCntPos, 3))
ans = 0
for v in validComb:
    ans = ans + v[0] * v[1] * v[2]

print(ans)

Solution (Python):
n=int(input())
march=[0,0,0,0,0]
for i in range(n):
    l=input()
    if l[0] in 'MARCH':
        index='MARCH'.find(l[0])
        march[index]+=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())
ls = [input()[:1] for _ in range(n)]
ans = 0
cmb = list(itertools.combinations(list("MARCH"), 3))

for c in cmb:
    ans += ls.count(c[0]) * ls.count(c[1]) * ls.count(c[2])

print(ans)

Solution (Python):
import sys
import math
import collections
import itertools
import array
import inspect


sys.setrecursionlimit(10000)


def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))


def to_bin(x):
    return bin(x)[2:]



dp = None

def main():
    N = int(input())
    name_list = [input() for i in range(N)]
    first_letter_dict = collections.defaultdict(lambda: 0)

    for name in name_list:
        first_letter_dict[name[0]] += 1

    first_letter_combination = [
        "MAR", "MAC", "MAH", "MRC", "MRH", "MCH", "ARC", "ARH", "ACH", "RCH"
    ]

    combinations = 0

    for f_comb in first_letter_combination:
        combinations += first_letter_dict[f_comb[0]] * first_letter_dict[f_comb[1]] * first_letter_dict[f_comb[2]]

    print(combinations)


main()

Solution (Python):
n = int(input())
names = []
for i in range(n):
  names.append(input())
names = [i[0] for i in names]
nm = ["M","A","R","C","H"]
ks = [names.count(nm[i]) for i in range(5)]
ans = 0
for i in range(3):
  for j in range(i+1,4):
    for k in range(j+1,5):
      ans += ks[i] * ks[j] * ks[k]
print(ans)

Solution (Python):
n = int(input())
s = [input() for i in range(n)]
march = {'M': [], 'A': [], 'R': [], 'C': [], 'H': []}

s = list(set(s))

a = b = 0
for i in s:
    if i[0] == 'M':
        march['M'].append(i)
    elif i[0] == 'A':
        march['A'].append(i)
    elif i[0] == 'R':
        march['R'].append(i)
    elif i[0] == 'C':
        march['C'].append(i)
    elif i[0] == 'H':
        march['H'].append(i)

nums = []
for i in march.values():
    if not len(i) == 0:
        nums.append(len(i))

count = 0
length = len(nums)
if length < 3:
    print(0)
else:
    for i in range(length):
        if length < 3:
            break
        v = nums[i]
        nums.pop(i)
        length = len(nums)
        for j in range(length):
            count += v * nums[j] * (sum(nums[j+1:]))
    print(count)

Solution (Python):
import collections
N = int(input())
a = ['']*N
for i in range(N):
    a[i] = list(input())[0]
c_list = [0]*5
MARCH = ['M','A','R','C','H']
c_list = [a.count(i) for i in MARCH]
summation = 0
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            summation += c_list[i]*c_list[j]*c_list[k]
print(summation)

Solution (Python):
n = int(input())
l = ['M','A','R','C','H']
m = []
a = []
r = []
c = []
h = []
for i in range(n):
    s = input()
    if not s[0] in l: continue
    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)
    else:
        h.append(s)

n = sum([len(i) for i in [m,a,r,c,h]])
all = n * (n - 1) * (n - 2) // 6
for t in [m,a,r,c,h]:
    i = len(t)
    if i >= 3:
        k = i * (i - 1) * (i - 2) // 6
        all -= k
    if i >= 2:
        k = i * (i - 1) // 2
        all -= k * (n - i)
print(all)

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

name = [0 for i in range(5)]
for i in range(n):
    if s[i][0] == "M":
        name[0] +=1
    elif s[i][0] == "A":
        name[1] +=1
    elif s[i][0] == "R":
        name[2] +=1
    elif s[i][0] == "C":
        name[3] +=1
    elif s[i][0] == "H":
        name[4] +=1
count = 0
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            
            count += name[i]*name[j]*name[k]
print(count)

Solution (Python):
import itertools as itr

n = int(input())

march = [0,0,0,0,0]
tops = list(range(5))

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

total = 0

for kumiawase in itr.combinations(tops,3):
    total += march[kumiawase[0]]*march[kumiawase[1]]*march[kumiawase[2]]

print(total)

Solution (Python):
N = int(input())
s = [input()[0] for _ in range(N)]
t = []
ans = 0
for k in 'MARCH':
    t.append(s.count(k))
for i in range(32):
    u = []
    for j in range(5):
        if i&(1<<j):
            u.append(t[j])
    if len(u) == 3:
        ans += u[0]*u[1]*u[2]
print(ans)

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

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

N = int(input())

S = deque()

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

for i in range(N):
    S.append(input())
    if S[i][0] in name:
        name[S[i][0]] += 1

conbi = 0
count = deque()

for alp in name.values():
    count.append(alp)
    
for i in range(3):
    for l in range(i+1, 5):
        for n in range(l+1, 5):
            if count[i] != 0 and count[l] != 0 and count[n] != 0:
                conbi += count[i] * count[l] * count[n]
print(conbi)

Solution (Python):
N=int(input())
s=[]
t=[]
ans=0
for j in range(N):
    a=list(input())
    s+=a[0]
for k in "MARCH":
    t.append(s.count(k))
for ii in range(32):
    u=[]
    for jj in range(5):
        if ii&(1<<jj):
            u.append(t[jj])
    if len(u)==3:
        ans+=u[0]*u[1]*u[2]
print(ans)