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

Solution (Python):
import re
import sys
import itertools

if __name__ == '__main__':
    N = input()
    S = list()
    c = 0
    d = {'M':0,'A':0,'R':0,'C':0,'H':0}
    for i in xrange(N):
        a = raw_input()[0]
        if a in d.keys():
            d[a] += 1
    if d['M'] > 0 and d['A'] > 0 and d['R'] > 0:
        c += d['M']*d['A']*d['R']
    if d['M'] > 0 and d['A'] > 0 and d['C'] > 0:
        c += d['M']*d['A']*d['C']
    if d['M'] > 0 and d['A'] > 0 and d['H'] > 0:
        c += d['M']*d['A']*d['H']
    if d['M'] > 0 and d['R'] > 0 and d['C'] > 0:
        c += d['M']*d['R']*d['C']
    if d['M'] > 0 and d['R'] > 0 and d['H'] > 0:
        c += d['M']*d['R']*d['H']
    if d['M'] > 0 and d['C'] > 0 and d['H'] > 0:
        c += d['M']*d['C']*d['H']
    if d['A'] > 0 and d['R'] > 0 and d['C'] > 0:
        c += d['A']*d['R']*d['C']
    if d['A'] > 0 and d['R'] > 0 and d['H'] > 0:
        c += d['A']*d['R']*d['H']
    if d['A'] > 0 and d['C'] > 0 and d['H'] > 0:
        c += d['A']*d['C']*d['H']
    if d['R'] > 0 and d['C'] > 0 and d['H'] > 0:
        c += d['R']*d['C']*d['H']
    print c

Solution (Python):
import itertools

n = int(input())
a = [0] * 26
for _ in range(n):
   a[ord(input()[0]) - ord('A')] += 1
c = []
for x in 'MARCH':
    c.append(a[ord(x) - ord('A')])
s = 0
for x in itertools.combinations(c, 3):
    k = 1
    for i in x: k *= i
    s += k
print(s)

Solution (Python):
m, a, r, c, h = [0] * 5

N = int(input())

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
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())
MARCH = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
for i in range(N):
    temp = input()
    if temp[0] in MARCH.keys():
        MARCH[temp[0]] += 1
ans = 0
for comb in list(itertools.combinations(MARCH.values(), 3)):
    temp2 = 1
    for i in comb:
        temp2 *= i
    ans += temp2
    
print(ans)

Solution (Python):
a=int(input())
list=[0,0,0,0,0]
for x in range(a):
	b=input()[:1]
	if 'M'==b:
		list[0]+=1
	elif 'A'==b:
		list[1]+=1
	elif 'R'==b:
		list[2]+=1
	elif 'C'==b:
		list[3]+=1
	elif 'H'==b:
		list[4]+=1
	a-=1
f=0
for c in range(5):
	for d in range(4):
		for e in range(3):
			if c<=d or c<=e or d<=e:
				break
			f+=list[c]*list[d]*list[e]
print(f)

Solution (Python):
n=int(input())
a=[input()for i in range(n)]
import itertools
c_0=c_1=c_2=c_3=c_4=0
for i in a:
    if i[0]=="M":
        c_0+=1
    elif i[0]=="A":
        c_1+=1
    elif i[0]=="R":
        c_2+=1
    elif i[0]=="C":
        c_3+=1
    elif i[0]=="H":
        c_4+=1
total=list(itertools.combinations((c_0,c_1,c_2,c_3,c_4),3))
ans=0
for i in range(10):
    ans+=(total[i][0]*total[i][1]*total[i][2])
print(ans)

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

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

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

import numpy as np
s=np.zeros(5)

for i in a:
    if i[0]=="M":
        s[0]+=1
    elif i[0]=="A":
        s[1]+=1
    elif i[0]=="R":
        s[2]+=1
    elif i[0]=="C":
        s[3]+=1
    elif i[0]=="H":
        s[4]+=1
    else:
        continue
c=0

for i in range(5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            c+=s[i]*s[j]*s[k]
print(int(c))

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

user_name = []

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

M_group = [x for x in user_name if x[0] == 'M']
A_group = [x for x in user_name if x[0] == 'A']
R_group = [x for x in user_name if x[0] == 'R']
C_group = [x for x in user_name if x[0] == 'C']
H_group = [x for x in user_name if x[0] == 'H']

choice_cnt = 0
choice_list = []

for i in range(2):
    choice_cnt += i
    for j in range(2):
        choice_cnt += i
        for k in range(2):
            choice_cnt += i
            for l in range(2):
                choice_cnt += i
                for m in range(2):
                    choice_cnt += i

                    if i+j+k+l+m == 3:
                        choice_list.append([i,j,k,l,m])

sums = 0
march = [len(M_group), len(A_group), len(R_group), len(C_group), len(H_group)]

prod = 0
choice_num = []

for x in choice_list:
    choice_num.append([march[i] for i in range(len(x)) if x[i] > 0])

prod_sum = 0

for y in choice_num:
    prod = 1

    for k in range(len(y)):
        prod = prod * y[k]
    prod_sum += prod

print(prod_sum)

Solution (Python):
n=int(input())
m=0
a=0
r=0
c=0
h=0
for i in range(n):
    name=input()
    n=name[0]
    if n=="M":
        m+=1
    if n=="A":
        a+=1
    if n=="R":
        r+=1
    if n=="C":
        c+=1
    if n=="H":
        h+=1
lst=[m,a,r,c,h]
ans=0
for i in range(5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            ans+=lst[i]*lst[j]*lst[k]
print(ans)

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

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

for i in range(n):
    si = input()
    if si[0] in march.keys():
        march[si[0]] += 1


sum = 0
sum += (march['M'] * march['A'] * march['R'])
sum += (march['M'] * march['A'] * march['C'])
sum += (march['M'] * march['A'] * march['H'])
sum += (march['A'] * march['R'] * march['C'])
sum += (march['A'] * march['R'] * march['H'])
sum += (march['R'] * march['M'] * march['C'])
sum += (march['R'] * march['M'] * march['H'])
sum += (march['R'] * march['C'] * march['H'])
sum += (march['C'] * march['M'] * march['H'])
sum += (march['C'] * march['A'] * march['H'])
print(sum)

Solution (Python):
import itertools
                                                                                                                           
n = int(input())
index = [0, 1, 2, 3, 4]
count = [0, 0, 0, 0, 0]
result = 0
for i in range(n):
  x = input()[0]
  if x == 'M':
    count[0] += 1
  elif x == 'A':
    count[1] += 1
  elif x == 'R':
    count[2] += 1
  elif x == 'C':
    count[3] += 1
  elif x == 'H':
    count[4] += 1
  else:
    pass
        
for cs in list(itertools.combinations(index, 3)):
  result += count[cs[0]]*count[cs[1]]*count[cs[2]]

print(result)

Solution (Python):
import itertools
import time
n = int(input())
names = []
ans = 0
ini = ["M", "A", "R", "C", "H"]
count = {"M":0, "A":0, "R":0, "C":0, "H":0}
for i in range(n):
  name = input()
  if name[0] in ini:
    count[name[0]] += 1

combo = list(itertools.combinations(ini, 3))

for a, b, c in combo:
  ans += count[a]*count[b]*count[c]

print(ans)

Solution (Python):
import itertools

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

for i in range(N):
    member = input()
    for key in march:
        if member[0] == key:
            march[key] += 1
            break

combi_list = list(itertools.combinations((list(march.values())), 3))
count = sum([i[0] * i[1] * i[2] for i in combi_list])
print(count)

Solution (Python):
def main():
    N = int(input())
    M = A = R = C = H = 0
    for i in range(N):
        name = input()
        if name[0] == "M":
            M = M + 1
        elif name[0] == "A":
            A = A + 1
        elif name[0] == "R":
            R = R + 1
        elif name[0] == "C":
            C = C + 1
        elif name[0] == "H":
            H = H + 1

    ans = M*A*R
    ans = ans + M*A*C
    ans = ans + M*A*H
    ans = ans + M*R*C
    ans = ans + M*R*H
    ans = ans + M*C*H
    ans = ans + A*R*C
    ans = ans + A*R*H
    ans = ans + A*C*H
    ans = ans + R*C*H
    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
from collections import defaultdict as ddict
from itertools import combinations as comb

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

dd = ddict(int)
for name in s:
    for i in ['M', 'A', 'R', 'C', 'H']:
        if name.startswith(i):
            dd[i] += 1

ans = sum(dd[i1] * dd[i2] * dd[i3] for i1, i2, i3 in comb(dd.keys(), 3))

print(ans)

Solution (Python):
import numpy as np
import sys
import itertools

n = int(input())
s = [0, 0, 0, 0, 0]

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

k = []
for i in range(len(s)):
    if s[i] > 0:
        k.append(s[i])

l = len(k)
if l < 3:
    print(0)
    sys.exit()

a = 0
c = list(itertools.combinations(range(l), 3))
for i in c:
    a += k[i[0]] * k[i[1]] * k[i[2]]

print(a)

Solution (Python):
from collections import Counter
from itertools import combinations
N = int(input())
S = Counter()
for _ in range(N):
    s = input()
    S.update(s[0])

ss = "MARCH"
coms = combinations(ss, 3)
ans = 0
for com in coms:
    ans += S.get(com[0], 0) * S.get(com[1], 0) * S.get(com[2], 0)
print(ans)

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

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

x=[]
x.append(m_count)
x.append(a_count)
x.append(r_count)
x.append(c_count)
x.append(h_count)
c=0
for i in range(len(x)):
    for j in range(i+1,len(x)):
        for k in range(j+1,len(x)):
            c+=x[i]*x[j]*x[k]
print(c)

Solution (Python):
n = int(input(""))
s = ["0"]*n
dict = {}
sum = [0,0,0,0,0,0,0,0,0,0]
ans = 0
for i in range(n):
    s[i] = input("")
    if s[i][0] in "MARCH":
        if s[i][0] in dict:
            dict[s[i][0]] += 1
        else:
            dict[s[i][0]] = 1
if "M" in dict:
    if "A" in dict:
        if "R" in dict:
              sum[0] = dict["M"]*dict["A"]*dict["R"]
        if "C" in dict:
              sum[1] = dict["M"]*dict["A"]*dict["C"]
        if "H" in dict:
              sum[2] = dict["M"]*dict["A"]*dict["H"]
    if "R" in dict:
        if "C" in dict:
              sum[3] = dict["M"]*dict["R"]*dict["C"]
        if "H" in dict:
              sum[4] = dict["M"]*dict["R"]*dict["H"]
    if "C" in dict:
        if "H" in dict:
              sum[5] = dict["M"]*dict["C"]*dict["H"]
if "A" in dict:
    if "R" in dict:
        if "C" in dict:
              sum[6] = dict["A"]*dict["R"]*dict["C"]
        if "H" in dict:
              sum[7] = dict["A"]*dict["R"]*dict["H"]
    if "C" in dict:
        if "H" in dict:
              sum[8] = dict["A"]*dict["C"]*dict["H"]
if "R" in dict and "C" in dict and "H" in dict:
    sum[9] = dict["R"]*dict["C"]*dict["H"]
for i in range(10):
    ans += sum[i]
print(ans)

Solution (Python):






def count_initial_name(people_count: int) -> dict:
    matching_strings_count = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}

    for person in range(people_count):
        initial_name = input()[0]

        if initial_name in matching_strings_count.keys():
            matching_strings_count[initial_name] += 1

    return matching_strings_count


def count_patterns(matching_strings_count):
    import itertools

    patterns = itertools.combinations(matching_strings_count.keys(), 3)
    pattern_count = 0

    for a_pattern in patterns:
        pattern_count += matching_strings_count[a_pattern[0]] * \
            matching_strings_count[a_pattern[1]] * \
            matching_strings_count[a_pattern[2]]
    return pattern_count


if __name__ == '__main__':
    matching_strings_count = count_initial_name(people_count=int(input()))

    if sum(matching_strings_count.values()) >= 3:
        print(count_patterns(matching_strings_count))
    else:
        print(0)

Solution (Python):
n = int(input())
s = [input() for i in range(n)]
st = [0,0,0,0,0]
p = [0,0,0,0,0,0,1,1,1,2]
q = [1,1,1,2,2,3,2,2,3,3]
r = [2,3,4,3,4,4,3,4,4,4]
ans = 0

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

for i in range(10):
    ans += st[p[i]]*st[q[i]]*st[r[i]]

print(ans)

Solution (Python):
N = int(input())
dic = {}
for _ in range(N):
    S = input()
    if S[0] not in "MARCH":
        continue
    if S[0] not in dic:
        dic[S[0]] = 0
    dic[S[0]]+=1
ans = 0

for a in dic:
    for b in dic:
        for c in dic:
            if a == b or b == c or c == a:
                continue
            ans += dic[a] * dic[b] * dic[c]
print(ans // 6)

Solution (Python):




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

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

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

Solution (Python):
import itertools
n = int(input())
x = [input() for i in range(n)] 
num,march,answer = [0,0,0,0,0],["M","A","R","C","H"],0
for j in x:
 if j[0] in march: num[march.index(j[0])] += 1
while 0 in num: num.remove(0)
for k in list(itertools.combinations(num,3)): 
 answer += k[0]*k[1]*k[2]
print(answer)

Solution (Python):
x = int(input())
count = [0 for i in range(5)]
for i in range(x):
    name = input()
    if name[0] == 'M':
        count[0] += 1
    elif name[0] == 'A':
        count[1] += 1
    elif name[0] == 'R':
        count[2] += 1
    elif name[0] == 'C':
        count[3] += 1
    elif name[0] == 'H':
        count[4] += 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]
res = 0
for i in range(10):
    res += count[p[i]]*count[q[i]]*count[r[i]]

print(res)

Solution (Python):
N = int(input())
_M = [] 
_A = [] 
_R = [] 
_C = [] 
_H = [] 

for i in range(N):
    x = input()
    if x[0] == 'M':
        _M.append(x)
    elif x[0] == 'A':
        _A.append(x)
    elif x[0] == 'R':
        _R.append(x)
    elif x[0] == 'C':
        _C.append(x)
    elif x[0] == 'H':
        _H.append(x)

m = len(_M)
a = len(_A)
r = len(_R)
c = len(_C)
h = len(_H)

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

Solution (Python):
import itertools
n = int(input())
m=0;a=0;r=0;c=0;h=0
for i in range(n):
    s = input()
    if s[0]=='M':
        m+=1
    elif s[0]=='A':
        a+=1
    elif s[0]=='R':
        r+=1
    elif s[0]=='C':
        c+=1
    elif s[0]=='H':
        h+=1
l = itertools.combinations([m,a,r,c,h],3)
ans = 0
for i in l:
    k = 1
    for i2 in i:
        k*=i2
    ans+=k
print(ans)

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

l=itertools.combinations([m,a,r,c,h],3)
c=0
for i in l:
    k=1
    for i2 in i:
        k*=i2
    c+=k
print(c)

Solution (Python):
import collections
import itertools

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

cnt = collections.Counter()
for s in S:
    cnt[s[0]] += 1

ans = 0
for x, y, z in itertools.combinations("MARCH", 3):
    ans += cnt[x] * cnt[y] * cnt[z]
print(ans)

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

march = "MARCH"
arr = [0 for i in range(5)]
for i in range(n):
    s = input()
    for j in range(len(march)):
        if s[0] == march[j]:
            arr[j] += 1

ans = 0

ans2 = [arr[x]*arr[y]*arr[z] for x in range(len(march)) for y in range(x+1, len(march)) for z in range(y+1, len(march))]
for i in ans2:
    ans += i

print(ans)

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

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

Solution (Python):
N = int(input())
march = "MARCH"
count = [0 for i in range(5)]
for i in range(N):
    S = input()
    for j in range(5):
        if S[0] == "MARCH"[j]:
            count[j] += 1
def f(m):
    result = 0
    for i in range(5):
        result += count[i] ** m
    return result
print((f(1) ** 3 + 2 * f(3) - 3 * f(1) * f(2)) // 6)

Solution (Python):
import itertools
N = int(input())
S = []
x = 0
y = 1
for i in range(N):
    Z = input()
    S.append(Z[0])

T = []

for j in "MARCH":
    T.append(S.count(j))

P = list(itertools.combinations(T,3))

for k in P:
    for l in range(3):
        y *= int(k[l])
    x += y
    y = 1

print(x)

Solution (Python):
import collections
import itertools

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

seq = list(itertools.combinations(['M', 'A', 'R', 'C', 'H'], 3))
ans = 0
for l in seq:
    ans += s[l[0]] * s[l[1]] * s[l[2]]
print(ans)

Solution (Python):
N = int(input())
m = 0
a = 0
r = 0
c = 0
h = 0
for _ in range(N):
    p = input()
    if p[0] == "M":
        m += 1
    elif p[0] == "A":
        a += 1
    elif p[0] == "R":
        r += 1
    elif p[0] == "C":
        c += 1
    elif p[0] == "H":
        h += 1
ans = 0
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
from collections import Counter

def solve(n, gc):
    

    
    if len(gc) < 3:
        return 0

    ans = 0
    for permutation in combinations("MARCH", 3):
        ans += (gc[permutation[0]] * gc[permutation[1]] * gc[permutation[2]])

    return ans

def main():
    n = int(input())
    gc = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
    for _ in range(n):
        x = input()[0]
        if x in "MARCH":
            gc[x] += 1
    print(solve(n, gc))

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
count = [0, 0, 0, 0, 0]
pattern = [[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]]
for i in range(N):
    s = input()
    if (s[0] == 'M'):
        count[0] += 1
    if (s[0] == 'A'):
        count[1] += 1
    if (s[0] == 'R'):
        count[2] += 1
    if (s[0] == 'C'):
        count[3] += 1
    if (s[0] == 'H'):
        count[4] += 1

s = 0
for pat in pattern:
    temp = count[pat[0]] * count[pat[1]] * count[pat[2]]
    s += temp
print(s)

Solution (Python):
import itertools

N = int(input())

mem = list(set() for i in range(5))

for _ in range(N):
    S = input()
    first_name = "MARCH".find(S[0])
    if first_name != -1:
        mem[first_name].add(S)

ans = 0
for t in list(itertools.combinations(range(5), 3)):
    ans += len(mem[t[0]]) * len(mem[t[1]]) * len(mem[t[2]])
    
print(ans)

Solution (Python):
N = int(input())
d = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
for i in range(N):
    inp = input()
    if inp[0] in d:
        d[inp[0]] += 1
import itertools
cnt = 0
for c in itertools.combinations(d.keys(), 3):
    cnt += d[c[0]] * d[c[1]] * d[c[2]]
print(cnt)

Solution (Python):
import itertools

n = int(input())
names = {}
for x in 'MARCH':
    names[x] = 0

for _ in range(n):
    s = input()
    if s[0] in 'MARCH' :
        names[s[0]] += 1

ans = 0
for (x,y,z) in itertools.combinations('MARCH',3) :
    ans += names[x]*names[y]*names[z]

print(ans)

Solution (Python):
import itertools

n = int(input())
names = {}
for x in 'MARCH':
    names[x] = 0

for _ in range(n):
    s = input()
    if s[0] in 'MARCH' :
        names[s[0]] += 1

ans = 0
for (x,y,z) in list(itertools.combinations('MARCH',3)) :
    ans += names[x]*names[y]*names[z]

print(ans)

Solution (Python):
n = int(input())
names = {}
for x in 'MARCH':
    names[x] = 0

for _ in range(n):
    s = input()
    if s[0] in 'MARCH' :
        names[s[0]] += 1

ans = 0
for x in 'MARCH' :
    for y in 'MARCH' :
        if x == y:
            continue
        for z in 'MARCH':
            if x == z or y == z :
                continue
            ans += names[x]*names[y]*names[z]

print(ans//6)

Solution (Python):
import pprint
import itertools

N = int(input())

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

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

for k in [name[0] for name in S]:
    if k in D:
        D[k] = D[k] + 1

C = 0
for x, y, z in itertools.combinations(D.keys(), 3):
    C += D[x] * D[y] * D[z]

print(C)

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

d = defaultdict(int)

n = int(input())

for _ in range(n):
    initial = input()[0]
    if initial in 'MARCH':
        d[initial] += 1

a = list(d.values())

ans = 0

for x in combinations(range(len(a)),3):
    ans += a[x[0]] * a[x[1]] * a[x[2]]

print(ans)

Solution (Python):
N = int(input())
l = []
m=0
a=0
r=0
c=0
h=0
for i in range(N):
    l.append(input()) 

for i in l:
    if i.startswith('M'):
        m+=1
    if i.startswith('A'):
        a+=1
    if i.startswith('R'):
        r+=1
    if i.startswith('C'):
        c+=1
    if i.startswith('H'):
        h+=1

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

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
INF = float("inf")
import sys
sys.setrecursionlimit(10000)


def solve(N, S):
    d = Counter([s[0] for s in S if s[0] in "MARCH"])
    ans = 0
    for comb in combinations("MARCH", 3):
        a = 1
        for c in comb:
            a *= d[c]
        ans += a
    return ans


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


if __name__ == '__main__':
    main()

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

s = [input() for i in range(n)]

order = "MARCH"

initial_array = [name[0] for name in s]
nums = [initial_array.count(order[i]) for i in range(len(order))]

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

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

s = [input() for i in range(n)]

order = "MARCH"

nums = [[name[0] for name in s].count(order[i]) for i in range(len(order))]

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

Solution (Python):
import sys
import itertools

with sys.stdin as f:
    s_input = f.read()

    s_args = s_input.splitlines()
    n = int(s_args[0])
    s = s_args[1:]

    a = len([nm for nm in s if nm.startswith("A")])
    c = len([nm for nm in s if nm.startswith("C")])
    h = len([nm for nm in s if nm.startswith("H")])
    m = len([nm for nm in s if nm.startswith("M")])
    r = len([nm for nm in s if nm.startswith("R")])
    
    

    cmb = []
    if m > 0:
        cmb.append("m")
    if a > 0:
        cmb.append("a")
    if r > 0:
        cmb.append("r")
    if c > 0:
        cmb.append("c")
    if h > 0:
        cmb.append("h")

    res = 0
    pats = list(itertools.combinations(cmb, 3))
    for pat in pats:
        p_res = 1
        if 'm' in pat:
            p_res *= m
        if 'a' in pat:
            p_res *= a
        if 'r' in pat:
            p_res *= r
        if 'c' in pat:
            p_res *= c
        if 'h' in pat:
            p_res *= h
        res += p_res
        
    print(res)
            
sys.exit(0)

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

d = defaultdict(int)

n = int(input())

for _ in range(n):
    initial = input()[0]
    if initial in 'MARCH':
        d[initial] += 1

a = list(d.values())

ans = 0

for x in combinations(range(min(len(a),5)),3):
    ans += a[x[0]] * a[x[1]] * a[x[2]]

print(ans)

Solution (Python):
lis = [0,0,0,0,0]
n = int(input())
for i in range(n):
    a = input()
    if a[0] == "M":lis[0] += 1
    if a[0] == "A":lis[1] += 1
    if a[0] == "R":lis[2] += 1
    if a[0] == "C":lis[3] += 1
    if a[0] == "H":lis[4] += 1
ans = 0
for m in range(5):
    for l in range(5):
        if l > m:
            for h in range(5):
                if h > l:
                    ans += lis[m] * lis[l] *lis[h]
print(ans)

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

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

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

d = defaultdict(int)

n = int(input())

for _ in range(n):
    initial = input()[0]
    if initial in 'MARCH':
        d[initial] += 1

a = list(d.items())

ans = 0

for x in combinations(range(min(len(a),5)),3):
    ans += a[x[0]][1] * a[x[1]][1] * a[x[2]][1]

print(ans)

Solution (Python):
N = int(input())
member = [0,0,0,0,0]
ans = 0
for _ in range(N):
    a = list(input())
    if a[0] == "M":
        member[0] += 1
    elif a[0] == "A":
        member[1] += 1
    elif a[0] == "R":
        member[2] += 1
    elif a[0] == "C":
        member[3] += 1
    elif a[0] == "H":
        member[4] += 1
 
for i in range(3):
    for j in range(i+1, 4):
        for k in range(j+1, 5):
            ans += member[i]*member[j]*member[k]

print(ans)

Solution (Python):
N = int(input())
name_list = [input() for name in range(N)]
char_list = ['M', 'A', 'R', 'C', 'H']
count_list = [0 for _ in range(len(char_list))]

flag = False

for name in name_list:
    if name[0] in char_list:
        count_list[char_list.index(name[0])] += 1
score = 0
for x in range(5):
    for y in range(x + 1, 5):
        for z in range(y + 1, 5):
            score += count_list[x] * count_list[y] * count_list[z]

print(score)

Solution (Python):
import itertools
n = int(input())
arr = [input()[0] for i in range(n)]
word = ['M','A','R','C','H']
ans = 0
con = list(itertools.combinations(word,3))
for i in con:
    ans += arr.count(i[0]) * arr.count(i[1]) * arr.count(i[2])
print(ans)

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

S0 = list(map(lambda s:s[0],S))
M,A,R,C,H = 0,0,0,0,0

for i in range(len(S0)):
    if S0[i] == 'M':
        M = M + 1
    elif S0[i] == 'A':
        A = A + 1
    elif S0[i] == 'R':
        R = R + 1
    elif S0[i] == 'C':
        C = C + 1
    elif S0[i] == 'H':
        H = H + 1

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


c = list(itertools.combinations(Num,3));
sum =0
for w in range(len(c)):
    sum = sum +c[w][0]*c[w][1]*c[w][2]
print(sum)

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

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

print(answer)

Solution (Python):


n=int(raw_input())
m=a=r=c=h=0
for i in xrange(n):
 temp=raw_input()
 if temp[0]=='M':
  m+=1
 elif temp[0]=='A':
  a+=1
 elif temp[0]=='R':
  r+=1
 elif temp[0]=='C':
  c+=1
 elif temp[0]=='H':
  h+=1
s=[m,a,r,c,h]
res=0
for i in xrange(5):
 for j in xrange(i):
  for k in xrange(j):
   res+=s[i]*s[j]*s[k]
print res

Solution (Python):
import itertools
N = int(input())
S = [input() for i in range(N)]
listWork = list(set(S))
listMARCH = ["M","A","R","C","H"]

listPat = list(itertools.combinations("01234", 3))
m,a,r,c,h = 0,0,0,0,0

def nCr():
    cnt = 0
    for i in range(len(listPat)):
        cnt += listMARCHcnt[int(listPat[i][0])] * listMARCHcnt[int(listPat[i][1])] * listMARCHcnt[int(listPat[i][2])]
    return cnt


for i in range(N):
    if listWork[i][0] in listMARCH[0]:
        m += 1
    elif listWork[i][0] in listMARCH[1]:
        a += 1
    elif listWork[i][0] in listMARCH[2]:
        r += 1
    elif listWork[i][0] in listMARCH[3]:
        c += 1
    elif listWork[i][0] in listMARCH[4]:
        h += 1

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

print(nCr())

Solution (Python):
import itertools as it


N = int(input())

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

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


count = [S.count('M'), S.count('A'), S.count('R'), S.count('C'), S.count('H')]


answer = count[0]*count[1]*count[2]
answer = count[0]*count[1]*count[3] + answer
answer = count[0]*count[1]*count[4] + answer
answer = count[0]*count[2]*count[3] + answer
answer = count[0]*count[2]*count[4] + answer
answer = count[0]*count[3]*count[4] + answer
answer = count[1]*count[2]*count[3] + answer
answer = count[1]*count[2]*count[4] + answer
answer = count[1]*count[3]*count[4] + answer
answer = count[2]*count[3]*count[4] + answer


print(answer)

Solution (Python):

import sys
if __name__ == "__main__":
    n = int(input())
    s = [ input() for tmp in range(n) ]
    alphabetDic = { alphabet : 0 for alphabet in [ chr(tmp) for tmp in range(ord('A'), ord('A')+26) ] }
    ans = 0
    for word in s:
        alphabetDic[word[0]] += 1
    factors = [ alphabetDic[tmp] for tmp in ['M', 'A', 'R', 'C', 'H'] if alphabetDic[tmp] > 0 ]
    if len(factors) <= 2:
        print(ans)
        sys.exit()
    for tmp in range(len(factors)):
        for tmp2 in range(tmp+1, len(factors)):
            for tmp3 in range(tmp2+1, len(factors)):
                ans += factors[tmp]*factors[tmp2]*factors[tmp3]
    else:
        print(ans)

Solution (Python):


if __name__ == "__main__":
	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
	
	ans  = m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h
	ans += a*r*c + a*r*h + a*c*h
	ans += r*c*h
	print(ans)