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 collections import Counter
from functools import reduce
from itertools import combinations

import operator

GOOD_LETTERS = "MARCH"
PEOPLE = 3

n = int(input())
c = Counter()

for _ in range(n):
  first = input()[0]
  if first in GOOD_LETTERS:
    c.update(first)

ways = 0
for tup in combinations(GOOD_LETTERS, PEOPLE):
  ways += reduce(operator.mul, [c[ch] for ch in tup], 1)

print(ways)

Solution (Python):
import sys
from statistics import *
from collections import *
from operator import itemgetter
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
ct = 0
cap = ["M", "A", "R", "C", "H"]
ct = [0] * 5
for i in range(n):
    s = input()
    for i in range(5):
        if s[0] == cap[i]:
            ct[i] += 1
ans = 0
for a in range(5):
    for b in range(a+1, 5):
        for c in range(b+1, 5):
            ans += ct[a] * ct[b] * ct[c]
print(ans)

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

Solution (Python):
import collections
import itertools
ok = ['M', 'A', 'R', 'C', 'H']
n = int(input())
d = collections.defaultdict(int)
for _ in range(n):
    s = input()
    if any([s[0] == x for x in ok]): d[s[0]] += 1
p = [a for a in itertools.combinations(ok, 3) if all([x in d for x in a])]
ans = 0
for a, b, c in p:
    ans += d[a] * d[b] * d[c]
print(ans)

Solution (Python):
N = int(input())
nM = 0
nA = 0
nR = 0
nC = 0
nH = 0
for i in range(N):
  S = input()
  if S[0] == "M": nM += 1
  if S[0] == "A": nA += 1
  if S[0] == "R": nR += 1
  if S[0] == "C": nC += 1
  if S[0] == "H": nH += 1
r = 0
r += nM*nA*nR
r += nM*nA*nC
r += nM*nA*nH
r += nM*nR*nC
r += nM*nR*nH
r += nM*nC*nH
r += nA*nR*nC
r += nA*nR*nH
r += nA*nC*nH
r += nR*nC*nH
print(r)

Solution (Python):
n = int(input())
groups = [0] * 5
for _ in range(n):
    s = input()
    if s[0] == "M":
        groups[0] += 1
    elif s[0] == "A":
        groups[1] += 1
    elif s[0] == "R":
        groups[2] += 1
    elif s[0] == "C":
        groups[3] += 1
    elif s[0] == "H":
        groups[4] += 1
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 += groups[i] * groups[j] * groups[k]
print(ans//6)

Solution (Python):
n = int(input())
s = [input() for i in range(n)]
m = 0
a = 0
r = 0
c = 0
h = 0
for j in range(n):
    if s[j][0] == "M":
        m += 1
    elif s[j][0] == "A":
        a += 1
    elif s[j][0] == "R":
        r += 1
    elif s[j][0] == "C":
        c += 1
    elif s[j][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}
ans = 0
for i in range(n):
    s = input()
    if s[0] in d:
        d[s[0]] += 1
va = list(d.values())
v = len(va)

for i in range(v):
    for j in range(i+1,v):
        for k in range(j+1,v):
            ans += va[i]*va[j]*va[k]
print(ans)

Solution (Python):
n = int(input())
d = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
va = []
ans = 0
for i in range(n):
    s = input()
    if s[0] in d:
        d[s[0]] += 1
for i in d:
    if d[i] > 0:
        va.append(d[i])
v = len(va)

if v < 3:
    print(0)
else:
    for i in range(v-2):
        for j in range(i+1,v-1):
            for k in range(j+1,v):
                ans += va[i]*va[j]*va[k]
    print(ans)

Solution (Python):
N = int(input())
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

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 Counter
from itertools import combinations

counter = Counter()

n = int(input())
for _ in range(n):
    line = input()
    if line[0] in "MARCH":
        counter[line[0]] += 1

ans = 0
for a, b, c in combinations("MARCH", 3):
    c = counter[a] * counter[b] * counter[c]
    ans += c

print(ans)

Solution (Python):
import itertools
import collections

n = int(input().split()[0])
s_list = []

for _ in range(n):
    s = input().split()[0]
    s_list.append(s)

target_list = [s[0] for s in s_list if s[0] in list('MARCH')]
counter = collections.Counter(target_list)
c = 0

if len(set(target_list)) < 3:
    ans = 0
else:
    p_list = itertools.combinations(set(target_list), 3)

    for p in p_list:
        c += counter[p[0]] * counter[p[1]] * counter[p[2]]
    ans = c
print(c)

Solution (Python):
from collections import Counter

N = int(input())

counter = Counter()
for _ in range(N):
    s = input()[0]
    if s in ('MARCH'):
        counter[s] += 1
if len(counter) < 3:
    print(0)
    exit()

import itertools

ans = 0
for a, b, c in itertools.combinations(counter.keys(), 3):
    ans += counter[a] * counter[b] * counter[c]
print(ans)

Solution (Python):
from collections import defaultdict
import itertools


def resolve():
    n = int(input())
    d = defaultdict(int)
    for _ in range(n):
        d[input()[0]] += 1
    print(sum([d[c1] * d[c2] * d[c3] for c1, c2, c3 in itertools.combinations(["M", "A", "R", "C", "H"], 3)]))


if __name__ == "__main__":
    resolve()

Solution (Python):
from collections import defaultdict
import itertools


def resolve():
    n = int(input())
    d = defaultdict(int)
    for _ in range(n):
        s = input()
        d[s[0]] += 1
    print(sum([d[c1] * d[c2] * d[c3] for c1, c2, c3 in itertools.combinations(["M", "A", "R", "C", "H"], 3)]))


if __name__ == "__main__":
    resolve()

Solution (Python):
from collections import defaultdict
import itertools


def resolve():
    n = int(input())
    d = defaultdict(list)
    for _ in range(n):
        s = input()
        d[s[0]].append(s)
    print(sum([len(d[c1]) * len(d[c2]) * len(d[c3]) for c1, c2, c3 in itertools.combinations(["M", "A", "R", "C", "H"], 3)]))


if __name__ == "__main__":
    resolve()

Solution (Python):
import itertools

first = {"M":0, "A":0, "R":0, "C":0, "H":0}
n = int(input())
s = [input() for i in range(n)]
for j in s:
    if j[0] in first:
        first[j[0]] += 1
    else:
        first[j[0]] = 1
ll = [[1,1,1,0,0],[1,1,0,1,0],[1,1,0,0,1],[1,0,1,1,0],[1,0,1,0,1],[1,0,0,1,1],[0,1,1,1,0],\
    [0,1,0,1,1],[0,1,1,0,1],[0,0,1,1,1]]

ans =0
for k in range(10):
    num = []
    if ll[k][0] == 1:
        num.append(first["M"])
    if ll[k][1] == 1:
        num.append(first["A"])
    if ll[k][2] == 1:
        num.append(first["R"])
    if ll[k][3] == 1:
        num.append(first["C"])
    if ll[k][4] == 1:
        num.append(first["H"])
    st = 1
    for m in num:
        st *= m
    ans += st
print(ans)

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

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

m = [name for name in s if name[0] == "M"]
a = [name for name in s if name[0] == "A"]
r = [name for name in s if name[0] == "R"]
c = [name for name in s if name[0] == "C"]
h = [name for name in s if name[0] == "H"]

march = [len(m),len(a),len(r),len(c),len(h)]
march = [i for i in march if i!= 0]

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

result = 0
for i in range(len(march)):
  for j in range(len(march)):
    for k in range(len(march)):
      if i != j and j != k and k != i:
        result += march[i]*march[j]*march[k]

print(int(result/6))

Solution (Python):
n = int(input())
s = [0,0,0,0,0]
for i in range(n):
  si = input()[0]
  if si in ["M","A","R","C","H"]:
    s[["M","A","R","C","H"].index(si)] += 1
m = s[0]*s[1]*s[2]+s[0]*s[1]*s[3]+s[0]*s[1]*s[4]+s[0]*s[2]*s[3]+s[0]*s[2]*s[4]+s[0]*s[3]*s[4]+s[1]*s[2]*s[3]+s[1]*s[2]*s[4]+s[1]*s[3]*s[4]+s[2]*s[3]*s[4]
print(m)

Solution (Python):
import itertools

N = int(input())
d = {}

for i in range(N):
    tmp = list(input())
    k = tmp[0]
    if k in 'MARCH':
        if k in d:
            d[k] += 1
        else:
            d[k] = 1

l = len(d)
ans = 0
key = d.keys()

if l >= 3:
    for a in itertools.combinations(key,3):
        ans += d[a[0]] * d[a[1]] * d[a[2]]

print(ans)

Solution (Python):
import itertools

n = int(input())
count_m = 0
count_a = 0
count_r = 0
count_c = 0
count_h = 0
sum = 0


for i in range(n):
    a = input()
    if a[0] == 'A':
        count_a += 1
    elif a[0] == 'C':
        count_c += 1
    elif a[0] == 'H':
        count_h += 1
    elif a[0] == 'M':
        count_m += 1
    elif a[0] == 'R':
        count_r += 1

l = [count_m, count_a, count_r, count_c, count_h]
c = itertools.combinations(l, 3)

for f, j, k in c:
    sum += f*j*k

print(sum)

Solution (Python):
def main():
    N = int(input())
    names = []
    for _ in range(N):
        names.append(input())
    d = dict()
    for s in names:
        if s[0] in "MARCH":
            d[s[0]] = d.get(s[0], 0) + 1
    ans = 0
    for c0 in d:
        for c1 in d:
            for c2 in d:
                if c0 < c1 < c2:
                    ans += d[c0]*d[c1]*d[c2]
    return ans

if __name__ == '__main__':
    print(main())

Solution (Python):
N=int(input())
l=[0]*5
for i 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
from itertools import combinations
t=list(combinations(range(5),3))
a=0
for i in range(10):
    a+=l[t[i][0]]*l[t[i][1]]*l[t[i][2]]
print(a)

Solution (Python):
import itertools

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


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

res = 0
for l in itertools.permutations(L,3):
    c = 1
    for x in l:
        c *= x
    res += c
print(res//6)

Solution (Python):
import collections, itertools
n = int(input())
s = collections.Counter([input()[0] for _ in range(n)])
ls = list("MARCH")
t = 0
for i in itertools.combinations(ls, 3):
    t += s[i[0]] * s[i[1]] * s[i[2]]
print(t)

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

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(5):
    for j in range(5):
        for k in range(5):
            if i >= j or i >= k or j >= k:
                continue
            ans += march[i] * march[j] * march[k]
            
print(ans)

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

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

Solution (Python):
from itertools import combinations
from collections import defaultdict
n=int(input())
S=tuple(input().strip() for _ in range(n))
d=defaultdict(int)
A=('M','A','R','C','H')
for i in range(n):
    tmp=S[i][0]
    if tmp in A:
        d[tmp]+=1
B=[]
for a in A:
    if d[a]:
        B.append(a)
if len(B)<3:
    print(0)
else:
    ans=0
    for i in combinations(B,3):
        tmp=1
        for j in range(3):
            tmp*=d[i[j]]
        ans+=tmp
    print(ans)

Solution (Python):
N = int(input())
li = [["M",0],["A",0],["R",0],["C",0],["H",0]]
ans = 0
for i in range(N):
    tmp = str(input())
    if tmp[0]=="M" or tmp[0]=="A" or tmp[0]=="R" or tmp[0]=="C" or tmp[0]=="H":
        for j in range(5):
            if tmp[0]==li[j][0]:
                li[j][1] += 1
                break

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

Solution (Python):
n = int(input())
s = [input() for _ in range(n)]
STR = "MARCH"
cnt = {c:0 for c in STR}
for ss in s:
  if ss[0] in STR:
    cnt[ss[0]] += 1
    
ans = 0
for i1 in range(5):
  for i2 in range(i1+1, 5):
    for i3 in range(i2+1, 5):
      ans += cnt[STR[i1]]*cnt[STR[i2]]*cnt[STR[i3]]

print(ans)

Solution (Python):
N = int(input())
C = [0] * 5
prefix = 'MARCH'

for i in range(N):
    s = input().rstrip()[0]
    if s in prefix:
        C[prefix.find(s)] += 1

ans = 0

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

print(ans)

Solution (Python):
from collections import Counter
n=int(input())
name=[]
initial={"M":0,
         "A":0,
         "R":0,
         "C":0,
         "H":0}
for _ in range(n):
    s=input()
    if s[0] in ["M","A","R","C","H"]:
        initial[s[0]]+=1
num=[v for k,v in initial.items()]

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

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



count = 0
candidate = ["M", "A", "R", "C", "H"]

M = len(sorted([name for name in names if name[0] == candidate[0]]))
A = len(sorted([name for name in names if name[0] == candidate[1]]))
R = len(sorted([name for name in names if name[0] == candidate[2]]))
C = len(sorted([name for name in names if name[0] == candidate[3]]))
H = len(sorted([name for name in names if name[0] == candidate[4]]))

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())
A=[0]*5
count=0
for i in range(N):
    S=input()
    if S[0]=='M':
        A[0]+=1
    if S[0]=='A':
        A[1]+=1
    if S[0]=='R':
        A[2]+=1
    if S[0]=='C':
        A[3]+=1
    if S[0]=='H':
        A[4]+=1

for i in range(5):
    for j in range(i):
        for k in range(j):
            if i!=j and j!=k and k!=i:
                count+=A[i]*A[j]*A[k]
print(count)

Solution (Python):
import itertools
N = int(input())
s = "MARCH"
dct = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for i in range(N):
  begin = input()[0] 
  if begin in dct.keys():
    dct[begin] += 1
cmb = itertools.combinations(list(dct.keys()), 3)
ans = 0
for i in list(cmb):
  n = 1
  for j in i:
    n *= dct[j]
  ans += n
print(ans)

Solution (Python):
n = int(input())
march = {'m': 0, 'a': 0, 'r': 0, 'c': 0, 'h': 0}
for i in range(n):
  s = input()[0].lower()
  try:
    march[s] += 1
  except:
    pass
ans = 0

for key1 in march.keys():
  for key2 in march.keys():
    if key1 != key2:
      for key3 in march.keys():
        if key3 != key1 and key3 != key2:
          ans += march[key1] * march[key2] * march[key3]
print(ans//6)

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

h = {}
for c in "MARCH":
    h[c] = 0

for i in range(int(input())):
    c = input().strip()[0]
    if c in h:
        h[c] += 1

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

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

n = int(input())
a = [0]*5
for i in range(n):
    s = input().strip()
    c = s[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(0, len(a)-2):
    for j in range(i+1, len(a)):
        for k in range(j+1, len(a)):

            ans += a[i]*a[j]*a[k]
print(ans)

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



initial_dict = defaultdict(int)
n = int(input())
for i in range(n):
    initial = input()[0]
    if initial in 'MARCH':
        initial_dict[initial] += 1



ret = 0
for i, j, k in comb('MARCH', 3):
    ret += initial_dict[i] * initial_dict[j] * initial_dict[k]


print(ret)

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


N = int(input())
d = defaultdict(int)
for _ in range(N):
    S = input()
    if S[0] in 'MARCH':
        d[S[0]] += 1

ans = 0
for a, b, c in combinations('MARCH', 3):
    ans += d[a] * d[b] * d[c]
print(ans)

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

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

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

ans = 0
count = list(count.items())
for i in range(len(count)):
    for j in range(i + 1, len(count)):
        for k in range(j + 1, len(count)):
            ans += count[i][1] * count[j][1] * count[k][1]

print(ans)

Solution (Python):
n = int(input())
dic = {"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"]:
        dic[s[0]]+=1
l = [dic["M"],dic["A"],dic["R"],dic["C"],dic["H"]]
count = 0
for i in range(5):
    for j in range(5):
        for k in range(5):
            if i<j and j<k:
                count += l[i]*l[j]*l[k]
print(count)

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

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

    S = defaultdict(int)

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

    ans = 0

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

    print(ans)
main()

Solution (Python):
from itertools import combinations
box=list(list(input())[0] for i in range(int(input())))
count=[0,0,0,0,0]
for i in box:
    if i=="M":count[0] +=1
    elif i=="A":count[1] +=1
    elif i=="R":count[2] +=1
    elif i=="C":count[3] +=1
    elif i=="H":count[4] +=1
point=0
for i,j,k in combinations(count,3):
    point +=i*j*k
print(point)

Solution (Python):

import collections
import itertools

def getint(): return int(input())
def getints(): return list(map(int, input().split()))

n = getint()
s = [input() for _ in range(n)]
c = collections.Counter()

for h in s:
    c[h[0]] += 1

res = 0
for perm in itertools.combinations("MARCH", 3):
    res += c[perm[0]] * c[perm[1]] * c[perm[2]]

print(res)

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

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

Solution (Python):
time = [0,0,0,0,0]
def suc(time):
  point = 5-1
  while point >= 0:
    if time[point] == 0:
      time[point] = 1
      return time
      break
    else:
      time[point] = 0
      point -= 1
  else:
    return 'over'
n = int(input())
s = [0 for _ in range(5)]
for i in range(n):
  now = input()[0]
  if now == 'M':
    s[0] += 1
  elif now == 'A':
    s[1] += 1
  elif now == 'R':
    s[2] += 1
  elif now == 'C':
    s[3] += 1
  elif now == 'H':
    s[4] += 1
ans = 0
while time != 'over':
  if sum(time) != 3:
    pass
  else:
    tmp = 1
    for j in range(5):
      if time[j] == 1:
        tmp *= s[j]
    ans += tmp
    
  time = suc(time)

print(ans)

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

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

Solution (Python):
import collections
import itertools

N = int(input())
ss = [input() for _ in range(N)]
s = [i[0] for i in ss if i[0] in ["M", "A", "R", "C", "H"]]
c = collections.Counter(s)



l = list(itertools.combinations(c,3))



ans = sum([c[i[0]] * c[i[1]] * c[i[2]] for i in l])

print(ans)

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

N = int(input())

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



nd = defaultdict(int)

for name in S:
    if name[0] in "MARCH":
        nd[name[0]] += 1

if len(nd.keys()) < 3:
    print(0)
    exit()

ans = 0
for trio in combinations(nd.keys(), 3):
    
    
    ans += nd[trio[0]] * nd[trio[1]] * nd[trio[2]]

print(ans)

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

Solution (Python):
from collections import Counter
N = int(input())
P = Counter((x for _ in range(N) for x in input()[0] if x in "MARCH"))
Pidx = list(P.keys())
def mycount(i, ptn, c):
    
    if c <= 0:
        return ptn
    elif len(P) - i < c:
        return 0
    return mycount(i+1, ptn, c) + mycount(i+1, ptn * P[Pidx[i]], c - 1)

print(mycount(0, 1, 3))

Solution (Python):
n = int(input())
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

lst = []
for i in range(2**5):
    s = format(i,'b').rjust(5,'0')
    if s.count('1') == 3:
        lst.append(s)

ans = 0
for l in lst:
    c = 1
    for i in range(5):
        if l[i] == '1':
            c *= name[i]
    ans += c
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

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

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

for i 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
  else:
    continue
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 itertools import combinations
n = int(input())
names = [input()[0] for _ in range(n)]
li = [0]*5
for i,c in enumerate("MARCH"):
	cnt = 0
	for name in names:
		if c == name:
			cnt += 1
	li[i] = cnt
ans = 0
for i,j,k in combinations(li,3):
	ans += i*j*k
print(ans)

Solution (Python):
a = int(input())
b = [input() for i in range(a)]
c = ['a']*a
for i in range(a):
    c[i] = b[i][0]
h = c.count('H')
m = c.count('M')
a = c.count('A')
r = c.count('R')
c1 = c.count('C')
ansm = m*a*h + m*a*c1 + m*a*r + m*r*h + m*r*c1 + m*c1*h
ansa = a*r*h + a*r*c1 + a*c1*h
ansr = r*c1*h
print(ansm+ansa+ansr)

Solution (Python):
N = int(input())
S = [0] * N
m = 0
a = 0
r = 0
c = 0
h = 0

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

ans = 0

l = [m, a, r, c, h]
for i in range(0,3):
    for j in range(i+1,4):
        for k in range(j+1, 5):
            ans += l[i] * l[j] * l[k]

print(ans)

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

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

l = [0]*5
M=A=R=C=H=0
for i in range(S):
	if name[i][0] == "M":
		l[0] += 1
	if name[i][0] == "A":
		l[1] += 1
	if name[i][0] == "R":
		l[2] += 1
	if name[i][0] == "C":
		l[3] += 1
	if name[i][0] == "H":
		l[4] += 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)

Solution (Python):

n = int(input())
li = [input()[0] for _ in range(n)]
count = [0, 0, 0, 0, 0]
name_index = ["M", "A", "R", "C", "H"]
li = [i for i in li if i in name_index ] 
for i in li:
    count[name_index.index(i)]+= 1
ans = 0

for i in range(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):
n=int(input())
s={"M":0,"A":0,"R":0,"C":0,"H":0}
for i in range(n):
    v=input()
    if v[0] in s:
        s[v[0]]+=1
l=list(s.values())
ans=0
for a in range(5):
    for b in range(a+1,5):
        for c in range(b+1,5):
            ans+=l[a]*l[b]*l[c]         
print(ans)

Solution (Python):
import itertools
n=int(input())
s=[input() for i in range(n)]
m=['M','A','R','C','H']
c=[0 for i in range(5)]
ans=0

for i in range(5):
    for j in range(n):
        if s[j][0].count(m[i])==1:
            c[i]+=1



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

Solution (Python):
n=int(input())
s=[input()[0] for _ in [0]*n]
l=['M','A','R','C','H']
L=[s.count(x) for x in l]
a=0
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            a+=L[i]*L[j]*L[k]
print(a)

Solution (Python):
import itertools

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

m = S.count('M')
a = S.count('A')
r = S.count('R')
c = S.count('C')
h = S.count('H')

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

j = 0
p = list(itertools.combinations(ans,3))
for i in p:
    j += i[0]*i[1]*i[2]

print(j)

Solution (Python):
from itertools import combinations
N = int(input())
m = [0] * 5
for _ in range(N):
    S = input()
    cand = ("M", "A", "R", "C", "H")
    if S[0] in cand:
        m[cand.index(S[0])] += 1
ans = 0
for i, j, k in combinations(range(5), 3):
    ans += m[i] * m[j] * m[k]
print(ans)

Solution (Python):
n = int(input())
s = list(input() for _ in range(n))
m,a,r,c,h = 0,0,0,0,0

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

ans = 0
cnt = 0
if m != 0:
  cnt += 1
if a != 0:
  cnt += 1
if r != 0:
  cnt += 1
if c != 0:
  cnt += 1
if h != 0:
  cnt += 1
if cnt < 3:
  print(0)
else:
  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
N = int(input())
S = [input() for _ in range(N)]
lis = []
for i in range(N):
    for j in ['M','A','R','C','H']:
        if S[i][0] == j:
            lis.append(j)

cnt = [lis.count('M'),lis.count('A'),lis.count('R'),lis.count('C'),lis.count('H')]
ans = 0
for a, b, c in itertools.combinations(cnt, 3):
    ans += a*b*c
print(ans)

Solution (Python):

import sys


def solve(N: int, S: "List[str]"):
    m = len([i for i in S if i[0] == 'M'])
    a = len([i for i in S if i[0] == 'A'])
    r = len([i for i in S if i[0] == 'R'])
    c = len([i for i in S if i[0] == 'C'])
    h = len([i for i in S if i[0] == '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
        )

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    S = [ next(tokens) for _ in range(N) ]  
    solve(N, S)

if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
s=[]
for i in range(n):
  s.append(input())
m=0
a=0
r=0
c=0
h=0
for i in range(n):
  if s[i][0]=='M':
    m+=1
  if s[i][0]=='A':
    a+=1
  if s[i][0]=='R':
    r+=1
  if s[i][0]=='C':
    c+=1
  if s[i][0]=='H':
    h+=1
li=[m,a,r,c,h]
li.sort(reverse=True)
if li[2]==0:
  print(0)
else:
  ans=m*a*(r+c+h)+m*r*(c+h)+m*c*h+a*r*(c+h)+a*c*h+r*c*h
  print(ans)

Solution (Python):
N = int(input())
char_lst = ['M', 'A', 'R', 'C', 'H']
counts = {'M' : 0, 'A': 0, 'R':0, 'C': 0, 'H': 0}
for i in range(N):
    S = input()
    if S[0] in char_lst:
        counts[S[0]] += 1
            
ans = 0
for i in range(len(char_lst) - 2):
    for j in range(i + 1, len(char_lst) - 1):
        for k in range(j + 1, len(char_lst)):
            ans += counts[char_lst[i]] * counts[char_lst[j]] * counts[char_lst[k]]
            
print(ans)

Solution (Python):
N = int(input())
S = []
for i in range(N):
    t = input()
    if t[0] == "M" or t[0] == "A" or t[0] == "R" or t[0] == "C" or t[0] == "H":
        S.append(t[0])
l = len(S)
S_set = set(S)
count_list = []
for i in S_set:
    count_list.append(S.count(i))
if len(S_set) == 3:
    ans = count_list[0] * count_list[1] * count_list[2]
elif len(S_set) == 4:
    ans = count_list[0] * count_list[1] * count_list[2] + count_list[0] * count_list[1] * count_list[3] + count_list[0] * count_list[2] * count_list[3] + count_list[1] * count_list[2] * count_list[3]
elif len(S_set) == 5:
    tmp0 = count_list[0] * count_list[1] * count_list[2] + count_list[0] * count_list[1] * count_list[3] + count_list[0] * count_list[1] * count_list[4]
    tmp1 = count_list[0] * count_list[2] * count_list[3] + count_list[0] * count_list[2] * count_list[4] + count_list[0] * count_list[3] * count_list[4]
    tmp2 = count_list[1] * count_list[2] * count_list[3] + count_list[1] * count_list[2] * count_list[4] + count_list[1] * count_list[3] * count_list[4]
    tmp3 = count_list[2] * count_list[3] * count_list[4]
    ans = tmp0 + tmp1 + tmp2 + tmp3
else:
    ans = 0
print(ans)

Solution (Python):
import itertools
N = int(input())
nm = []
for i in range(N):
    S = input()
    nm.append(S[0])
tm = [nm.count(i) for i in str('MARCH')]
f = [(n == 0) for n in tm]
ans = 0
for i,j,k in itertools.combinations(range(5), 3):
    ans += tm[i]*tm[j]*tm[k] 
print(ans)