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())
s = []

mrch = ["M","A","R","C","H"]
memo = [0 for i in range(5)]

for i in range(n):
    a = list(input())
    for j in range(5):
        if a[0] == mrch[j]:
            memo[j] += 1

ans = 0
for i in range(2**5):
    cnt = 0
    memo2 = 1
    for j in range(5):
        
        if (i >> j) & 1:
            
            cnt += 1
            memo2 *= memo[j]
    if cnt == 3:
        ans += memo2
        

print(ans)

Solution (Python):
n=int(input())
m=[]
a=[]
r=[]
c=[]
h=[]
for i in range(n):
    A=input()
    if A[0]=="M":
        m.append(A)
    elif A[0]=="A":
        a.append(A)
    elif A[0]=="R":
        r.append(A)
    elif A[0]=="C":
        c.append(A)
    elif A[0]=="H":
        h.append(A)
m=len(m)
a=len(a)
r=len(r)
c=len(c)
h=len(h)
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):
from itertools import combinations as comb
n = int(input())
d = {'M':0,'A':0,'R':0,'C':0,'H':0}
for i in range(n):
  try:
    d[input()[0]] += 1
  except:
    continue
c = 0
l = d.values()
for i,j,k in comb(l,3):
  c += i*j*k
print(c)

Solution (Python):
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac
import fractions
from functools import reduce
from operator import mul
import bisect
import sys
import logging
import heapq
import itertools



input = sys.stdin.readline

setrecursionlimit(1000000)


def main():
	n = int(input())
	s = defaultdict(set)
	for _ in range(n):
		t = input()
		if(t[0] in ['M','A','R','C','H']):
			s[t[0]].add(t)
	s = list(s.values())
	ans = 0
	for i in itertools.permutations(s,3):
		ans += len(i[0]) * len(i[1]) * len(i[2])
	print(ans//6)

def factorization(n):
	arr = []
	temp = n
	for i in range(2, int(-(-n**0.5//1))+1):
		if temp%i==0:
			cnt=0
			while temp%i==0:
				cnt+=1
				temp //= i
			arr.append([i, cnt])

	if temp!=1:
		arr.append([temp, 1])

	if arr==[]:
		arr.append([n, 1])

	return arr

def cmb(n,r):
    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 zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def lcm(numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

class PriorityQueue():
	def __init__(self):
		self.queue = []
	def push(self,i):
		heapq.heappush(self.queue,-i)
	def pop(self):
		return -1 * heapq.heappop(self.queue)
	def sum(self):
		return -sum(self.queue)

main()

Solution (Python):

N = int(input())
ans = 0
a_l = {"M":0, "A":0, "R":0, "C":0, "H":0}
a_l = [0] * 5
a_l_char = ["M", "A", "R", "C", "H"]
for _ in range(N):
    tmp = input()
    
    for i in range(len(a_l_char)):
        if tmp[0] == a_l_char[i]:
            a_l[i] += 1
ans += a_l[0] * a_l[1] * a_l[2]
ans += a_l[0] * a_l[1] * a_l[3]
ans += a_l[0] * a_l[1] * a_l[4]
ans += a_l[0] * a_l[2] * a_l[3]
ans += a_l[0] * a_l[2] * a_l[4]
ans += a_l[0] * a_l[3] * a_l[4]

ans += a_l[1] * a_l[2] * a_l[3]
ans += a_l[1] * a_l[2] * a_l[4]
ans += a_l[1] * a_l[3] * a_l[4]

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

print(ans)

Solution (Python):
import sys
import collections
import itertools


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    d = collections.defaultdict(lambda: collections.defaultdict(list))
    for i in range(n):
        s = str(input().rstrip('\n'))
        if s[0] == "M":
            d["M"][s]
        elif s[0] == "A":
            d["A"][s]
        elif s[0] == "R":
            d["R"][s]
        elif s[0] == "C":
            d["C"][s]
        elif s[0] == "H":
            d["H"][s]
    ls = [0] * len(d)
    cur = 0
    for v in d.values():
        ls[cur] += len(v)
        cur += 1
    t = 0
    for v in itertools.combinations(ls, 3):
        t += (v[0] * v[1] * v[2])
    print(t)


if __name__ == '__main__':
    solve()

Solution (Python):
from collections import Counter
import itertools

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

c = Counter(S)
print(sum(c[x]*c[y]*c[z]  for x, y, z in itertools.combinations('MARCH', 3)))

Solution (Python):
from itertools import combinations

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

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


x = list(combinations(lst, 3))


ans = 0
for a,b,c in x:
    ans += a * b * c
print(ans)

Solution (Python):
N=int(input())
KEY = 'MARCH'

d={}
for i in KEY:
	d[i]=0

for i in range(N):
	t = input()[0]
	if t in KEY:
		d[t]+=1

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

print(ans)

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

C=[0]*5
for i in range(N):
  s=list(input())
  if s[0]=="M":
    C[0]+=1
  elif s[0]=="R":
    C[1]+=1
  elif s[0]=="A":
    C[2]+=1
  elif s[0]=="C":
    C[3]+=1
  elif s[0]=="H":
    C[4]+=1
    
ans=0
for i,j,k 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]]:
  ans+=C[i]*C[j]*C[k]
  
print(ans)

Solution (Python):
N=int(input())
a=[0,0,0,0,0]
for i in range(N):
    c=input()[0]
    if c=='M':
        a[0]+=1
    elif c=='A':
        a[1]+=1
    elif c=='R':
        a[2]+=1
    elif c=='C':
        a[3]+=1
    elif c=='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())
name_dict={'M':0,'A':0,'R':0,'C':0,'H':0}
for n in range(N):
    S=list(input())
    if S[0] in name_dict:
        name_dict[S[0]]+=1

ans=name_dict['M']*name_dict['A']*name_dict['R']\
    +name_dict['M']*name_dict['A']*name_dict['C']\
    +name_dict['M']*name_dict['A']*name_dict['H']\
    +name_dict['M']*name_dict['R']*name_dict['C']\
    +name_dict['M']*name_dict['R']*name_dict['H']\
    +name_dict['M']*name_dict['C']*name_dict['H']\
    +name_dict['A']*name_dict['R']*name_dict['C']\
    +name_dict['A']*name_dict['R']*name_dict['H']\
    +name_dict['A']*name_dict['C']*name_dict['H']\
    +name_dict['R']*name_dict['C']*name_dict['H']
print(ans)

Solution (Python):
n=int(input())
s=[]
c=[]
ans=0
for i in range(n):
  s.append(input()[0])
for x in 'MARCH':
  c.append(s.count(x))
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):
def main():
    cnt_march = [0] * 5
    N = int(input())
    for _ in range(N):
        S = input()
        if S[0] == 'M':
            cnt_march[0] += 1
        elif S[0] == 'A':
            cnt_march[1] += 1
        elif S[0] == 'R':
            cnt_march[2] += 1
        elif S[0] == 'C':
            cnt_march[3] += 1
        elif S[0] == 'H':
            cnt_march[4] += 1

    ans = 0
    from itertools import combinations
    for i, j, k in combinations(range(5), 3):
        ans += cnt_march[i] * cnt_march[j] * cnt_march[k]

    print(ans)


if __name__ == '__main__':
    main()

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

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

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

    print(ans)


main()

Solution (Python):
n, *s = open(0).read().split()
n = int(n)
slist = []
for i  in range(5):
  slist.append([])
for ss in s:
  if ss[0] == "M":
    slist[0].append(ss)
  elif ss[0] == "A": 
    slist[1].append(ss)
  elif ss[0] == "R": 
    slist[2].append(ss)
  elif ss[0] == "C": 
    slist[3].append(ss)
  elif ss[0] == "H": 
    slist[4].append(ss)
  else:
    continue

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

Solution (Python):
def input():
    import sys
    return sys.stdin.readline().rstrip()


def main():
    import math
    import collections
    import itertools
    import functools
    
    n = int(input())
    ss = [input() for _ in range(n)]
    target_chars = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
    
    for name in ss:
        if name[0] in target_chars.keys():
            target_chars[name[0]] += 1
    
    ans = 0
    for comb in itertools.combinations(target_chars, 3):
        ans += functools.reduce(lambda x, y: x * target_chars[y], comb, 1)

    print(ans)
            

if __name__ == '__main__':
    main()

Solution (Python):
import itertools

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

    for x,y,z in itertools.combinations(name,3):
        ans += x*y*z
    print(ans)


if __name__ == "__main__":
    test()

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

Solution (Python):
n = int(input())
s = [ input() for _ in range(n)]
march = [ 0 for _ in range(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] + ans
print(ans)

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

Solution (Python):
from collections import Counter
import itertools

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

c = Counter(S)
print(sum(c[x]*c[y]*c[z]  for x, y, z in itertools.combinations('MARCH', 3)))

Solution (Python):
import itertools

N = int(input())
count = [0,0,0,0,0]
total = 0

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

for v in itertools.combinations(count, 3):
    total += v[0]*v[1]*v[2]
print(total)

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

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

Solution (Python):
n=int(input())
al=list('MARCH')
d=[0]*5
for i in range(n):
    s=list(input())
    if s[0] in al:
        d[al.index(s[0])]+=1
op=['0','1']
for i in range(4):
    tmp=[]
    for j in op:
        tmp.append(j+'0')
        tmp.append(j+'1')
    op=tmp
k=[]
for i in op:
    g=list(i)
    c=0
    for j in g:
        if j=='1':
            c+=1
    if c==3:
        k.append(i)
ans=0
for i in k:
    t=1
    for j in range(5):
        if i[j]=='1':
            t*=d[j]
    ans+=t
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
  elif s[0]=='A':
    a+=1
  elif s[0]=='R':
    r+=1
  elif s[0]=='C':
    c+=1
  elif s[0]=='H':
    h+=1
print(m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h)

Solution (Python):
n=int(input())
sl=[input() for _ in range(n)]
t=[0]*5
a=[0,0,0,0,0,0,1,1,1,2]
b=[1,1,1,2,2,3,2,2,3,3]
c=[2,3,4,3,4,4,3,4,4,4]
for s in sl:
    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(10):
    ans+=t[a[i]]*t[b[i]]*t[c[i]]
print(ans)

Solution (Python):


N=int(input())
l=[0]*5

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

print(count)

Solution (Python):
import itertools

N = int(input())




n_initial_MARCH = [0]*5
match_initial = ["M", "A", "R", "C", "H"]
for _ in range(N):
    s = input()
    for idx in range(5):
        if s[0] == match_initial[idx]:
            n_initial_MARCH[idx] += 1

taken_indices = list(itertools.combinations([idx for idx in range(5) if n_initial_MARCH[idx] > 0], 3))

ans = 0

for groups in taken_indices:
    ans += n_initial_MARCH[groups[0]] * n_initial_MARCH[groups[1]] * n_initial_MARCH[groups[2]]

print(ans)

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

Solution (Python):
n=int(input())
l=[0]*5
m='MARCH'
for i in range(n):
  s=input()
  f=s[0]
  for i in range(5):
    if f==m[i]:
      l[i]+=1
      break
x=0
for i in range(3):
  for j in range(i+1,4):
    for k in range(j+1,5):
      x+=l[i]*l[j]*l[k]
print(x)

Solution (Python):
n=int(input())
l=[0]*5
m='MARCH'
for i in range(n):
  s=input()
  f=s[0]
  for i in range(5):
    if f==m[i]:
      l[i]+=1
      break
a=[]
for i in l:
  if i!=0:
    a.append(i)
if len(a)<3:
  print(0)
elif len(a)==3:
  print(a[0]*a[1]*a[2])
elif len(a)==4:
  print(a[0]*a[1]*(a[2]+a[3])+a[2]*a[3]*(a[0]+a[1]))
else:
  x=0
  for i in range(3):
    for j in range(i+1,4):
      for k in range(j+1,5):
        x+=a[i]*a[j]*a[k]
  print(x)

Solution (Python):
from itertools import combinations


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

trios = combinations(['M','A','R','C','H'],3)
ans = 0
for trio in trios:
    ans += march[trio[0]]*march[trio[1]]*march[trio[2]]

print(ans)

Solution (Python):
M = []
A = []
R = []
C = []
H = []
ans = 0
n = int(input())
for _ in range(n):
    tmp = input()
    if tmp[0] == "M":
        M.append(tmp)
    elif tmp[0] == "A":
        A.append(tmp)
    elif tmp[0] == "R":
        R.append(tmp)
    elif tmp[0] == "C":
        C.append(tmp)
    elif tmp[0] == "H":
        H.append(tmp)
if len(M) == 0 and len(A) == 0 and len(R) == 0 and len(C) == 0 and len(H) == 0:
    print(ans)
else:
    lenM = len(M)
    lenA = len(A)
    lenR = len(R)
    lenC = len(C)
    lenH = len(H)

    ans += lenM * lenA * lenR
    ans += lenM * lenA * lenC
    ans += lenM * lenA * lenH
    ans += lenM * lenR * lenC
    ans += lenM * lenR * lenH
    ans += lenM * lenC * lenH
    ans += lenA * lenR * lenC
    ans += lenA * lenR * lenH
    ans += lenA * lenC * lenH    
    ans += lenR * lenC * lenH

    print(ans)

Solution (Python):
from collections import Counter
import itertools
n = int(input())
ary = []
for i in range(n):
    x = input()[0]
    if x == "M" or x =="A" or x =="R" or x =="C" or x == "H":
        ary.append(x)
c = Counter(ary)
cmb = itertools.combinations(c.keys(),3)
ans = 0
for s in cmb:
    ans += c[s[0]]*c[s[1]]*c[s[2]]
print(ans)

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

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

Solution (Python):
import itertools
N = int(input())
Data = [0]*5
for _ in range(N):
    s = input()
    c = s[0]
    if c == 'M':
        Data[0] += 1
    elif c == 'A':
        Data[1] += 1
    elif c == 'R':
        Data[2] += 1
    elif c == 'C':
        Data[3] += 1
    elif c == 'H':
        Data[4] += 1
ans = 0
for data in itertools.combinations(Data,3):
    ans += data[0]*data[1]*data[2]
print(ans)

Solution (Python):
import itertools

N = int(input())
S = []
cnt_dict = {'M': 0, 'A': 0, 'R': 0, 'C': 0,'H': 0}

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

cnt_list = list(cnt_dict.values())
cnt = 0
for c in itertools.combinations(range(5), 3):
    cnt += cnt_list[c[0]]*cnt_list[c[1]]*cnt_list[c[2]]
print(cnt)

Solution (Python):
import itertools
N = int(input())
C = {"M":0,"A":0,"R":0,"C":0,"H":0}
for _ in range(N):
    s = input().strip()
    x = s[0]
    if x in C:
        C[x] += 1
D = list(C.values())
cnt = 0
for y in itertools.combinations(range(5),3):
    cnt += D[y[0]]*D[y[1]]*D[y[2]]
print(cnt)

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

Solution (Python):
from itertools import combinations
n,*s=map(str,open(0).read().split())
a=[0]*5
for i in s:
    if i[0] in "MARCH":
        a["MARCH".index(i[0])]+=1
print(sum([a[x]*a[y]*a[z] for x,y,z in combinations(range(5),3)]))

Solution (Python):
n,*s=map(str,open(0).read().split())
a=[0]*5
ans=0
for i in s:
    if i[0] in "MARCH":
        a["MARCH".index(i[0])]+=1
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())
s = [input() for i in range(n)]
m,a,r,c,h = 0,0,0,0,0

for name in s:
    if name[0] == "M":
        m += 1
    if name[0] == "A":
        a += 1
    if name[0] == "R":
        r += 1
    if name[0] == "C":
        c += 1
    if name[0] == "H":
        h += 1
        
print(m*a*r
    +m*a*c
    +m*a*h
    +m*r*c
    +m*r*h
    +m*c*h
    +a*r*c
    +a*r*h
    +a*c*h
    +r*c*h
    )

Solution (Python):
n = int(input())
d = {"M":0, "A":0, "R":0, "C":0, "H":0}
for i in range(n):
    s = input()
    letter = s[0]
    if letter in d:
        d[letter] += 1
ans = 0
l = ["M", "A", "R", "C", "H"]
t1 = 0
t2 = 0
t3 = 0
for i in range(0, 3):
    if d[l[i]] != 0:
        t1 = d[l[i]]
        for j in range(i+1, 4):
            if d[l[j]] != 0:
                t2 = d[l[j]]
                for k in range(j+1, 5):
                    if d[l[k]] != 0:
                        t3 = d[l[k]]
                        ans += t1 * t2 * t3
print(ans)

Solution (Python):
n = int(input())
d = {"M":0, "A":0, "R":0, "C":0, "H":0}
for i in range(n):
    s = input()
    letter = s[0]
    if letter in d:
        d[letter] += 1
ans = 0
if d["M"] != 0 and d["A"] != 0 and d["R"] != 0:
    ans += d["M"] * d["A"] * d["R"]
if d["M"] != 0 and d["A"] != 0 and d["C"] != 0:
    ans += d["M"] * d["A"] * d["C"]
if d["M"] != 0 and d["A"] != 0 and d["H"] != 0:
    ans += d["M"] * d["A"] * d["H"]
if d["M"] != 0 and d["R"] != 0 and d["C"] != 0:
    ans += d["M"] * d["R"] * d["C"]
if d["M"] != 0 and d["R"] != 0 and d["H"] != 0:
    ans += d["M"] * d["R"] * d["H"]
if d["M"] != 0 and d["C"] != 0 and d["H"] != 0:
    ans += d["M"] * d["C"] * d["H"]
if d["A"] != 0 and d["R"] != 0 and d["C"] != 0:
    ans += d["A"] * d["R"] * d["C"]
if d["A"] != 0 and d["R"] != 0 and d["H"] != 0:
    ans += d["A"] * d["R"] * d["H"]
if d["A"] != 0 and d["C"] != 0 and d["H"] != 0:
    ans += d["A"] * d["C"] * d["H"]
if d["R"] != 0 and d["C"] != 0 and d["H"] != 0:
    ans += d["R"] * d["C"] * d["H"]
print(ans)

Solution (Python):
from itertools import combinations
from collections import defaultdict
n = int(input())
d = defaultdict(int)
for i in range(n):
    tmp = input()
    if tmp.startswith("M"):
        d["m"] += 1
    elif tmp.startswith("A"):
        d["a"] += 1
    elif tmp.startswith("R"):
        d["r"] += 1
    elif tmp.startswith("C"):
        d["c"] += 1
    elif tmp.startswith("H"):
        d["h"] += 1

if len(d) < 3:
    print(0)
else:
    res = 0
    for a, b, c in combinations(d.keys(), 3):
        res += d[a] * d[b] * d[c]
    print(res)

Solution (Python):
n=int(input())
name={}
name["M"]=0
name["A"]=0
name["R"]=0
name["C"]=0
name["H"]=0
for _ in range(n):
    s=list(input())
    if s[0] not in name:
        name[s[0]]=1
    else:
        name[s[0]]+=1
cnt=[name["M"],name["A"],name["R"],name["C"],name["H"]]
ans=0
n=5
for i in range(n-2):
    for j in range(n-i-2):
        j+=i+1
        for k in range(n-j-1):
            k+=j+1
            ans+=cnt[i]*cnt[j]*cnt[k]
print(ans)

Solution (Python):
from collections import Counter
import itertools
n = int(input())
ary = []
for i in range(n):
    s = input()[0]
    if s == "M" or s == "A" or s =="R" or s =="C" or s == "H":
        ary.append(s)
count = Counter(ary)
s = set(count.keys())
cnb = list(itertools.combinations(s,3))
ans = 0
for a,b,c in cnb:
    ans += count[a] * count[b] * count[c]
print(ans)

Solution (Python):
from collections import Counter

n = int(input())
s = set([input() for _ in range(n)])
cnt = []
for i in s:
    if i[0] in "MARCH":
        cnt.append(i[0])

if len(cnt) < 3:
    print(0)
    exit()

cnt = list(Counter(cnt).values())
N = len(cnt)
ans = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        for k in range(j + 1, N):
            ans += cnt[i] * cnt[j] * cnt[k]
print(ans)

Solution (Python):
from collections import defaultdict as dd
import sys
N = int(input())
D = dd(int)
D["M"] = 0
D["A"] = 0
D["R"] = 0
D["C"] = 0
D["H"] = 0

for i in range(N):
  s = input()[0]
  if any((s == "M", s == "A", s == "R", s == "C", s == "H")):
    D[s] += 1
ans = 0
tpls = (("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"))

for t in tpls:
    ans += D[t[0]] * D[t[1]] * D[t[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()
  f = s[0]
  if f == 'M':
    m += 1
  elif f == 'A':
    a += 1
  elif f == 'R':
    r += 1
  elif f == 'C':
    c += 1
  elif f == 'H':
    h += 1

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

Solution (Python):
from itertools import combinations

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

chenge = list("MARCH")
d = dict()
for i, c in enumerate(chenge):
    d[c] = i

cnt = [0] * 5

for s in S:
    if s[0] in chenge:
        cnt[d[s[0]]] += 1

ans = 0

for i, j, k in combinations(cnt, 3):
    ans += i * j * k

print(ans)

Solution (Python):
from collections import Counter
from itertools import combinations
N =int(input())
B = []
for i in range(N):
  S = list(input())
  if S[0]=="M" or S[0]=="A" or S[0]=="R" or S[0]=="C" or S[0]=="H":
    B.append(S[0])
B = Counter(B)
l = ["M","A","R","C","H"]
ans = 0
for a,b,c in combinations(l, 3):
  if a in B.keys() and b in B.keys() and c in B.keys():
    ans += B[a]*B[b]*B[c]
print(ans)

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

check=['M','A','R','C','H']
cnt=[0]*5
for i in range(n):
  for j in range(5):
    if S[i][0]==check[j]:
      cnt[j]+=1
      break
ans=0
for i in range(2**5):
  tmp=1
  flag=0
  for j in range(5):
    if i>>j&1:
      tmp*=cnt[j]
      flag+=1
  if flag==3:
    ans+=tmp
print(ans)

Solution (Python):
N=int(input())
cnt_M=0
cnt_A=0
cnt_R=0
cnt_C=0
cnt_H=0
for _ in range(N):
    s=input()[0]
    if s=='M':
        cnt_M+=1
    elif s=='A':
        cnt_A+=1
    elif s=='R':
        cnt_R+=1
    elif s=='C':
        cnt_C+=1
    elif s=='H':
        cnt_H+=1
arr=[cnt_M, cnt_A, cnt_R, cnt_C, cnt_H]
ans=0
for i in range(5):
    for j in range(5):
        for k in range(5):
            if i!=j and j!=k and k!=i:
                ans+=arr[i]*arr[j]*arr[k]

print(ans//6)

Solution (Python):
from itertools import combinations
n = int(input())
dic = {"M":0, "A":0, "R":0, "C":0, "H":0}
march = ["M", "A", "R", "C", "H"]
for i in range(n):
  kashira = input()[0]
  if kashira in march:
    dic[kashira] += 1

ans = 0
for items in combinations(march, 3):
  ans += dic[items[0]] * dic[items[1]] * dic[items[2]]
print(ans)

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

Solution (Python):
import itertools

N = int(input())

M = [0, 0, 0, 0, 0]

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

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

print(ans)

Solution (Python):
import sys
from functools import reduce
import copy
import math
from pprint import pprint


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    persons = inputs
    N = 5
    kinds = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0, }
    for n in persons:
        if n[0] in kinds:
            kinds[n[0]] += 1
    kinds_list = list(kinds.keys())

    if len(persons) < 3:
        return 0

    pattern = 0
    for i in range(N-2):
        for j in range(i+1, N-1):
            for k in range(j+1, N):
                p1 = kinds_list[i]
                p2 = kinds_list[j]
                p3 = kinds_list[k]
                pattern += kinds[p1] * kinds[p2] * kinds[p3]
    return pattern


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    N = int(input())
    ret = solve(inputs(N))
    print(ret)

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

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

for x in s:
    if x[0] in 'MARCH':
        d[x[0]] += 1

res = 0
march = 'MARCH'
for i in range(3):
    for j in range(i+1, 4):
        for k in range(j+1, 5):
            res += d[march[i]] * d[march[j]] * d[march[k]]

print(res)

Solution (Python):
n = int(input())
li = set(list("MARCH"))

name_li = set()
name = dict()

for i in range(n):
    s = input()
    if s[0] in li:
        name.setdefault(s[0], 0)
        name[s[0]] += 1
        name_li.add(s[0])

import itertools
c_list = list(itertools.combinations(name_li, 3))

ans = 0

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

Solution (Python):

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

x = [0,0,0,0,0,0,1,1,1,2]
y = [1,1,1,2,2,3,2,2,3,3]
z = [2,3,4,3,4,4,3,4,4,4]

m = 0
a = 0
r = 0
c = 0
h = 0

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

ans = 0
D = []
D.append(m)
D.append(a)
D.append(r)
D.append(c)
D.append(h)

for d in range(10):
    ans += D[x[d]]*D[y[d]]*D[z[d]]
print(ans)

Solution (Python):
N = int(input())
S = [input() for _ in range(N)]
L = ['M', 'A', 'R', 'C', 'H']
dict_S = {}

for i in range(N):
    moji = S[i][0]
    if moji in L:
        if moji not in dict_S:
            dict_S[moji] = 1
        else:
            dict_S[moji] += 1

keys = len(dict_S.keys())
values = list(dict_S.values())

if keys < 3 or keys == None:
    print(0)
else:
    x = 0
    for i in range(keys):
        for j in range(i+1, keys):
            for k in range(j+1, keys):
                x += values[i] * values[j] * values[k]
    print(x)