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

Solution (Python):
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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

S_head = []
for s in S:
    if s[0] in ['M', 'A', 'R', 'C', 'H']:
        S_head.append(s[0])

S_head_c = Counter(S_head)
ans = 0
for i in list(combinations(['M', 'A', 'R', 'C', 'H'], 3)):
    tmp = 1
    for j in i:
        tmp *= S_head_c[j]
    ans += tmp

print(ans)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = [input() for i in range(N)]
dic = defaultdict(list)

for s in S:
    dic[s[0]].append(s)

L = list(combinations(list("MARCH"), 3))


cnt = 0
for l in L:
    
    cnt += len(dic[l[0]]) * len(dic[l[1]]) * len(dic[l[2]])
print(cnt)

Solution (Python):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()

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

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

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

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

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

Solution (Python):
from sys import stdin
def input():
    return stdin.readline().strip()
 
n = int(input())
m, a, r, c, h = 0, 0, 0, 0, 0
for _ in range(n):
    i = input()
    i = i[0]
    if i == 'M':
        m += 1
    elif i == 'A':
        a += 1
    elif i == 'R':
        r += 1
    elif i == 'C':
        c += 1
    elif i == 'H':
        h += 1
 
ans = 0
from itertools import combinations
for i in combinations([m, a, r, c, h], 3):
    i, j, k = i
    ans += i * j * k
print(ans)

Solution (Python):
N=int(input())
lst=[]
s1=0
s2=0
s3=0
s4=0
s5=0
for i in range(N):
    s=input()
    if s[0]=="M":
        s1+=1
    elif s[0]=='A':
        s2+=1
    elif s[0]=="R":
        s3+=1
    elif s[0]=="C":
        s4+=1
    elif s[0]=="H":
        s5+=1
ans=0
ans+=s1*s2*s3
ans+=s1*s2*s4
ans+=s1*s2*s5
ans+=s1*s4*s5
ans+=s1*s3*s5
ans+=s1*s3*s4
ans+=s2*s3*s4
ans+=s2*s3*s5
ans+=s3*s4*s5
ans+=s2*s4*s5
print(ans)

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

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

l=[0]*5

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

ans=0
for i in range(5):
    for j in range(5):
        for k in range(5):
            if i!=j and j!=k and k!=i:
                ans+=l[i]*l[j]*l[k]
ans//=6
print(ans)

Solution (Python):
from itertools import combinations

n = int(input())
c = {
    "M": 0,
    "A": 0,
    "R": 0,
    "C": 0,
    "H": 0
}
ck = list(c.keys())
cnt = 0

for i in range(n):
    s = input()
    if s[0] in c.keys():
        c[s[0]] += 1
        cnt += 1

if cnt >= 3:
    ans = 0
    for p in list(combinations("MARCH", 3)):
        ans += c[p[0]] * c[p[1]] * c[p[2]]
    print(ans)
else:
    print(0)

Solution (Python):
N = int(input())
march_dict = {
    'M': 0,
    'A': 0,
    'R': 0,
    'C': 0,
    'H': 0
}
for i in range(N):
    S = input()
    s_head = S[0]
    if march_dict.get(s_head) is not None:
        march_dict[s_head] += 1


import itertools

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

Solution (Python):
N = int(input())
march_dict = {
    'M': 0,
    'A': 0,
    'R': 0,
    'C': 0,
    'H': 0
}
for i in range(N):
    S = input()
    s_head = S[0]
    if march_dict.get(s_head) is not None:
        march_dict[s_head] += 1

march_candidate = [key for key, val in march_dict.items() if val != 0]

import itertools

ans = 0
for C in itertools.combinations(march_candidate, 3):
    a = march_dict[C[0]]
    b = march_dict[C[1]]
    c = march_dict[C[2]]
    ans += a * b * c
    
    
print(ans)

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

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

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):
from sys import stdin
def input():
    return stdin.readline().strip()

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

ans = 0
from itertools import combinations
for i in combinations([m, a, r, c, h], 3):
    i, j, k = i
    ans += i * j * k
print(ans)

Solution (Python):
import itertools
N = int(input())
M_Dict = {"M":0,"A":0,"R":0,"C":0,"H":0}
for i in range(N):
    moji = str(input())
    if moji[0] in M_Dict.keys():
        M_Dict[moji[0]] += 1
M_Dict = {k: v for k, v in M_Dict.items() if v != 0}    
if len(M_Dict) < 3:
    ans = 0
else:
    ans = 0
    for k in itertools.combinations(list(M_Dict.keys()),3):
        ans += int(M_Dict[k[0]]) * int(M_Dict[k[1]]) * int(M_Dict[k[2]])
    
print(ans)

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    S = [SS() for _ in range(N)]

    cnt = collections.Counter([i[0] for i in S])
    
    ans = 0
    for i, j, k in itertools.combinations(('M', 'A', 'R', 'C', 'H'), 3):
        ans += cnt[i] * cnt[j] * cnt[k]

    print(ans)

if __name__ == '__main__':
    resolve()

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())
num = {s: 0 for s in list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")}
for i in range(N):
    s = input()
    num[s[0]] += 1

patterns = [
    "MAR",
    "MAC",
    "MAH",
    "MRC",
    "MRH",
    "MCH",

    "ARC",
    "ARH",
    "ACH",

    "RCH"
]
ans = 0
for pat in patterns:
    ans += num[pat[0]]*num[pat[1]]*num[pat[2]]
print(ans)

Solution (Python):
import sys
from itertools import combinations

input = sys.stdin.readline
d = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for i in range(int(input())):
    a = input()
    if a[0] in "MARCH":
        d[a[0]] += 1

l = [i for i in d.values() if i != 0]
print(sum(i * j * k for i, j, k in combinations(l, 3)))

Solution (Python):
import itertools
n=int(input())
name=dict()
for c in "MARCH":
    name[c]=0
for i in range(n):
    t=input()
    if t[0] in "MARCH":
        name[t[0]]+=1

ans=0
for hey in itertools.combinations("MARCH",3):
    ans+=name[hey[0]]*name[hey[1]]*name[hey[2]]
print(ans)

Solution (Python):
M,A,R,C,H=list(),list(),list(),list(),list()
N=int(input())
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)
a=len(M)
b=len(A)
c=len(R)
d=len(C)
e=len(H)
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 sys
from collections import defaultdict

_,*s=sys.stdin.read().split()
intl=defaultdict(int)
for p in s:
  intl[p[0]]+=1

march=list(intl[w] for w in 'MARCH')
ans=0
for i in range(5):
  for j in range(i+1,5):
    for k in range(j+1,5):
      ans+=march[i]*march[j]*march[k]
print(ans)

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

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

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

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

cnt = [0] * 5

for x in s:
    if x[0] == 'M':
        cnt[0] += 1
    if x[0] == 'A':
        cnt[1] += 1
    if x[0] == 'R':
        cnt[2] += 1
    if x[0] == 'C':
        cnt[3] += 1
    if x[0] == 'H':
        cnt[4] += 1

if cnt.count(0) > 2:
    print(0)
    exit()

ans = 0 
for i in range(len(cnt)-2):
    for j in range(i+1, len(cnt)-1):
        for k in range(j+1, len(cnt)):
            ans += cnt[i] * cnt[j] * cnt[k]

print(ans)

Solution (Python):
import itertools
N=int(input())
l=[0]*5
m=list('MARCH')
for i in range(N):
    S=input()
    if S[0] in m:
        l[m.index(S[0])]+=1
ans=0
for i in list(itertools.combinations(l,3)):
    m=1
    for j in i:
        m*=j
    ans+=m
print(ans)

Solution (Python):
n = int(input())
slist = []
for i in range(n):
    s = input()
    slist.append(s[0])
import collections
c = collections.Counter(slist)
l = ["M","A","R","C","H"]
import itertools
citer = list(itertools.combinations(l,3))
ans = 0
for i in citer:
    ans += c[i[0]] * c[i[1]] * c[i[2]]
print(ans)

Solution (Python):
def solve():
    from collections import defaultdict
    from itertools import combinations
    n = int(input())
    d = defaultdict(int)
    for i in range(n):
        s = input()
        d[s[0]] += 1
    ans = 0
    for x, y, z in combinations(["M", "A", "R", "C", "H"], 3):
        ans += d[x] * d[y] * d[z]
    print(ans)
    return


solve()

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

for lst in itertools.combinations([m,a,r,c,h],3):
  cnt=1
  for i in lst:
    cnt*=i
    
  ans+=cnt
  
print(ans)

Solution (Python):
from itertools import combinations

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

indices = [0, 1, 2, 3, 4]
letters = ["M", "A", "R", "C", "H"]
mapping = dict(zip(letters, indices))

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

cnt = 0
for combo in combinations(c, 3):
    cnt += combo[0]*combo[1]*combo[2]

print(cnt)

Solution (Python):
from itertools import combinations

n=int(input())
cnt=[0]*26

for i in range(n):
    s=input()
    cnt[ord(s[0])-ord('A')]+=1

ans=0

for c1,c2,c3 in combinations(["M","A","R","C","H"],3):
    c1=ord(c1)-ord("A")
    c2=ord(c2)-ord("A")
    c3=ord(c3)-ord("A")

    ans+=cnt[c1]*cnt[c2]*cnt[c3]

print(ans)

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

march=[0]*5
string="MARCH"

for i in range(n):
    for j in range(5):
        if s[i][0]==string[j]:
            march[j] +=1

if march.count(0)>=3:
    print(0)
    exit()

while march.count(0):
    march.remove(0)

ans=0
for i_0 in range(len(march)):
    for i_1 in range(i_0+1,len(march)):
        for i_2 in range(i_1+1,len(march)):
            ans = ans + march[i_0]*march[i_1]*march[i_2]
print(ans)

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

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):
from collections import defaultdict
n = int(input())
name_d = dict()
name_d["M"] = 0
name_d["A"] = 0
name_d["R"] = 0
name_d["C"] = 0
name_d["H"] = 0

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

name_patturn = ["MAR", "MRC", "MCH", "MAH", "MAC", "MRH", "ARC", "ARH", "ACH", "RCH"]
ans = 0
for patturn in name_patturn:
    ans += name_d[patturn[0]]*name_d[patturn[1]]*name_d[patturn[2]]

print(ans)

Solution (Python):

import itertools
N = int(input())
Name = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}


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

l = []
for k, v in Name.items():
    l.append(v)

ret = 0

for x in itertools.combinations(l, 3):
    ret += x[0]*x[1]*x[2]

print(ret)

Solution (Python):
from itertools import combinations
n = int(input())
d = {}
for _ in range(n):
  s = input()[0]
  if s in ["M","A","R","C","H"]:
    if s in d: d[s] += 1
    else: d[s] = 1

t = []
for k in d.keys(): t.append(k)
if len(t) < 3:
  print(0)
  exit()
  
ans = 0
for i in combinations(t, 3):
  ans += d[i[0]]*d[i[1]]*d[i[2]]
print(ans)

Solution (Python):
import sys
from itertools import combinations

input = sys.stdin.readline


def main():
    N = int(input())
    S = [""] * N
    for i in range(N):
        S[i] = input().rstrip()

    count = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
    for s in S:
        if s[0] in "MARCH":
            count[s[0]] += 1

    ans = 0
    for c1, c2, c3 in combinations("MARCH", 3):
        ans += count[c1] * count[c2] * count[c3]

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
d = dict()
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":
        if s[0] not in d:
            d[s[0]] = 1
        else:
            d[s[0]] += 1
count = 0
d = list(d.values())
if len(d) == 3:
    count += d[0] * d[1] * d[2]
elif len(d) == 4:
    count += d[0] * d[1] * d[2]
    count += d[3] * d[1] * d[2]
    count += d[0] * d[1] * d[3]
    count += d[0] * d[3] * d[2]
elif len(d) == 5:    
    count += d[0] * d[1] * d[2]
    count += d[3] * d[1] * d[2]
    count += d[0] * d[1] * d[3]
    count += d[0] * d[3] * d[2]

    
    count += d[4] * d[1] * d[2]
    count += d[0] * d[1] * d[4]
    count += d[0] * d[4] * d[2]

    
    
    count += d[4] * d[1] * d[3]
    count += d[4] * d[3] * d[2]

    
    
    count += d[0] * d[4] * d[3]
    


print(count)

Solution (Python):
MARCH = list('MARCH')

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


namect = []
for i in range(5):
    st = [s for s in S if s.startswith(MARCH[i])]
    namect.append(len(st))
ans = 0
for i in range(5):
    for j in range(i+1, 5):
        for k in range(j+1, 5):
            ans += namect[i]*namect[j]*namect[k]
print(ans)

Solution (Python):
import sys
from collections import Counter

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    S = [readline().strip() for _ in range(N)]

    initials = set('MARCH')
    counter = Counter()
    for s in S:
        if s[0] in initials:
            counter[s[0]] += 1

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

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
l = [0]*5

for i in range(n):
    a = input()
    if a[0] == "M":
        l[0] += 1
    elif a[0] == "A":
        l[1] += 1
    elif a[0] == "R":
        l[2] += 1
    elif a[0] == "C":
        l[3] += 1
    elif a[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())
M=0
A=0
R=0
C=0
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
    
print(M*A*R+M*A*C+M*A*H+M*R*C+M*R*H+M*C*H+A*R*C+A*C*H+A*R*H+R*C*H)

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

Solution (Python):
import itertools
from functools import reduce

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

counter = [len(list(filter(lambda s: s[0] == l, S))) for l in 'MARCH']

ans = 0
for pat in itertools.combinations(range(5), 3):
    ans += reduce(lambda a, b: a * b, [counter[p] for p in pat], 1)

print(ans)

Solution (Python):
from itertools import combinations
N = int(input())
X = ["M","A","R","C","H"]
Y = [0 for _ in range(5)]
for _ in range(N):
  S = input()
  for i, x in enumerate(X):
    if x == S[0]:
      Y[i] += 1
      break
    
ans = 0
for y in combinations(Y, 3):
  ans += y[0] * y[1] * y[2]
print(ans)

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

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

c = defaultdict(int)

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

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

if len(c)==3:
  ans=1
  for k in c.keys():
    ans *= c[k]
  print(ans)
  exit()

else:
  ans = 0
  l = len(c)
  keys = list(c.keys())
  for C in combinations(range(l),3):
    tmp = c[keys[C[0]]]*c[keys[C[1]]]*c[keys[C[2]]]
    ans += tmp
  print(ans)

Solution (Python):
from collections import defaultdict
from itertools import combinations
def main():
    n = int(input())
    d = defaultdict(int)
    for _ in range(n):
        s = input()
        d[s[0]] += 1
    ans = 0
    for i, j, k in combinations('MARCH', 3):
        ans += d[i] * d[j] * d[k]
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import collections

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

for i in range(5):
    ref_lst[i][1] = S.count(ref_lst[i][0])

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

print(ans)

Solution (Python):
import itertools
l=['M','A','R','C','H']
c = itertools.combinations(l, 3)
MARCH = {'M':0,'A':0,'R':0,'C':0,'H':0}
N=int(input())
for i in range(N):
  s=str(input())
  if s[0]=='M':
    MARCH['M']+=1
  elif s[0]=='A':
    MARCH['A']+=1
  elif s[0]=='R':
    MARCH['R']+=1
  elif s[0]=='C':
    MARCH['C']+=1
  elif s[0]=='H':
    MARCH['H']+=1
ans=0
for i in c:
  ans+=MARCH[i[0]]*MARCH[i[1]]*MARCH[i[2]]
print(ans)

Solution (Python):
MARCH = {'M':0,'A':0,'R':0,'C':0,'H':0}
N=int(input())
for i in range(N):
  s=str(input())
  if s[0]=='M':
    MARCH['M']+=1
  elif s[0]=='A':
    MARCH['A']+=1
  elif s[0]=='R':
    MARCH['R']+=1
  elif s[0]=='C':
    MARCH['C']+=1
  elif s[0]=='H':
    MARCH['H']+=1
ans = MARCH['M']*MARCH['A']*MARCH['R']\
  +MARCH['M']*MARCH['A']*MARCH['C']\
  +MARCH['M']*MARCH['A']*MARCH['H']\
  +MARCH['M']*MARCH['R']*MARCH['C']\
  +MARCH['M']*MARCH['R']*MARCH['H']\
  +MARCH['M']*MARCH['C']*MARCH['H']\
  +MARCH['A']*MARCH['R']*MARCH['C']\
  +MARCH['A']*MARCH['R']*MARCH['H']\
  +MARCH['A']*MARCH['C']*MARCH['H']\
  +MARCH['R']*MARCH['C']*MARCH['H']
print(ans)

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

STR = "MARCH"

N = int(input())
s = [input() for _ in range(N)]
dd = defaultdict(int)
for i in range(N):
  dd[s[i][0]] += 1
t = tuple(dd[S]  for S in STR)
p = combinations(t,3)
ans = sum(x[0]*x[1]*x[2] for x in p)
print(ans)

Solution (Python):

import itertools


def main():
    N = int(input())
    S = [input() for i in range(N)]
    S_cnt = [0]*5
    E = ["M", "A", "R", "C", "H"]
    for s in S:
        for i in range(5):
            if s[0] ==E[i]:
                S_cnt[i] += 1
    E_list = list(itertools.combinations(E, 3))
    tmp = 1
    ans = 0
    for e in E_list:
        for i in range(3):
            for j in range(5):
                if e[i] == E[j]:
                    tmp *= S_cnt[j]
        ans += tmp
        tmp = 1
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
from collections import defaultdict
from itertools import groupby, accumulate, product, permutations, combinations
def solve():
  d = defaultdict(lambda: 0)
  N = int(input())
  for i in range(N):
    S = input()
    d[S[0]] += 1
  s = 'MARCH'
  s = list(s)
  cnt = 0
  for com in combinations(s,3):
    prod = 1
    for c in com:
      prod *= d[c]
    cnt += prod
  return cnt
print(solve())

Solution (Python):
import sys
import itertools

N = int(sys.stdin.readline())

count = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for _ in range(N):
    s = sys.stdin.readline().strip()
    if s[0] in count:
        count[s[0]] += 1

ans = 0
for perm in itertools.combinations(count.keys(), 3):
    tmp = 1
    for i in perm:
        tmp *= count[i]
    ans += tmp

print(ans)

Solution (Python):
import itertools
n = int(input())
s = [input() for _ in range(n)]
a = [0,0,0,0,0]
for i in range(len(s)):
    if (s[i][0]=="M"):
        a[0] += 1
    elif (s[i][0]=="A"):
        a[1] += 1
    elif (s[i][0]=="R"):
        a[2] += 1
    elif (s[i][0]=="C"):
        a[3] += 1
    elif (s[i][0]=="H"):
        a[4] += 1

l = [0,1,2,3,4]
p = list(itertools.combinations(l, 3))
ans = 0
for i in range(len(p)):
    x,y,z = p[i][0],p[i][1],p[i][2]
    ans += a[x]*a[y]*a[z]
print(ans)

Solution (Python):
from itertools import combinations

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

memo = {}
for i in 'MARCH':
    memo[i] = 0

for i in S:
    if i[0] in 'MARCH':
        memo[i[0]] += 1

ans = 0
for i, j, k in combinations('MARCH', 3):
    ans += memo[i] * memo[j] * memo[k]
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()
    if S[0] == 'M':
        march['M'] += 1
    elif S[0] == 'A':
        march['A'] += 1
    elif S[0] == 'R':
        march['R'] += 1
    elif S[0] == 'C':
        march['C'] += 1
    elif S[0] == 'H':
        march['H'] += 1
ans = 0
ans += march['M']*march['A']*march['R']
ans += march['M']*march['A']*march['C']
ans += march['M']*march['A']*march['H']
ans += march['M']*march['R']*march['C']
ans += march['M']*march['R']*march['H']
ans += march['M']*march['C']*march['H']
ans += march['A']*march['R']*march['C']
ans += march['A']*march['R']*march['H']
ans += march['A']*march['C']*march['H']
ans += march['R']*march['C']*march['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
    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
MARCH = [M,A,R,C,H]
for i in range(5):
    for j in range(i+1, 5):
        for k in range(j+1, 5):
            ans += MARCH[i]*MARCH[j]*MARCH[k]
print(ans)

Solution (Python):
import collections
def dfs(i, cumul, cc, k, s): return (cumul if k == 0 else 0) if (i == len(s) or k == 0) else (dfs(i+1,  cumul * cc[s[i]], cc,k - 1, s) +dfs(i+1,  cumul, cc, k, s))
print dfs(0,  1 , collections.Counter([raw_input()[0] for _ in range(int(raw_input()))]), 3, 'MARCH')

Solution (Python):
import collections
cc = collections.Counter([raw_input()[0] for _ in range(int(raw_input()))])


def dfs(i, total ,cumul, cc, k, s):
	if i == len(s) or k == 0:
		if k == 0: total[0] += cumul
		return 
	
	dfs(i+1, total, cumul * cc[s[i]], cc,k - 1, s)
	dfs(i+1, total, cumul, cc, k, s)

total = [0]
dfs(0, total, 1 , cc, 3, 'MARCH')
print total[0]

Solution (Python):
import collections
cc = collections.Counter()
for _ in range(int(raw_input())): 
	cc[raw_input()[0]] +=1	

def dfs(i, total ,cumul, cc, k, s):
	if i == len(s) or k == 0:
		if k == 0: total[0] += cumul
		return 
	if k:
		dfs(i+1, total, cumul * cc[s[i]], cc,k - 1, s)

	dfs(i+1, total, cumul, cc, k, s)

total = [0]
dfs(0, total, 1 , cc, 3, 'MARCH')
print total[0]

Solution (Python):
import collections
cc = collections.Counter()
for _ in range(int(raw_input())): 
	s = raw_input()
	cc[s[0]] +=1	

def dfs(i, total ,cumul, cc, k, s):
	if i == len(s):
		if k == 0:
			total[0] += cumul
		return 

	if k:
		dfs(i+1, total, cumul * cc[s[i]], cc,k - 1, s)
	dfs(i+1, total, cumul, cc, k, s)

total = [0]
dfs(0, total, 1 , cc, 3, 'MARCH')
print total[0]

Solution (Python):
import collections
cc = collections.Counter()
for _ in range(int(raw_input())): 
	s = raw_input()
	cc[s[0]] +=1	

def dfs(i, total ,cumul, cc, k, s):
	if i == len(s):
		if k == 0:
			total[0] += cumul
		return 

	dfs(i+1, total, cumul * cc[s[i]], cc,k - 1, s)
	dfs(i+1, total, cumul, cc, k, s)

total = [0]
dfs(0, total, 1 , cc, 3, 'MARCH')
print total[0]

Solution (Python):
def main():
    N = int(input())
    A = [input()[0] for i in range(N)]
    from collections import Counter
    from itertools import combinations
    c = Counter(A)
    d = ('M', 'A', 'R', 'C', 'H')
    ans = 0
    for (a1, a2, a3) in combinations(d, 3):
        ans += c[a1] * c[a2] * c[a3]
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
import collections
import itertools

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007



def main():
	n = int(input())
	
	
	al = collections.defaultdict(lambda :0)
	for _ in range(n):
		s=input()
		al[s[0]] += 1
	ret = 0
	for cl in itertools.combinations('MARCH', 3):
		r=1
		for c in cl:
			
			r *= al[c]
		ret += r
	print(ret)
	
	
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

Solution (Python):
import itertools

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

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

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

print(ans)

Solution (Python):
import itertools
N = int(input())
X = [input()[0] for _ in range(N)]
M = X.count("M")
A = X.count("A")
R = X.count("R")
C = X.count("C")
S = 0
H = X.count("H")
for s in itertools.combinations([M, A, R, C, H], 3):
  S += s[0]*s[1]*s[2]
print(S)

Solution (Python):

from collections import defaultdict
from itertools import combinations

_, *s = open(0).read().split()
d = defaultdict(int)
for i in s:
    d[i[0]] += 1
ans = 0
for a, b, c in combinations(["M", "A", "R", "C", "H"], 3):
    ans += d[a] * d[b] * d[c]
print(ans)

Solution (Python):
from itertools import combinations
initials = {'M':0,'A':0,'R':0,'C':0,'H':0}
for _ in range(int(input())):
  name = input()
  initials[name[0]] = initials.get(name[0],0)+1
answer = 0
for initial in combinations('MARCH',3):
  answer += initials[initial[0]]*initials[initial[1]]*initials[initial[2]]
print(answer)