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):
n = int(input())
march = ["M", "A", "R", "C", "H"]
d = {"M":0, "A":0, "R":0, "C":0, "H":0}


for i in range(n):
    s = input()
    if s[0] in march:
        d[s[0]] = d.get(s[0], 0)+1
ans = 0
li = []
for i in d:
    for j in d:
        for k in d:
            if i!=j and j!=k and k!=i and not set([i,j,k]) in li:
                li.append(set([i,j,k]))
                ans += d[i]*d[j]*d[k]
print(ans)

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

c = (
    s.count("M"),
    s.count("A"),
    s.count("R"),
    s.count("C"),
    s.count("H"),
)
from itertools import combinations
a = sum(x*y*z for x, y, z in combinations(c, 3))
print(a, flush=True)

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

ans = 0

set_m = set()
set_a = set()
set_r = set()
set_c = set()
set_h = set()

for i in range(n):
    s = input()
    if s[0] == "M":
        set_m.add(s)
    if s[0] == "A":
        set_a.add(s)
    if s[0] == "R":
        set_r.add(s)
    if s[0] == "C":
        set_c.add(s)
    if s[0] == "H":
        set_h.add(s)

l_m = len(set_m)
l_a = len(set_a)
l_r = len(set_r)
l_c = len(set_c)
l_h = len(set_h)

l_l = [l_m,l_a,l_r,l_c,l_h]

comb_list = list(itertools.combinations(l_l,3))

for i in range(len(comb_list)):
    ans += comb_list[i][0]*comb_list[i][1]*comb_list[i][2]

print(ans)

Solution (Python):
n=int(input())
l=[0,0,0,0,0]
for _ in range(n):
    s=input()
    if s[0]=='M':l[0]+=1
    if s[0] == 'A': l[1] += 1
    if s[0] == 'R': l[2] += 1
    if s[0] == 'C': l[3] += 1
    if s[0] == 'H': l[4] += 1

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

Solution (Python):
n=int(input())
l=[0,0,0,0,0]
for _ in range(n):
    s=input()
    if s[0]=='M':l[0]+=1
    if s[0] == 'A': l[1] += 1
    if s[0] == 'R': l[2] += 1
    if s[0] == 'C': l[3] += 1
    if s[0] == 'H': l[4] += 1

for i in l:
    if i==0:l.remove(i)
total=len(l)
if total<3:ans=0
else:
    ans=0
    for i in range(0,total-2):
        for j in range(i+1,total-1):
            for k in range(j+1,total):
                ans+=l[i]*l[j]*l[k]
print(ans)

Solution (Python):
n = int(input())
a = [0] * 5
for i in range(n):
  s = 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

res = 0
res += a[0] * a[1] * a[2]
res += a[0] * a[1] * a[3]
res += a[0] * a[1] * a[4]
res += a[0] * a[2] * a[3]
res += a[0] * a[2] * a[4]
res += a[0] * a[3] * a[4]
res += a[1] * a[2] * a[3]
res += a[1] * a[2] * a[4]
res += a[1] * a[3] * a[4]
res += a[2] * a[3] * a[4]
print(res)

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

dic = {"M" : 0, "A": 0, "R": 0, "C": 0, "H": 0}
for _ in range(N):
  s = input()
  if s[0] in dic:
    dic[s[0]] += 1
      
char = ["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 += dic[char[i]] * dic[char[j]] * dic[char[k]]
      
print(ans)

Solution (Python):


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

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

print(ans)

Solution (Python):
from itertools import combinations

n = int(input())
S = [input() for _ in range(n)]
initials = ('M', 'A', 'R', 'C', 'H')
d = {}
for s in S:
  if s[0] in initials:
    d[s[0]] = d.get(s[0], 0) + 1

print(sum(d[x] * d[y] * d[z] for x, y, z in combinations(d.keys(), 3)))

Solution (Python):
import math
"""
int(input())
map(int, input().split())
list(map(int, input().split()))
input()
input().split()
"""

n = int(input())
ans = 0
dp = [0,0,0,0,0]
for i in range(n):
    s = input()
    if (s[0]=='M'): dp[0]+=1
    elif (s[0]=='A'): dp[1]+=1
    elif (s[0]=='R'): dp[2]+=1
    elif (s[0]=='C'): dp[3]+=1
    elif (s[0]=='H'): dp[4]+=1
for i in range(5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            ans += dp[i]*dp[j]*dp[k]

print(ans)

Solution (Python):

"""
Created on Wed Sep 23 14:49:47 2020

@author: liang
"""

"""
【組み合わせ生成】
    itertools.combinations(iterable, r)
【総積】
    numpy.prod(iterable)
"""
from itertools import combinations
import numpy as np

N = int(input())
d = [0]*5
for i in range(N):
    s = input()
    if s[0] == "M":
        d[0] += 1
    if s[0] == "A":
        d[1] += 1
    if s[0] == "R":
        d[2] += 1
    if s[0] == "C":
        d[3] += 1
    if s[0] == "H":
        d[4] += 1
    
ans = 0
for lis in combinations(d,3):
    ans += np.prod(lis)
print(ans)

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

MARCH_dic = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
MARCH_list = ['M', 'A', 'R', 'C', 'H']

for i in range(N):
  if S[i][0] in MARCH_list:
    MARCH_dic[S[i][0]] += 1
    
p_01 = MARCH_dic['M'] * MARCH_dic['A'] * MARCH_dic['R']
p_02 = MARCH_dic['M'] * MARCH_dic['A'] * MARCH_dic['C']
p_03 = MARCH_dic['M'] * MARCH_dic['A'] * MARCH_dic['H']
p_04 = MARCH_dic['M'] * MARCH_dic['R'] * MARCH_dic['C']
p_05 = MARCH_dic['M'] * MARCH_dic['R'] * MARCH_dic['H']
p_06 = MARCH_dic['M'] * MARCH_dic['C'] * MARCH_dic['H']
p_07 = MARCH_dic['A'] * MARCH_dic['R'] * MARCH_dic['C']
p_08 = MARCH_dic['A'] * MARCH_dic['R'] * MARCH_dic['H']
p_09 = MARCH_dic['A'] * MARCH_dic['C'] * MARCH_dic['H']
p_10 = MARCH_dic['R'] * MARCH_dic['C'] * MARCH_dic['H']

ans = 0

for i in range(10):
  ans += eval(f"p_{str(i+1).zfill(2)}")
  
print(ans)

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

MARCH = [0,0,0,0,0]

for i in range (0, N):
	S = str(input())
	if S[0] == 'M':
		MARCH[0]+=1
	if S[0] == 'A':
		MARCH[1]+=1
	if S[0] == 'R':
		MARCH[2]+=1
	if S[0] == 'C':
		MARCH[3]+=1
	if S[0] == 'H':
		MARCH[4]+=1
        
import itertools as it
mokou = list(it.product([0,1], repeat = 5))
count = 0

for i in range (0, len(mokou)):
	if sum(mokou[i]) == 3:
		zen = 1
		for j in range (0, 5):
			if mokou[i][j] == 1:
				zen=zen*MARCH[j]
		count+=zen
        
print(count)

Solution (Python):
import collections
import itertools

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

for i in S:
    if i == 'M' or i == 'A' or i == 'R' or i == 'C' or i == 'H':
        A.append(i)
        
if len(A) != 0:       
    C = collections.Counter(A).most_common()
    v,c = zip(*C)
    
    

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

print(ans)

Solution (Python):
N = int(input())
text = "MARCH"
d = {a:0 for a in text}
for _ in range(N):
  s = input()[0]
  if s in text:
    d[s] += 1

tot = 0
L = [v for k,v in d.items()]
for i in range(0,5):
  for j in range(i+1,5):
    for k in range(j+1,5):
      
      tot += L[i]*L[k]*L[j]


print(tot)

Solution (Python):
n = int(input())
march = {}
for s in "MARCH":
  march[s] = 0
for _ in range(n):
  s = input()[0]
  if s in "MARCH":
    march[s] += 1
ans = 0
for i in range(5):
  s1 = "MARCH"[i]
  n1 = march[s1]
  for j in range(i + 1, 5):
    s2 = "MARCH"[j]
    n2 = march[s2]
    for k in range(j + 1, 5):
      s3 = "MARCH"[k]
      n3 = march[s3]
      ans += n1 * n2 * n3
print(ans)

Solution (Python):
from itertools import combinations

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

letters = {"M":0, "A":0, "R":0, "C":0, "H":0, }
to_check = combinations([i for i in "MARCH"], 3)

for word in s:
    if word[0] in letters:
        letters[word[0]] += 1

count = 0
for i in to_check:
    count += letters[i[0]] * letters[i[1]] * letters[i[2]]

print(count)

Solution (Python):
from itertools import combinations
from collections import Counter
N = int(input())
S = Counter()
for i in range(N):
  S[input()[0]]+=1
print(sum([S[a]*S[b]*S[c] for a,b,c in combinations("MARCH",3)]))

Solution (Python):
n = int(input())
Mnum = 0
Anum = 0
Rnum = 0
Cnum = 0
Hnum = 0
for i in range(n):
  a = input()
  if a[0] == "M":
    Mnum+=1
  elif a[0] == "A":
    Anum+=1
  elif a[0] == "R":
    Rnum+=1
  elif a[0] == "C":
    Cnum+=1
  elif a[0] == "H":
    Hnum+=1
alist = []
alist.append(Mnum)
alist.append(Anum)
alist.append(Rnum)
alist.append(Cnum)
alist.append(Hnum)
from itertools import combinations
print(sum([a*b*c for a,b,c in combinations(alist,3)]))

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

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

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

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

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

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

Solution (Python):
from collections import Counter
from itertools import combinations, starmap
func = lambda x, y, z: x*y*z

def main():
    with open(0) as f:
        N, *S = f.read().split()
    S = [s[0] for s in S if s[0] in list('MARCH')]
    S = Counter(S)
    ans = sum(starmap(func, combinations(S.values(), 3)))
    print(ans)

main()

Solution (Python):
N=int(input())
S=[input() for _ in range(N)]
cnt=[0]*N
cnt2=[]
flag=0

if len(S)>1:
    for i in range(N):
        if S[i][0]=='M':
            cnt[0]+=1
        elif S[i][0]=='A':
            cnt[1]+=1
        elif S[i][0]=='R':
            cnt[2]+=1
        elif S[i][0]=='C':
            cnt[3]+=1
        elif S[i][0]=='H':
            cnt[4]+=1

for i in range(N):
    if cnt[i]!=0:
        cnt2.append(cnt[i])
        
import math
import itertools
ans=0

for v in itertools.combinations(cnt2, 3):
    ans+=v[0]*v[1]*v[2]

print(ans)

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

name_d = ['M','A','R','C','H']
sub_s = {}
for d in name_d:                    
    sub_s[d] = 0

for s in s_l:
    if s[0] in name_d:
        sub_s[s[0]] += 1

ans = 0
memo = set()
for i in range(5):
    for j in range(5):
        for k in range(5):
            a,b,c = sorted([i, j, k])
            if a != b and a!=c and b!=c:
                key = str(a)+str(b)+str(c)
                if key not in memo:
                    ans +=sub_s[name_d[a]] * sub_s[name_d[b]] * sub_s[name_d[c]]
                    memo.add(key)
print(ans)

Solution (Python):
from itertools import combinations as cmbs
from sys import stdin


def main():
    c = {"M":0,"A":0,"R":0,"C":0,"H":0}
    for si in map(lambda s:s[0],stdin):
        if si in c:
            c[si] += 1
    print(sum(i*j*k for i,j,k in cmbs(c.values(),r=3)))


main()

Solution (Python):
from itertools import combinations as cmbs
from sys import stdin
c = {"M":0,"A":0,"R":0,"C":0,"H":0}
for si in map(lambda s:s[0],stdin):
    if si in c:
        c[si] += 1
print(sum(i*j*k for i,j,k in cmbs(c.values(),r=3)))

Solution (Python):
from itertools import combinations as cmbs
import sys
c = {"M":0,"A":0,"R":0,"C":0,"H":0}
for si in map(lambda s:s[0],sys.stdin):
    if si in c:
        c[si] += 1
ans = sum(i*j*k for i,j,k in cmbs(c.values(),r=3))
print(ans)

Solution (Python):
from itertools import combinations as cmbs
import sys
c = {"M":0,"A":0,"R":0,"C":0,"H":0}
sys.stdin.readline()
for si in sys.stdin:
    if si[0] in c:
        c[si[0]] += 1
ans = sum(i*j*k for i,j,k in cmbs(c.values(),r=3))
print(ans)

Solution (Python):
from itertools import combinations as cmbs
import sys
c = {"M":0,"A":0,"R":0,"C":0,"H":0}
for i in range(int(input())):
  si = sys.stdin.readline()[0]
  if si in c:
    c[si] += 1
ans = sum(i*j*k for i,j,k in cmbs(c.values(),r=3))
print(ans)

Solution (Python):
from itertools import combinations as cmbs
import sys
c = {"M":0,"A":0,"R":0,"C":0,"H":0}
for i in range(int(input())):
  si = sys.stdin.readline()
  if si[0] in c:
    c[si[0]] += 1
ans = sum(i*j*k for i,j,k in cmbs(c.values(),r=3))
print(ans)

Solution (Python):
from itertools import combinations as cmbs
import sys
c = {"M":0,"A":0,"R":0,"C":0,"H":0}
for i in range(int(input())):
  si = sys.stdin.readline()
  if si[0] in c:
    c[si[0]] += 1
ans = 0
for i,j,k in cmbs(c.values(),r=3):
  t = i*j*k
  ans += t
print(ans)

Solution (Python):
N = int(input())
M = []
A = []
R = []
C = []
H = []
for _ in range(N):
    s = input()
    if s.startswith("M"):
        M.append(s)
    if s.startswith("A"):
        A.append(s)
    if s.startswith("R"):
        R.append(s)
    if s.startswith("C"):
        C.append(s)
    if s.startswith("H"):
        H.append(s)

m = len(M)
a = len(A)
r = len(R)
c = len(C)
h = len(H)
ans = m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h
print(ans)

Solution (Python):
from collections import defaultdict
from itertools import combinations
def inpl(): return list(map(int, input().split()))

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

res = 0
for H in combinations("MARCH", r=3):
    res += C[H[0]] * C[H[1]] * C[H[2]]
print(res)

Solution (Python):
from collections import Counter

n = int(input())
s = [input() for _ in range(n)]
cnt = 0
c = Counter(x[0] for x in s)
for x in s:
    if x[0] in "MARCH":
        cnt += 1
ans = cnt * (cnt - 1) * (cnt - 2) // 6
for k, v in c.items():
    if k not in "MARCH":
        continue
    if v >= 2:
        ans -= v * (v - 1) // 2 * (cnt - v)
    if v >= 3:
        ans -= v * (v - 1) * (v - 2) // 6
print(ans)

Solution (Python):
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    D = dict()
    W = ["M", "A", "R", "C", "H"]
    for w in W: D[w] = 0
    for _ in range(N):
        S = input().strip("\n")
        if S[0] in W:
            D[S[0]] += 1
    
    ans = 0
    for i in range(3):
        for j in range(i+1, 4):
            for k in range(j+1, 5):
                ans += D[W[i]] * D[W[j]] * D[W[k]]
    print(ans)

    return 0

if __name__ == "__main__":
    solve()

Solution (Python):
from itertools import combinations as cmbs
c = {"M":0,"A":0,"R":0,"C":0,"H":0}
for i in range(int(input())):
  si = input()
  if si[0] in c:
    c[si[0]] += 1
ans = 0
for i,j,k in cmbs(c.values(),r=3):
  t = i*j*k
  ans += t
print(ans)

Solution (Python):
n = int(input())
m = 0
a = 0
r = 0
c = 0
h = 0
for _ 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


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

Solution (Python):
def idx_cmb(n, r):
    import itertools
    lst1 = [i for i in range(0, n)]
    lst = list(itertools.combinations(lst1, r))
    return lst


def main():
    n = int(input())
    s_lst = [str(input()) for _ in range(n)]

    march = [0] * 5
    for i in range(n):
        s = s_lst[i]
        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

    idx_lst = idx_cmb(5, 3)
    x = 0
    for i in range(len(idx_lst)):
        idx1 = idx_lst[i][0]
        idx2 = idx_lst[i][1]
        idx3 = idx_lst[i][2]
        number1 = march[idx1]
        number2 = march[idx2]
        number3 = march[idx3]
        x += number1 * number2 * number3

    print(x)


if __name__ == '__main__':
    main()

Solution (Python):
import itertools
N=int(input())
s=set(["M","A","R","C","H"])
d=dict(zip(list(s),[0]*5))
for _ in range(N):
    try:
        d[input()[0]]+=1
    except KeyError:
        pass
ans=0
for v in itertools.combinations(d.keys(), 3):
    ans+=d[v[0]]*d[v[1]]*d[v[2]]

print(ans)

Solution (Python):
n=int(input())
march=["M","A","R","C","H"]
cnt=[0]*5
for i in range(n):
  inp=input()
  for j in march:
    if inp[0]==j:
      cnt[march.index(j)]+=1
ans=0
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):
import itertools

n = int(input())
d = {'M':0, 'A':1, 'R':2, 'C':3, 'H':4}
h = [0, 0, 0, 0, 0]
for _ in range(n):
  name = input()
  if name[0] in d.keys():
    h[d[name[0]]] += 1

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

Solution (Python):
import itertools
 
n = int(input())
 
 
data = [[] for i in range(5)]

for i in range(n):
    tmp = str(input())
    if tmp[0] == "M":
        data[0].append(tmp)
    elif tmp[0] == "A":
        data[1].append(tmp)
    elif tmp[0] == "R":
        data[2].append(tmp)
    elif tmp[0] == "C":
        data[3].append(tmp)
    elif tmp[0] == "H":
        data[4].append(tmp)
 
ans = 0
for i, j, k in itertools.combinations([0, 1, 2, 3, 4], 3):
    ans += len(data[i])*len(data[j])*len(data[k])
print(ans)

Solution (Python):
N=int(input())
S=[input()[0] for _ in range(N)]
A=[S.count(c) for c in "MARCH"]
ans=0
for i in range(5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            ans+=A[i]*A[j]*A[k]
print(ans)

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

Solution (Python):
import itertools

n = int(input())

name = {"M":[],"A":[],"R":[],"C":[],"H":[]}
for i in range(n):
    s = input()
    if s[0] not in name:
        continue
    else:
        name[s[0]].append(s)

ans = 0
for p,q,r in itertools.combinations(name.keys(), 3):
    ans += len(name[p])*len(name[q])*len(name[r])
    
print(ans)

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


def read():
    N = int(input().strip())
    S = []
    for i in range(N):
        s = input().strip()
        S.append(s)
    return N, S


def solve(N, S):
    Z = [0 for i in range(26)]
    for s in S:
        a = s[0]
        Z[ord(a)-ord("A")] += 1
    ans = 0
    D = [Z[ord(a)-ord("A")] for a in "MARCH"]
    for i, j, k in combinations(D, r=3):
        ans += i * j * k
    return ans


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Solution (Python):
import itertools
from collections import defaultdict
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N = ii()
    count = defaultdict(lambda:0)

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

    ans =0
    X = []
    for x in ["M","A","R","C","H"]:
        if count[x] < 1: continue
        X.append(x)
    
    if len(X) < 3:
        print(0)
        exit()

    for V in itertools.combinations(X,3):
        U = list(V)
        res = 1
        for u in U:
            res *= count[u]
        
        ans += res


    print(ans)

        
     


if __name__ == "__main__":
    main()

Solution (Python):

import itertools

n = int(input())


data = [[] for i in range(5)]

for i in range(n):
    tmp = str(input())
    if tmp[0] == "M":
        data[0].append(tmp)
    elif tmp[0] == "A":
        data[1].append(tmp)
    elif tmp[0] == "R":
        data[2].append(tmp)
    elif tmp[0] == "C":
        data[3].append(tmp)
    elif tmp[0] == "H":
        data[4].append(tmp)

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

Solution (Python):



import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """4
ZZ
ZZZ
Z
ZZZZZZZZZZ"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO"""
        output = """7"""
        self.assertIO(input, output)


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

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

    ans = 0
    for i, c1 in enumerate(C):
        for j, c2 in enumerate(C[i+1:], i+1):
            for c3 in C[j+1:]:
                ans += c1*c2*c3

    print(ans)


if __name__ == "__main__":
    
    resolve()

Solution (Python):
N = int(input())
A = [0, 0, 0, 0, 0]
for i in range(N):
  s = 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
ans = 0
for i in range(3):
  for j in range(i+1, 4):
    for k in range(j+1, 5):
      ans += A[i] * A[j] * A[k]
print(ans)

Solution (Python):
n=int(input())
dict={'M':0,'A':0,'R':0,'C':0,'H':0}
for i in range(n):
  s=input()
  if s[0] in dict:
    dict[s[0]]+=1
data=['M','A','R','C','H']
ans=0
for i in range(3):
  for j in range(i+1,4):
    for k in range(j+1,5):
      ans+=dict[data[i]]*dict[data[j]]*dict[data[k]]
print(ans)

Solution (Python):
n=int(input())
s=[input() for _ in range(n)]
sdic={}
march=['M', 'A', 'R', 'C', 'H']
ans=0
for i in range(n):
  if s[i][0] in march:
    if s[i][0] in sdic:
      sdic[s[i][0]]+=1
    else:
      sdic[s[i][0]]=1
lis=[_ for _ in sdic.values()]
for j in range(len(lis)-2):
  for k in range(j+1,len(lis)-1):
    for l in range(k+1,len(lis)):
      ans+=lis[j]*lis[k]*lis[l]
print(ans)

Solution (Python):

import collections
import itertools
N = int(input())
S = [input() for _ in range(N)]
S = [s[0] for s in S if s[0] == 'M' or s[0] == 'A' or s[0] == 'R' or s[0] == 'C' or s[0] == 'H']

cnt = collections.Counter(S)

comb = itertools.combinations(cnt.keys(),3)

ans = 0
for a,b,c in comb:
    ans += cnt[a]*cnt[b]*cnt[c]
print(ans)

Solution (Python):
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right 
from heapq import heapify, heappop, heappush
from itertools import combinations, permutations, product
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x):
        self.setdefault(x,0)
        self[x] += 1

N = int(input())
L = [0]*26
for _ in range(N):
    S = input()
    L[ston(S[0],'A')] += 1
s = ['M','A','R','C','H']
ans = 0
for l in combinations(s,3):
    x,y,z = map(lambda x:ston(x,'A'), l)
    ans += L[x]*L[y]*L[z]
print(ans)

Solution (Python):
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right 
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x):
        self.setdefault(x,0)
        self[x] += 1

N = int(input())
L = [0]*26
for _ in range(N):
    S = input()
    L[ston(S[0],'A')] += 1
s = ['M','A','R','C','H']
ans = 0
for l in [[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]]:
    x,y,z = map(lambda x:ston(s[x],'A'), l)
    ans += L[x]*L[y]*L[z]
print(ans)

Solution (Python):

import math

N = int(input())

first = "MARCH"

dic = {s:0 for s in first}

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

t = []
for key in dic:
    if dic[key] > 0:
        t.append(dic[key])

if len(t) < 3:
    print(0)
else:
    tl = len(t)
    ans = 0
    for i in range(2 ** tl):
        cnt = []
        for j in range(tl):
            if (i >> j) & 1:
                cnt.append(j)

        if len(cnt) == 3:
            tans = 1
            for i in cnt:
                tans *= t[i]

            ans += tans
    
    print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    L = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
    for i in range(N):
        S = input().rstrip()
        if S[0] in L:
            L[S[0]] += 1
    CNT = 0
    i = 0
    S = [0]*5
    for k, v in L.items():
        S[i] = v
        i += 1
    ans = 0
    for p in range(3):
        for q in range(p+1,4):
            for r in range(q+1,5):
                ans += S[p]*S[q]*S[r]
    print(ans)
    

if __name__ == '__main__':
    main()

Solution (Python):
from itertools import combinations
N = int(input())

march = [0] * 5
for _ in range(N):
  S = input()
  S = S[0]
  if S == "M":
    march[0] += 1
  elif S == "A":
    march[1] += 1
  elif S == "R":
    march[2] += 1
  elif S == "C":
    march[3] += 1
  elif S == "H":
    march[4] += 1
  
ls = list(combinations(range(5),3))

ans = 0
for (i,j,k) in ls:
  ans += march[i] * march[j] * march[k]
  
print(ans)

Solution (Python):
from collections import defaultdict
import itertools

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

ans = 0
for c in itertools.combinations(list('MARCH'), 3):
    a = 1
    for cc in c:
        a *= r[cc]
    ans += a
print(ans)

Solution (Python):
import itertools
from collections import defaultdict

n = int(input())
d = defaultdict(int)

for i in range(n):
    s = input()
    for e in ["M", "A", "R", "C", "H"]:
        if s[0] == e:
            d[e] += 1

sum_num = 0
l = ["M", "A", "R", "C", "H"]
for a, b, c in itertools.combinations(l, 3):
    sum_num += d[a] * d[b] * d[c]
print(sum_num)

Solution (Python):
n=int(input())
D={"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"]:
        D[s[0]]+=1

from itertools import combinations as com 
ans=0
A=list(D.values()) ; 
for l in com(list(range(5)), 3):
    ans+= A[l[0]]* A[l[1]] * A[l[2]]
print(ans)

Solution (Python):
N=int(input())
d={}
l="MARCH"
c=[0 for _ in range(5)]
for n in range(N):
    S=input()
    for n in range(len(l)):
        if l[n]==S[0]:
            c[n]+=1
ans=0
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            ans+=c[i]*c[j]*c[k]
print(ans)

Solution (Python):
from sys import stdin
rs = lambda : stdin.readline().strip()
ri = lambda : int(rs())
ril = lambda : list(map(int, rs().split()))

def main():
    N = ri()
    d = {s: i for i, s in enumerate('MARCH')}
    l = [0] * 5
    for i in range(N):
        s = rs()[0]
        if s in d:
            l[d[s]] += 1
    ans = 0
    for i in range(3):
        for j in range(i + 1, 4):
            for k in range(j + 1, 5):
                ans += l[i] * l[j] * l[k]
    print(ans)




if __name__ == '__main__':
    main()

Solution (Python):
import sys
import itertools

input = sys.stdin.readline

def main():
    N = int(input())
    l = ['M', 'A', 'R', 'C', 'H']
    m = [0]*5
    for _ in range(N):
        S = input()[:-1]
        Shead = S[0]
        for i, s0 in enumerate(l):
            if Shead == s0:
                m[i] += 1
                break
    ll = []
    for i, n in enumerate(m):
        if n >= 1:
            ll.append(l[i])
    if len(ll) <= 2:
        print(0)
        return
    ans = 0
    for i, j, k in itertools.combinations(ll, 3):
        ans += m[l.index(i)] * m[l.index(j)] * m[l.index(k)]

    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
M = 0
A = 0
R = 0
C = 0
H = 0
for i in range(N):
    S = input()
    s = S[0]
    if s == "M":
        M += 1
    elif s == "A":
        A += 1
    elif s == "R":
        R += 1
    elif s == "C":
        C += 1
    elif s == "H":
        H += 1
ans = 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)