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
from collections import Counter

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


C = Counter(S)
total = 0
for comb in combinations('MARCH', 3):
    total += C[comb[0]] * C[comb[1]] * C[comb[2]]
print(total)

Solution (Python):
N = int(input())
names = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
FIRST = ('M', 'A', 'R', 'C', 'H')
for _ in range(N):
  name = input()
  if name[0] in FIRST:
    names[name[0]] += 1
ans = 0
for i in range(5):
  for j in range(i+1, 5):
    for k in range(j+1, 5):
      ans += names[FIRST[i]]*names[FIRST[j]]*names[FIRST[k]]
print(ans)

Solution (Python):


import sys

n = int(input())
num_m = 0
num_a = 0
num_r = 0
num_c = 0
num_h = 0
for i in range(0,n):
	tmp = input()
	if(tmp[0]=='M'):
		num_m += 1
	if(tmp[0]=='A'):
		num_a += 1
	if(tmp[0]=='R'):
		num_r += 1
	if(tmp[0]=='C'):
		num_c += 1
	if(tmp[0]=='H'):
		num_h += 1

sum=0
sum+=num_m*num_a*num_r
sum+=num_m*num_a*num_c
sum+=num_m*num_a*num_h
sum+=num_m*num_r*num_c
sum+=num_m*num_r*num_h
sum+=num_m*num_c*num_h
sum+=num_a*num_r*num_c
sum+=num_a*num_r*num_h
sum+=num_a*num_c*num_h
sum+=num_r*num_c*num_h

print(sum)

Solution (Python):
N = int(input())
Al = ['M', 'A', 'R', 'C', 'H']
S = {}
for _ in range(N):
    s = input()[0]
    if s in Al:
        if not s in S.keys():
            S[s] = 1
        else:
            S[s] += 1
L = S.values()
if len(L) == 3:
    a, b, c = L
    ans = a*b*c
elif len(L) == 4:
    a, b, c ,d = L
    ans = a*b*c + a*b*d + a*c*d + b*c*d
elif len(L) == 5:
    a, b, c, d, e = L
    ans = a*b*c + a*b*d + a*c*d + b*c*d + a*b*e + a*c*e + a*d*e + b*c*e + b*d*e + c*d*e
else:
    ans = 0

print(ans)

Solution (Python):
import itertools

N = int(input())
S = [input() for _ in range(N)]
M, A, R, C, H = 0, 0, 0, 0, 0

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

comb = list(itertools.combinations([M, A, R, C, H], 3))
answer = 0 

for i in comb:
  answer += (i[0]*i[1]*i[2])

print(answer)

Solution (Python):
N = int(input())
M = A = R = C = H = 0
for _ 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

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

print(ans)

Solution (Python):

import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math





 
def main():
    N = int(input())
    s = []
    
    for i in range(N):
        tmp = input()
        s.append(tmp)
        
    m = 0
    a = 0
    r = 0
    c = 0
    h = 0
    for i in s:
        if i[0] == "M":
            m += 1
        elif i[0] == "A":
            a += 1
        elif i[0] == "R":
            r += 1
        elif i[0] == "C":
            c += 1
        elif i[0] == "H":
            h += 1
            
    
    total = (a*m*c) + (a*m*r) + (a*m*h) + (a*c*r) + (a*c*h) + (a*r*h) + (m*c*r) + (m*c*h) + (m*r*h) + (c*r*h)
            
    print(total)
	
if __name__ == "__main__":
	main()

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

ans = 0
for i, j, k in combinations("MARCH", 3):
  ans += S[i]*S[j]*S[k]
print(ans)

Solution (Python):
from itertools import combinations

M = 'MARCH'
d = {i: set() for i in M}
for _ in range(int(input())):
    s = input()
    if s[0] in M:
        d[s[0]].add(s)

cmb = list(combinations(M, 3))
ans = 0
for c in cmb:
    t = 1
    for k in c:
        t *= len(d[k])
    ans += t

print(ans)

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

names = {}
for s in S:
    initial = s[0]
    if initial not in names:
        names[initial] = 0
    names[initial] += 1

initial_keys = set(names.keys()).intersection({"M", "A", "R", "C", "H"})
if len(initial_keys) < 3:
    print(0)
else:
    initials = ["M", "A", "R", "C", "H"]
    count = 0
    for i in range(len(initials)-2):
        for j in range(i+1, len(initials)-1):
            for k in range(j+1, len(initials)):
                count += (names.get(initials[i], 0) * names.get(initials[j], 0) * names.get(initials[k], 0))
    print(count)

Solution (Python):

import sys
def input(): return sys.stdin.readline().rstrip()
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
import heapq
INF = float("inf")
sys.setrecursionlimit(10**7)

dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def mi(): return map(int, input().split())
def ii(): return int(input())


N = ii()
nums = [0 for _ in range(5)]
ans = 0

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

for i, j, k in combinations(range(5), 3):
  ans += nums[i] * nums[j] * nums[k]

print(ans)

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

ans = 0
ans += dict["M"] * dict["A"] * dict["R"]
ans += dict["M"] * dict["A"] * dict["C"]
ans += dict["M"] * dict["A"] * dict["H"]
ans += dict["M"] * dict["R"] * dict["C"]
ans += dict["M"] * dict["R"] * dict["H"]
ans += dict["M"] * dict["C"] * dict["H"]
ans += dict["A"] * dict["R"] * dict["C"]
ans += dict["A"] * dict["R"] * dict["H"]
ans += dict["A"] * dict["C"] * dict["H"]
ans += dict["R"] * dict["C"] * dict["H"]
print(ans)

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

ans = 0
for bits in range(1<<5):
    bits_list = [i for i in range(5) if (bits >> i) & 1 == 1]
    if len(bits_list) == 3:
        ans += d[t[bits_list[0]]] * d[t[bits_list[1]]] * d[t[bits_list[2]]]

print(ans)

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


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

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



H=['M','A','R','C','H']
res = 0
for i in range(0,5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            cnt = count[H[i]] * count[H[j]] * count[H[k]]
            
            res += cnt

print(res)

Solution (Python):

N = int(input())

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

word = "MARCH"

n = len(word)

dic_initial = dict()
for letter in word:
    dic_initial[letter] = 0

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

ans = 0

for p in range(n - 2):
    
    num_p = dic_initial[word[p]]
    
    if num_p == 0:
        continue
    for q in range(p + 1, n - 1):
        num_q = dic_initial[word[q]]
        if num_q == 0:
            continue
        for r in range(q + 1, n):
            num_r = dic_initial[word[r]]
            ans += num_p * num_q * num_r

print(ans)

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

t_moji = ['M', 'A', 'R', 'C', 'H']
moji = {'M': 0, 'A': 1, 'R':2, 'C': 3, 'H': 4}
buff = [0 for i in range(5)]

for i in range(N):
    flag = False
    for j in range(5):
        if t_moji[j] == S[i][0]:
            flag = True
    if flag:
        buff[moji[S[i][0]]] += 1




count = 0
for i in range(5):
    if buff[i] > 0:
        count += 1

if count < 3:
    print(0)
    exit()
else:
    
    ans = 0
    for i in range(5):
        for j in range(5):
            if i != j:
                for k in range(5):
                    if i != k and j != k:
                        ans += buff[i] * buff[j] * buff[k]
    print(ans//6)

Solution (Python):



import math

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

m,a,r,c,h = 0,0,0,0,0
for i in s:
    if i[0] == 'M':m += 1
    elif i[0] == 'A':a+= 1
    elif i[0] == 'R':r += 1
    elif i[0] == 'C':c += 1
    elif i[0] == 'H':h += 1

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

Solution (Python):
N = int(input())
m,a,r,c,h = 0,0,0,0,0
for i 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
A = [m,a,r,c,h]
ans = 0
for i in range(5):
  for j in range(min(i+1,5),5):
    for k in range(min(j+1,5),5):
      ans += A[i]*A[j]*A[k]
print(ans)

Solution (Python):
N = int(input())
d = {'M':0,'A':0,'R':0,'C':0,'H':0} 
for _ in range(N):
    c = input()[0]
    if c in 'MARCH':d[c] +=  1
gl = [d['M']*d['A']*d['R'],
        d['M']*d['A']*d['C'],
        d['M']*d['A']*d['H'],
        d['M']*d['R']*d['C'],
        d['M']*d['R']*d['H'],
        d['M']*d['C']*d['H'],
        d['A']*d['R']*d['C'],
        d['A']*d['R']*d['H'],
        d['A']*d['C']*d['H'],
        d['R']*d['C']*d['H']]
print(sum(gl))

Solution (Python):
n=int(input())
da=[input() for i in range(n)]
st='MARCH'
gg=[0 for i in range(5)]
for i in da:
    for j in range(5):
        if i[0]==st[j]:
            gg[j]+=1
ans=0
for i in range(2,5):
    for j in range(1,i):
        for k in range(0,j):
            ans+=gg[i]*gg[j]*gg[k]
print(ans)

Solution (Python):
from itertools import combinations

n = int(input())
D = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for _ in range(n):
    s = input()[0]
    if s in D:
        D[s] += 1
print(sum([i * j * k for i, j, k in combinations(D.values(), 3)]))

Solution (Python):
n = int(input())
D = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for _ in range(n):
    s = input()
    k = s[0]
    if k in D:
        D[k] += 1
L = list(D.values())
ans = 0
for i in range(len(L) - 2):
    for j in range(i + 1, len(L) - 1):
        for k in range(j + 1, len(L)):
            ans += L[i] * L[j] * L[k]
print(ans)

Solution (Python):


import sys
import math
from collections import Counter
input = sys.stdin.readline

def P(n, r):
    return math.factorial(n)//math.factorial(n-r)

def C(n, r):
    return P(n, r)//math.factorial(r)

N = int(input())
arr = [input() for i in range(N)]
ini_arr = [j[0] for j in arr if j[0] == "M" or j[0] == "A" or j[0] == "R" or j[0] == "C" or j[0] == "H"]
dic = Counter(ini_arr)
key_num = len(dic)
val_num = sum(k for k in dic.values())
if key_num < 3:
    print(0)
else:
    total = C(len(ini_arr), 3)
    for i in dic.values():
        if i == 2:
            total -= C(val_num - i, 1)
        elif i >= 3:
            total -= C(i, 2) * C(val_num - i, 1)  + C(i, 3)
    print(total)

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

count = [0]*5
countType = 0
    

for i in range(N):
    if S[i][0]  =='M':
        count[0]  = count[0] + 1
        if count[0] == 1:
            countType = countType+1
    elif S[i][0]  =='A':
        count[1]  = count[1] + 1
        if count[1] == 1:
            countType = countType+1
    elif S[i][0]  =='R':
        count[2]  = count[2] + 1
        if count[2] == 1:
            countType = countType+1
    elif S[i][0]  =='C':
        count[3]  = count[3] + 1
        if count[3] == 1:
            countType = countType+1
    elif S[i][0]  =='H':
        count[4]  = count[4] + 1
        if count[4] == 1:
            countType = countType+1
            
if countType<3:
    print(0)
else:
    ans = 1
    buf =  0
    LIST = list(itertools.combinations([0,1,2,3,4],3))
    for i in range(len(LIST)):
        for j in range(len(LIST[i])):
            ans = ans*count[LIST[i][j]]
        buf = buf + ans
        ans = 1
    print(buf)

Solution (Python):
letterlist = ['M', 'A', 'R', 'C', 'H']
countlist = [0, 0, 0, 0, 0]
N = int(input())
for i in range(0, N):
	S = input()
	for j in range(0, 5):
		if S[0] == letterlist[j]:
			countlist[j] += 1
sum = 0
for i in range(0, 5):
	for j in range(i+1, 5):
		for k in range(j+1, 5):
			sum += countlist[i]*countlist[j]*countlist[k]
print(sum)

Solution (Python):


import sys
input = sys.stdin.readline

n = int(input())
t = [0] * n
for i in range(n):
    t[i] =input()[0]
t2 = [t.count(i) for i in ["M","A","R","C","H"]]
ans = 0
for i in range(5):
    for j in range(5):
        if j == i:
            break
        for k in range(5):
            if k == j:
                break
            ans += t2[i] * t2[j] * t2[k]
print(ans)

Solution (Python):
n=int(input())
march=['M','A','R','C','H']
s=[input() for _ in range(n)]
m=[]
a=[]
r=[]
c=[]
h=[]
for i in s:
    if i[0]=='M':
        m.append(i)
    elif i[0]=='A':
        a.append(i)
    elif i[0]=='R':
        r.append(i)
    elif i[0]=='C':
        c.append(i)
    elif i[0]=='H':
        h.append(i)
m=list(set(m))
a=list(set(a))
r=list(set(r))
c=list(set(c))
h=list(set(h))
l=[len(m),len(a),len(r),len(c),len(h)]
ans=0
rr=[]
if l.count(0)<=2:
    ll=[i for i in l if i>=1]
    ans=1
    if len(ll)==3:
        for i in ll:
            ans*=i
    elif len(ll)==4:
        for i in range(2):
            for j in range(i+1,3):
                for k in range(j+1,4):
                    rr.append(ll[i]*ll[j]*ll[k])
        ans=sum(rr)
    else:
        for i in range(3):
            for j in range(i+1,4):
                for k in range(j+1,5):
                    rr.append(ll[i]*ll[j]*ll[k])
        ans=sum(rr)
print(ans)

Solution (Python):
import sys
from itertools import combinations


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

ans=0

cmb=list(combinations(s.values(),3))

for a,b,c in cmb:
    ans+=a*b*c

print(ans)

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

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

ans=0

cmb=list(combinations(s.values(),3))

for a,b,c in cmb:
    ans+=a*b*c

print(ans)

Solution (Python):


import sys

input=sys.stdin.readline

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




ans=0
for ik,iv in s.items():
    for jk,jv in s.items():
        if ik==jk:break
        for kk,kv in s.items():
            if jk==kk:break
            ans+=iv*jv*kv

print(ans)

Solution (Python):
n=int(input())
t=[0]*n
for i in range(n):
    t[i] =input()[0]
t2=[t.count(i) for i in ["M","A","R","C","H"]]
ans=0
for i in range(5):
    for j in range(5):
        if j==i:break
        for k in range(5):
            if k==j:break
            ans += t2[i]*t2[j]*t2[k]
print(ans)

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


def cmb(n, r):
    if n < r:
        return 0

    r = min(n-r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


def solve(n):
    
    p = [set() for _ in range(27)]
    for i in range(n):
        s = input()
        p[ord(s[0])-65].add(s)

    sum_of_elems = len(p[12])+len(p[17])+len(p[0])+len(p[2])+len(p[7])
    all_cmb = cmb(sum_of_elems, 3)

    for j in [12, 17, 0, 2, 7]:
        count_of_elem = len(p[j])
        all_cmb -= cmb(count_of_elem, 2) * (sum_of_elems - count_of_elem)
        all_cmb -= cmb(count_of_elem, 3)

    return all_cmb


if __name__ == '__main__':
    n = int(input())
    print(solve(n))

Solution (Python):
N = int(input())
S = list(input() for i in range(N))
march = "MARCH"
A = [0]*5
for i in S:
    if i[0] in march:
        A[march.index(i[0])]+=1
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 i in range(n)]
march = [0,0,0,0,0]
for i in range(n):
    if s[i][0:1] == "M":
        march[0] += 1
    elif s[i][0:1] == "A":
        march[1] += 1
    elif s[i][0:1] == "R":
        march[2] += 1
    elif s[i][0:1] == "C":
        march[3] += 1
    elif s[i][0:1] == "H":
        march[4] += 1

ans = 0
ans += march[0]*march[1]*march[2]
ans += march[0]*march[1]*march[3]
ans += march[0]*march[1]*march[4]
ans += march[0]*march[2]*march[3]
ans += march[0]*march[2]*march[4]
ans += march[0]*march[3]*march[4]
ans += march[1]*march[2]*march[3]
ans += march[1]*march[2]*march[4]
ans += march[1]*march[3]*march[4]
ans += march[2]*march[3]*march[4]
print(ans)

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

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

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

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

dict={"M":0, "A":0, "R":0, "C":0, "H":0}
dickey=list(dict.keys())
for i in range(n):
    if s[i][0] in dict:
        dict[s[i][0]]+=1



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

print(ans)

Solution (Python):
n=int(input())
m=[0]*5
for i in range(n):
    s=input()
    if s[0]=='M':
        m[0]+=1
    elif s[0]=='A':
        m[1]+=1
    elif s[0]=='R':
        m[2]+=1
    elif s[0]=='C':
        m[3]+=1
    elif s[0]=='H':
        m[4]+=1
ans=0
for a in range(5):
    for b in range(a+1,5):
        for c in range(b+1,5):
            ans+=m[a]*m[b]*m[c]
print(ans)

Solution (Python):
import itertools

N=int(input())
march='MARCH'
S=[]
counter={'M':0,'A':0,'R':0,'C':0,'H':0}
for _ in range(N):
    s=input()
    if s[0] in march:
        counter[s[0]]+=1
        S.append(s)
ans=0
if len(S)>=3:
    select=list(itertools.combinations(march,3))
    for i in range(len(select)):
        key=[]
        key.append(select[i][0])
        key.append(select[i][1])
        key.append(select[i][2])
        ans+=counter[key[0]]*counter[key[1]]*counter[key[2]]
print(ans)

Solution (Python):
from itertools import combinations
N = int(input())
L = [input()[0] for _ in range(N)]

ans = sum(x * y * z for x,y,z in combinations([L.count(s) for s in "MARCH"], 3))
print(ans)

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

M = 0
A = 0
R = 0
C = 0
H = 0
for i in range(N):
    tmp = S[i][0]
    if tmp == 'M':
        M += 1
    elif tmp == 'A':
        A += 1
    elif tmp == 'R':
        R += 1
    elif tmp == 'C':
        C += 1
    elif tmp == 'H':
        H += 1
P = [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 += P[i]*P[j]*P[k]
print(ans)

Solution (Python):
N=int(input())
S=[input()[0] for _ in range(N)]
from collections import Counter
S=Counter(S)
M=S["M"]
A=S["A"]
R=S["R"]
C=S["C"]
H=S["H"]
print(M*A*(R+C+H)+(M+A)*R*(C+H)+(M+A+R)*C*H)

Solution (Python):

cha = "MARCH"
dic = {}

N = int(input())

for i in range(N):

    S = input()

    if S[0] in cha and S[0] not in dic:

        dic[S[0]] = 1

    elif S[0] in cha:

        dic[S[0]] += 1

ans = 0

for i in dic:

    for j in dic:

        if i == j:
            break

        for k in dic:

            if j == k or i == k:
                break

            ans += dic[i]*dic[j]*dic[k]

print (ans)

Solution (Python):
N = int(input())
S = []
for n in range(N):
  s = input()
  if s[0] in "MARCH":
    S.append(s[0])
S_set = list(set(S))
if len(S_set) < 3:
  ans = 0
elif len(S_set) == 3:
  ans = S.count(S_set[0]) * S.count(S_set[1]) * S.count(S_set[2])
elif len(S_set) == 4:
  ans = 0
  T = [S.count(S_set[0]), S.count(S_set[1]), S.count(S_set[2]), S.count(S_set[3])]
  for i in [0, 1]:
    for j in range(i+1, len(T)-1):
      for k in range(j+1, len(T)):
        ans += T[i] * T[j] * T[k]
elif len(S_set) == 5:
  ans = 0
  T = [S.count(S_set[0]), S.count(S_set[1]), S.count(S_set[2]), S.count(S_set[3]), S.count(S_set[4])]
  for i in [0, 1, 2]:
    for j in range(i+1, len(T)-1):
      for k in range(j+1, len(T)):
        ans += T[i] * T[j] * T[k]

print(ans)

Solution (Python):
N = int(input())
S = []
for n in range(N):
  s = input()
  if s[0] in "MARCH":
    S.append(s[0])
S_set = list(set(S))
if len(S_set) < 3:
  ans = 0
elif len(S_set) == 3:
  ans = S.count(S_set[0]) * S.count(S_set[1]) * S.count(S_set[2])
elif len(S_set) == 4:
  ans = 0
  T = [S.count(S_set[0]), S.count(S_set[1]), S.count(S_set[2]), S.count(S_set[3])]
  for i in [0, 1]:
    for j in range(i+1, len(T)-1):
      for k in range(j+1, len(T)):
        ans += T[i] * T[j] * T[k]
elif len(S_set) == 5:
  ans = 0
  T = [S.count(S_set[0]), S.count(S_set[1]), S.count(S_set[2]), S.count(S_set[3]), S.count(S_set[4])]
  for i in [0, 1, 2]:
    for j in range(i+1, len(T)-1):
      for k in range(j+1, len(T)):
        ans += T[i] * T[j] * T[k]

print(ans)

Solution (Python):
from itertools import combinations

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

m = []
a = []
r = []
c = []
h = []
for i in range(N):
    if S[i][0] == 'M':
        m.append(S[i])
    elif S[i][0] == 'A':
        a.append(S[i])
    elif S[i][0] == 'R':
        r.append(S[i])
    elif S[i][0] == 'C':
        c.append(S[i])
    elif S[i][0] == 'H':
        h.append(S[i])

cnt = []
cnt.append(len(m))
cnt.append(len(a))
cnt.append(len(r))
cnt.append(len(c))
cnt.append(len(h))

com = list(combinations(range(5), 3))

ans = 0
for i in com:
    ans += cnt[i[0]]*cnt[i[1]]*cnt[i[2]]
print(ans)

Solution (Python):
import itertools

n = int(input())
lst = [str(input())[0] for i in range(n)]
l_march = ["M","A","R","C","H"]
l_a = []
for i in l_march:
    l_a.append(lst.count(i))
l_b = list(itertools.combinations(range(5),3))
ans=0
for i in l_b:
    ans += l_a[i[0]]*l_a[i[1]]*l_a[i[2]]
print(ans)

Solution (Python):

import sys

input = sys.stdin.readline

from itertools import combinations


def main():
    n = int(input())
    lst = [input().rstrip()[0] for _ in range(n)]
    print(
        sum(x * y * z for x, y, z in combinations([lst.count(s) for s in "MARCH"], 3))
    )


if __name__ == "__main__":
    main()

Solution (Python):

import sys
input = sys.stdin.readline

from itertools import combinations


def main():
    n = int(input())
    lst = [input().rstrip()[0] for _ in range(n)]
    cand = [lst.count(s) for s in "MARCH"]
    ans = sum(x * y * z for x, y, z in combinations(cand, 3))
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

from itertools import combinations


def main():
    n = int(input())
    lst = [input().rstrip()[0] for _ in range(n)]
    cand = [lst.count(s) for s in "MARCH"]
    ans = sum(x * y * z for x, y, z in combinations(cand, 3))
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

import sys
input = sys.stdin.readline

from itertools import combinations


def main():
    n = int(input())
    lst = [input().rstrip() for _ in range(n)]
    cond = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
    for i in lst:
        if i[0] in "MARCH":
            cond[i[0]] += 1
    ans = 0
    for x, y, z in combinations("MARCH", 3):
        ans += cond[x] * cond[y] * cond[z]
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

from itertools import combinations


def main():
    n = int(input())
    lst = [input().rstrip() for _ in range(n)]
    cond = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
    for i in lst:
        if i[0] in "MARCH":
            cond[i[0]] += 1
    ans = 0
    for x, y, z in combinations("MARCH", 3):
        ans += cond[x] * cond[y] * cond[z]
    print(ans)


if __name__ == "__main__":
    main()

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

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

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

Solution (Python):
import itertools

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

M=len([s for s in S if s.startswith('M')])
A=len([s for s in S if s.startswith('A')])
R=len([s for s in S if s.startswith('R')])
C=len([s for s in S if s.startswith('C')])
H=len([s for s in S if s.startswith('H')])


ans=0
for i,j,k in itertools.combinations((M,A,R,C,H), 3):
    ans+=i*j*k

print(ans)

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


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


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

Solution (Python):
n = int(input())
s = []
for i in range(n):
  s.append(str(input()))
march=[0]*5
for i in range(n):
  if s[i][0]=="M":
      march[0]+=1
  elif s[i][0]=="A":
      march[1]+=1
  elif s[i][0]=="R":
      march[2]+=1
  elif s[i][0]=="C":
      march[3]+=1
  elif s[i][0]=="H":
      march[4]+=1
ans = 0
for i in range(3):
  for j in range(i+1,4):
    for k in range(j+1,5):
      ans += march[i]*march[j]*march[k]
print(ans)

Solution (Python):
from collections import defaultdict
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N = n()
names = defaultdict(int)
for i in range(N):
    name = s()
    if name[0] not in 'MARCH':
        continue
    names[name[0]] += 1

total = 0
cand = ''.join(names.keys())
import itertools
for p in itertools.combinations(cand, 3):
    total += names[p[0]] * names[p[1]] * names[p[2]]
print(total)

Solution (Python):
import itertools

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

ans =  0
if len(dict) >= 3:
  for v in itertools.combinations(dict.keys(), 3):
    ans += dict[v[0]] * dict[v[1]] * dict[v[2]]
print(ans)

Solution (Python):
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


ans=0
ans+=m*a*r
ans+=m*a*c
ans+=m*a*h
ans+=m*r*c
ans+=m*r*h
ans+=m*c*h
ans+=a*r*c
ans+=a*r*h
ans+=a*c*h
ans+=r*c*h

print(ans)

Solution (Python):
import itertools

from sys import stdin
N = int(stdin.readline().rstrip())

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

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

for i in data:
    if i[0] == "M":
        M += 1
    
    if i[0] == "A":
        A += 1
    
    if i[0] == "R":
        R += 1
    
    if i[0] == "C":
        C += 1
    
    if i[0] == "H":
        H += 1

ans = 0
tmp = 1
for j in list(itertools.combinations([M,A,R,C,H],3)):
    for k in j:
        tmp = tmp * k
    ans += tmp
    tmp = 1
print(ans)

Solution (Python):
n = int(input())
s = "MARCH"
cnt = [0, 0, 0, 0, 0]
for i in range(n):
    name = input()
    for j in range(len(s)):
        if name[0] == s[j]:
            cnt[j] += 1
cnt = [c for c in cnt if c > 0]
if len(cnt) < 3:
    print(0)
elif len(cnt) == 3:
    print(cnt[0]*cnt[1]*cnt[2])
elif len(cnt) == 4:
    ans = 0
    for i in range(4):
        ans += cnt[0]*cnt[1]*cnt[2]*cnt[3]//cnt[i]
    print(ans)
else:
    ans = 0
    for i in range(5):
        cnt_4 =[cnt[_] for _ in range(5) if _ != i]
        for j in range(4):
            ans += cnt_4[0]*cnt_4[1]*cnt_4[2]*cnt_4[3]//cnt_4[j]
    print(ans//2)

Solution (Python):
n=int(input())
M=[]
A=[]
R=[]
C=[]
H=[]
for i in range(n):
    S=input()
    if S[0]=='M':
        M.append(S)
    elif S[0]=='A':
        A.append(S)
    elif S[0]=='R':
        R.append(S)
    elif S[0]=='C':
        C.append(S)
    elif S[0]=='H':
        H.append(S)
score=[]
if len(M)!=0:
    score.append(len(M))
if len(A)!=0:
    score.append(len(A))
if len(R)!=0:
    score.append(len(R))
if len(C)!=0:
    score.append(len(C))
if len(H)!=0:
    score.append(len(H))

l=len(score)
if l==3:
    print(score[0]*score[1]*score[2])
elif l<=2:
    print(0)
elif l==4:
    k=score[0]*score[1]*score[2]*score[3]
    ans=0
    for i in range(4):
        ans+=k//score[i]
    print(ans)
else:
    k=score[0]*score[1]*score[2]*score[3]*score[4]
    ans=0
    for i in range(4):
        for j in range(i+1,5):
            ans+=k//(score[i]*score[j])
    print(ans)

Solution (Python):
march = ['M', 'A', 'R', 'C', 'H']
N = int(input())
S = []
people = {prefix: 0 for prefix in march}
for _ in range(N):
	s = input()
	for prefix in march:
		if s[0] == prefix:
			people[prefix] += 1
			break

ns = [n for n in people.values() if n > 0]
ans = 0
for i in range(len(ns)-2):
	for j in range(i+1,len(ns)-1):
		for k in range(j+1, len(ns)):
			ans += ns[i]*ns[j]*ns[k]
			
print(ans)

Solution (Python):
N,S=int(input()),""
for _ in range(N):S+=input()[0]
M,A,R,C,H=S.count("M"),S.count("A"),S.count("R"),S.count("C"),S.count("H")
print(M*A*R+M*A*C+M*A*H+M*R*C+M*R*H+M*C*H+A*R*C+A*R*H+A*C*H+R*C*H)

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

counter = Counter(S)
answer = 0
for x,y,z in itertools.combinations('MARCH',3):
  answer += counter[x] * counter[y] * counter[z]

print(answer)

Solution (Python):
from collections import defaultdict
def main():
	N = int(input())
	march_list = ["M", "A", "R", "C", "H"]
	march_dict = defaultdict(int)
	for _ in range(N):
		x = input()
		if x[0] in march_list:
			march_dict[x[0]] += 1

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


if __name__ == '__main__':
    main()