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):
def main():
    from collections import Counter
    import itertools
    from math import factorial as f
    
    n, *s = open(0).read().split()
    i = [x[0] for x in s]
    d = Counter(i)
    c = [d.get(i) for i in 'MARCH' if d.get(i) != None]
    
    if len(c) < 3:
        ans = 0
    else:
        ans = 0
        for a,b,c in itertools.combinations(c,3):
          ans += a*b*c
    
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import itertools
N = int(input())
SK = {"M":0,"A":1,"R":2,"C":3,"H":4}
SD = [0]*5
del_list = []
A = ["M","A","R","C","H"]
for x in range(N):
    tmp = str(input())
    if tmp[0] in A:
        SD[SK[tmp[0]]] +=1
C = 0
for x in range(5):
    if SD[x] == 0 :
        del_list.append(x)
        C +=1
del_list.reverse()
for x in del_list:
    SD.pop(x)
    
if C >2:
    print(0)
else:
    Z = 5-C
    k = itertools.combinations(range(Z), 3)
    ans = 0
    for x in k:
        ans += SD[x[0]]*SD[x[1]]*SD[x[2]]
    print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
from itertools import combinations
from collections import Counter
def main():
    N = int(input())
    s = Counter()
    for _ in range(N):
        s[input().rstrip("\r\n")[0]] += 1
    print(sum([s[a]*s[b]*s[c] for a,b,c in combinations("MARCH",3)]))
if __name__ == "__main__":
    main()

Solution (Python):
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    d = {"M":0,"A":0,"R":0,"C":0,"H":0}
    for _ in range(N):
        s = input().rstrip("\r\n")
        if s[0] in d.keys():
            d[s[0]] += 1
    dv = []
    for v in d.values():
        if v != 0:dv.append(v)
    ans = 0
    if len(dv) >= 3:
        for i in range(len(dv)-2):
            for j in range(i+1,len(dv)-1):
                for k in range(j+1,len(dv)):
                    ans += dv[i]*dv[j]*dv[k]
    print(ans)
if __name__ == "__main__":
    main()

Solution (Python):
from collections import Counter
n = int(input())
name = [str(input()) for _ in range(n)]
name_first = []
cnt = 0

for i in name:
    name_first.append(i[0])
name_dic = Counter(name_first)


info = [name_dic["M"], name_dic["A"], name_dic["R"], name_dic["C"], name_dic["H"]]

for i in range(5):
    for j in range(5):
        for k in range(5):
            if i < j < k:
                cnt += info[i]*info[j]*info[k]

print(cnt)

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

Solution (Python):
from collections import Counter 
import itertools

def main():
    n = int(input())
    str_list = [input()[0] for _ in range(n)]

    str_count = Counter(str_list)

    ans = 0

    seq = ['M', 'A', 'R', 'C', 'H']

    for l in list(itertools.combinations(seq,3)):
        ans += str_count[l[0]] * str_count[l[1]] * str_count[l[2]]

    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):

from collections import Counter, deque



from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product


import sys
sys.setrecursionlimit(10 ** 5 + 10)


def resolve():

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

    SS=Counter(S)
    for i in SS:
        if i in 'MARCH':
            cnt.append(SS[i])
    ans=0
    for a,b,c in combinations(cnt,3):
        ans+=a*b*c



    print(ans)


resolve()

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

Solution (Python):


import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from collections import defaultdict
from itertools import combinations

n = ni()
s = nsn(n)
d = defaultdict(int)
for i in range(n):
    d[s[i][0]] += 1

m = [0] * 5
for i, v in enumerate("MARCH"):
    m[i] = d[v]

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

print(ans)

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

march = ["M","A","R","C","H"]
march_num = [0,0,0,0,0]

for i in range(len(s)):
    if s[i] in march:
        march_num[march.index(s[i])] += 1
ans = 0
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            ans += (march_num[i]*march_num[j]*march_num[k])
print(ans)

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

Solution (Python):
from itertools import (
    accumulate,  
    groupby,  
    permutations,  
    combinations,  
    product,  
)

n = int(input())
Sm, Sa, Sr, Sc, Sh = set(), set(), set(), set(), set()
for _ in range(n):
    s = input()
    if s[0]=='M':
        Sm.add(s)
    elif s[0]=='A':
        Sa.add(s)
    elif s[0]=='R':
        Sr.add(s)
    elif s[0]=='C':
        Sc.add(s)
    elif s[0]=='H':
        Sh.add(s)

ans = 0
S = [len(Sm), len(Sa), len(Sr), len(Sc), len(Sh)]

for v1, v2, v3 in combinations(S, 3):
    ans += v1*v2*v3

print(ans)

Solution (Python):
from itertools import combinations
n, *S = open(0).read().split()
n = int(n)
march = []
for c in 'MARCH':
    march.append(len([s for s in S if s[0] == c]))
ans = 0
for a, b, c in combinations(march, 3):
    ans += a*b*c
print(ans)

Solution (Python):
N = int(input())
alp = list("MARCH")
data = [0]*5
for i in range(N):
    s = list(input())
    for i in range(5):
        if alp[i] == s[0]: data[i] += 1

flag = 0
for i in range(5):
    if data[i] != 0: flag += 1

if flag < 3:
    print(0)
else:
    ans = 0
    for a in range(3):
        for b in range(a+1,4):
            for c in range(b+1,5):
                ans += data[a]*data[b]*data[c]
    print(ans)

Solution (Python):
from itertools import combinations
import collections

N = int(input()) 

A = []
for i in range(N):
    A.append(input()[0])

C = collections.Counter(A)
print(sum(C[a]*C[b]*C[c] for a, b, c in combinations("MARCH", 3)))

Solution (Python):
N = int(input())
alp = list("MARCH")
data = [0]*5
for i in range(N):
    s = list(input())
    for i in range(5):
        if alp[i] == s[0]: data[i] += 1

flag = 0
for i in range(5):
    if data[i] != 0: flag += 1

if flag < 3:
    print(0)
else:
    ans = 0
    for a in range(3):
        for b in range(a+1,4):
            for c in range(b+1,5):
                ans += data[a]*data[b]*data[c]
    print(ans)

Solution (Python):
import itertools
from collections import Counter

n=int(input())
s=[input()[0] for _ in range(n)]
d=Counter(s)
ans=0
for i,j,k in itertools.combinations("MARCH",3):
    ans+=d[i]*d[j]*d[k]
print(ans)

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
x = [m,a,r,c,h]
ans = 0
for i in range(5):
    for j in range(i):
        for k in range(j):
                ans += x[i]*x[j]*x[k]
print(ans)

Solution (Python):
import sys
from collections import Counter


N = int(input())
C = Counter()
for s in sys.stdin.readlines():
    C[s[0]] += 1

I = ['M', 'A', 'R', 'C', 'H']
ans = 0
for i in range(1 << 5):
    bit = i
    if bin(bit).count('1') == 3:
        var = 1
        for k in range(5):
            if (bit >> k) & 1:
                var *= C[I[k]]
        ans += var

print(ans)

Solution (Python):
import collections
import itertools
N=int(input())
S=[input() for _ in range(N)]
l=[]
l2=[]
l3=[]
sq=[]
lst=[]
cnt=0
for i in range(N):
    if (S[i][0]=="M")or(S[i][0]=="A")or(S[i][0]=="R")or(S[i][0]=="C")or(S[i][0]=="H"):
        l2.append(S[i][0])
c=collections.Counter(l2)
values=list(c.values())	
key=list(c.keys())	
for i in range(len(key)):
    sq.append(values[i])
    l.append([key[i],values[i]])
lst=list(itertools.combinations(sq,3))
for i in range(len(lst)):
    l3=list(lst[i])
    cnt=cnt+l3[0]*l3[1]*l3[2]

print(cnt)

Solution (Python):



from itertools import combinations


def main():

    N = int(input())

    count = {x: 0 for x in "MARCH"}

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

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

    print(result)


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
initials = ['M', 'A', 'R', 'C', 'H']
names = dict()
for init in initials:
  names[init] = set()

for i in range(N):
  si = str(input())
  if si[0] in initials:
    names[si[0]].add(si)


from itertools import combinations
ans = 0
for init in combinations(initials, 3):
  cmb = len(names[init[0]]) * len(names[init[1]]) * len(names[init[2]])
  ans += cmb
  

print(ans)

Solution (Python):
N=int(input())
L=[]
for i in range (N):
	L.append(input())
M=0
A=0
R=0
C=0
H=0
for i in L:
	if i[0]=="M":
		M+=1
	elif i[0]=="A":
		A+=1
	elif i[0]=="R":
		R+=1
	elif i[0]=="C":
		C+=1
	elif i[0]=="H":
		H+=1
ans=(M*A*R)+(M*A*C)+(M*A*H)+(M*R*C)+(M*R*H)+(M*C*H)+(A*R*C)+(A*R*H)+(A*C*H)+(R*C*H)
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 

def ii(): return int(sys.stdin.readline().rstrip()) 
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) 
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]

def ss(): return sys.stdin.readline().rstrip() 
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) 
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]





n=ii()

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

for i in range(n):
    s=ss()
    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
mat=[m,a,r,c,h]

arr=list(combinations([0,1,2,3,4],3))
ans=0
for i in arr:
    if mat[i[0]]>0 and mat[i[1]]>0 and mat[i[2]]>0:
        ans+=mat[i[0]]*mat[i[1]]*mat[i[2]]
print(ans)

Solution (Python):
n = int(input())
march = 'MARCH'
c = [0] * 5

for _ in range(n):
    s = input()
    for i in range(5):
        if s[0] == march[i]:
            c[i] += 1
ans = 0
for i in range(3):
    for j in range(i+1, 4):
        for k in range(j+1, 5):
            ans += c[i] * c[j] * c[k]
            
            

print(ans)

Solution (Python):
n = int(input())
march = 'MARCH'
c = [0] * 5

for _ in range(n):
    s = input()
    for i in range(5):
        if s[0] == march[i]:
            c[i] += 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):
_,*l=open(0);from itertools import*;print(sum(x*y*z for x,y,z in combinations([sum(c==s[0]for s in l)for c in'MARCH'],3)))

Solution (Python):
_,*l=open(0)
import itertools as it
print(sum(x*y*z for x,y,z in it.combinations([sum(s[0]==c for s in l) for c in 'MARCH'],3)))

Solution (Python):
l=[input()[0] for _ in range(int(input()))]
import itertools as it
print(sum(x*y*z for x,y,z in it.combinations([l.count(c) for c in 'MARCH'],3)))

Solution (Python):
from collections import *
d=Counter()
for _ in range(int(input())): d[input()[0]]+=1
import itertools as it
print(sum(d[s]*d[t]*d[r] for s,t,r in it.combinations('MARCH',3)))

Solution (Python):
n=int(input())
from collections import *
d=Counter()
for _ in range(n): d[input()[0]]+=1
import itertools as it
print(sum(d[s]*d[t]*d[r] for s,t,r in it.combinations('MARCH',3)))

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

m=0
a=0
r=0
c=0
h=0
for i in range(n):
    s=input()
    if s[0]=="M":
        m+=1
    elif s[0]=="A":
        a+=1
    elif s[0]=="R":
        r+=1
    elif s[0]=="C":
        c+=1
    elif s[0]=="H":
        h+=1
        
ans=m*a*(r+c+h)+m*r*(c+h)+m*c*h
ans=ans+a*r*(c+h)+a*c*h+r*c*h

print(ans)

Solution (Python):
m=[0]*5
for i in range(int(input())):
        try: m["MARCH".index(input()[0])]+=1
        except: continue
ans = 0
for i in range(5):
        for j in range(i+1,5):
                for k in range(j+1, 5):
                        ans += m[i]*m[j]*m[k]
print(ans)

Solution (Python):
ListM = []
ListA = []
ListR = []
ListC = []
ListH = []
N = int(input())
for j in range(N):
 S = input()
 if S[0] == "M":
  ListM.append(S)
 elif S[0] == "A":
  ListA.append(S)
 elif S[0] == "R":
  ListR.append(S)
 elif S[0] == "C":
  ListC.append(S)
 elif S[0] == "H":
  ListH.append(S)
 S = ()
print(len(ListM)*len(ListA)*len(ListR)+len(ListM)*len(ListA)*len(ListC)+len(ListM)*len(ListA)*len(ListH)+len(ListM)*len(ListR)*len(ListC)+len(ListM)*len(ListH)*len(ListR)+len(ListM)*len(ListC)*len(ListH)+\
len(ListC)*len(ListA)*len(ListR)+len(ListH)*len(ListA)*len(ListR)+len(ListC)*len(ListA)*len(ListH)+len(ListH)*len(ListC)*len(ListR))

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
 
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(int)
for s in S:
    if s[0] in "MARCH":
        dic[s[0]] += 1

march = list("MARCH")
L = list(combinations(march, 3))
ans = 0
for l in L:
    tmp = 1
    for y in l:
        tmp *= dic[y]
    ans += tmp
print(ans)

Solution (Python):
n=int(input())
start={"M","A","R","C","H"}
import collections
d=collections.defaultdict(set)
for i in range(n):
    a=input()
    if a not in d[a[0]] and a[0] in start:
        d[a[0]].add(a)

lis=[len(i) for i in d.values() if len(i)>0]

num=len(lis)
if num<3:
    print(0)
    exit()
ans=0
for x in range(num-2):
    for y in range(x+1,num-1):
        for z in range(y+1,num):
            ans+=lis[x]*lis[y]*lis[z]
print(ans)

Solution (Python):
def main():
    N = int(input())
    ans = []
    for i in range(N):
        s = input()
        if s[0] in ["M", "A", "R", "C", "H"]:
            ans.append(s[0])
    from collections import Counter
    c = Counter(ans)
    ret = 0
    from itertools import combinations
    for com in combinations(c.values(), 3):
        ret += com[0]*com[1]*com[2]
    print(ret)


if __name__ == '__main__':
    main()

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

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

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

ans+=r*c*h

print(ans)

Solution (Python):
from itertools import combinations
import collections
N = int(input())
S = [input() for i in range(N)]
table = collections.defaultdict(int)

for x in S:
    table[x[0]] += 1

tmp = ["M", "A", "R", "C", "H"]


ans = 0
for x in combinations(tmp, 3):
    ans += table[x[0]]*table[x[1]]*table[x[2]]
print(ans)

Solution (Python):
import sys
argVec = sys.argv
if len(argVec) > 1:
    GBN_DEBUG = True
else:
    GBN_DEBUG = False


N = int(input())


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


def dprn(s, i):
    if GBN_DEBUG:
        print(", " + s + " = " + str(i), end = "")

def dprns(s):
    if GBN_DEBUG:
        print(", " + s, end = "")

def dprni(i):
    if GBN_DEBUG:
        print(str(i), end=" ")

def puts(s):
    print(s)

def puti(i):
    print(str(i))

startM = 0
startA = 0
startR = 0
startC = 0
startH = 0

for i in range(N):
    if S[i][0] == 'M':
        startM += 1
    if S[i][0] == 'A':
        startA += 1
    if S[i][0] == 'R':
        startR += 1
    if S[i][0] == 'C':
        startC += 1
    if S[i][0] == 'H':
        startH += 1

mar = startM * startA * startR
mac = startM * startA * startC
mah = startM * startA * startH
mrc = startM * startR * startC
mrh = startM * startR * startH
mch = startM * startC * startH
arc = startA * startR * startC
arh = startA * startR * startH
ach = startA * startC * startH
rch = startR * startC * startH

ans = mar + mac + mah + mrc + mrh + mch + arc + arh + ach + rch
puti(ans)

Solution (Python):
N = int(input())
m = a = r = c = h = 0
for _ in range(N):
  s_in = input()
  if s_in[0] == "M": m += 1
  elif s_in[0] == "A": a += 1
  elif s_in[0] == "R": r+= 1
  elif s_in[0] == "C": c += 1
  elif s_in[0] == "H": h += 1

all_l = [m, a, r, c, h]
ans = 0
import itertools
for v in itertools.combinations(all_l, 3):
  if v[0] * v[1] * v[2] > 0:
    ans += v[0] * v[1] * v[2]
print(ans)

Solution (Python):
from collections import Counter
from itertools import combinations
from functools import reduce
from operator import mul
n = int(input())
S = [input()[0] for _ in range(n)]
S = [s for s in S if s in {"M","A","R","C","H"}]
cs = Counter(S)
ptn = combinations(cs.keys(), 3)

ans = 0
for p in ptn:
  arr = [cs[i] for i in p]
  ans += reduce(mul, arr)
print(ans)

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

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

ans = 0
for h in combinations(['M', 'A', 'R', 'C', 'H'], r=3):
    prd = 1
    for s in h:
        prd *= cnt[s]
    ans += prd
print(ans)

Solution (Python):
from itertools import combinations
N = int(input())
d = {}
for _ in range(N):
    s = input()
    if not s[0] in ("M","A","R","C","H"):
        continue
    if s[0] in d.keys():
        d[s[0]] += 1
    else:
        d[s[0]] = 1
ret = 0
comb = combinations(d.values(), 3)
for i in comb:
    tmp = 1
    for j in i:
        tmp *= j
    ret += tmp

print(ret)

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

if sum(S) == 0:
    print(0)
    exit(0)

I = [0, 0, 0, 0, 0, 0, 1, 1, 1, 2]
J = [1, 2, 3, 1, 1, 2, 2, 3, 2, 3]
K = [2, 3, 4, 3, 4, 4, 3, 4, 4, 4]
ans = 0
for i in range(10):
    ans += S[I[i]]*S[J[i]]*S[K[i]]
print(ans)

Solution (Python):
import sys

def solve():
    input = sys.stdin.readline
    nameCount = [0] * 5
    N = int(input())
    for _ in range(N):
        s = input().strip("\n")
        if s[0] == "M": nameCount[0] += 1
        elif s[0] == "A": nameCount[1] += 1
        elif s[0] == "R": nameCount[2] += 1
        elif s[0] == "C": nameCount[3] += 1
        elif s[0] == "H": nameCount[4] += 1
        else: continue
    Ans = 0
    for i in range(3):
        for j in range(i+1, 4):
            for k in range(j + 1, 5):
                Ans += nameCount[i] * nameCount[j] * nameCount[k]
    print(Ans)


    return 0

if __name__ == "__main__":
    solve()

Solution (Python):


from itertools import combinations

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

S=dict()
w=['M','A','R','C','H']

for e in s:
    fst=e[0]
    if fst in w:
        S[fst]=S.get(fst,0)+1

C=list(combinations(S,3))

ans=0
for c in C:
    tmp=1
    for e in c:
        tmp*=S[e]
    ans+=tmp
print(ans)

Solution (Python):

import itertools
"""
def len(a):
    return len(set(a))
"""

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

ans = 0
name_count = [0 for _ in range(5)]
M = []
A = []
R = []
C = []
H = []
for i in range(n):
    if s[i][0] == 'M':
        name_count[0] += 1
        M.append(s[i])
    if s[i][0] == 'A':
        name_count[1] += 1
        A.append(s[i])
    if s[i][0] == 'R':
        name_count[2] += 1
        R.append(s[i])
    if s[i][0] == 'C':
        name_count[3] += 1
        C.append(s[i])
    if s[i][0] == 'H':
        name_count[4] += 1
        H.append(s[i])

len_M = len(set(M))
len_A = len(set(A))
len_R = len(set(R))
len_C = len(set(C))
len_H = len(set(H))


tmp = [i for i in range(5)]
tmp2 = [len_M, len_A, len_R, len_C, len_H]
combination = list(itertools.combinations(tmp, 3))
ans = 0
for i in range(len(combination)):
    ans += tmp2[combination[i][0]] * tmp2[combination[i][1]] * tmp2[combination[i][2]] 
print(ans)

Solution (Python):
def main():
    N = int(input())
    ans = []
    for i in range(N):
        s = input()
        if s[0] in ["M", "A", "R", "C", "H"]:
            ans.append(s[0])
    from collections import Counter
    c = Counter(ans)
    ret = 1
    sumS = sum(int(c[s] > 0) for s in ["M", "A", "R", "C", "H"])
    accS = sum(c[s] for s in ["M", "A", "R", "C", "H"])
    if sumS >= 3:
        ret = accS*(accS-1)*(accS-2)//2//3
        for s in ["M", "A", "R", "C", "H"]:
            if c[s] == 2:
                ret -= (accS - c[s])
            elif c[s] >= 3:
                ret -= (c[s]*(c[s]-1)*(c[s]-2)//2//3) + \
                    ((c[s]-1)*(c[s])//2)*(accS - c[s])
    else:
        ret = 0
    print(ret)


if __name__ == '__main__':
    main()

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

for _ in range(N):
    S = input()
    if S[0] in ["M","A","R","C","H"]:
        cnt[S[0]] += 1

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

ans = 0
comb = list(combinations(["M","A","R","C","H"], 3))
for i in range(10):
    tmp = 1
    for c in comb[i]:
        tmp *= cnt[c]
    ans += tmp

print(ans)

Solution (Python):
from collections import defaultdict
import itertools

b = defaultdict(lambda: len(b))
n = int(input())
hed = ["M","A","R","C","H"]
for i in hed:
    b[i] 
li = [0]*5
for _ in range(n):
    a = input()
    if a[0] in hed:
        li[b[a[0]]] += 1
c = [j for j in li if j != 0]
ans = 0
for k in itertools.combinations(c,3):
    ans += k[0]*k[1]*k[2]
print(ans)

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

l = ['M', 'A', 'R', 'C', 'H']
d = dict()
for li in l: d[li] = 0
for si in S:
    for li in l:
        if si[0] == li: d[li] += 1

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

Solution (Python):
from collections import defaultdict
from itertools import combinations
n=int(input())
s=[input() for i in range(n)]
cnt=defaultdict(lambda :0)
cnt['M']=0
for i in range(n):
    if s[i][0] in 'MARCH':
        cnt[s[i][0]]+=1

if len(cnt)<=2:print(0)
else:
    num=len(cnt)
    ans=0
    for x,y,z in combinations(list(cnt.values()), 3):
        ans+=x*y*z
    print(ans)

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


v = list(d.values())
import itertools
ans = 0
for c in itertools.combinations(range(5),3):
    ans += v[c[0]]*v[c[1]]*v[c[2]]
print(ans)

Solution (Python):
import itertools
n = int(input())
a = [0] * 5
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
ar = list(itertools.combinations([0,1,2,3,4], 3))
ans = 0
for i in range(len(ar)):
    ans += a[ar[i][0]] * a[ar[i][1]] * a[ar[i][2]]
print(ans)

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

ans = 0
import itertools
for ptn in itertools.combinations('MARCH', 3):
    t = 1
    for c in ptn:
        t *= ctr[c]
    ans += t
print(ans)

Solution (Python):
N=int(input())
S=[input() for _ in range(N)]
march=list('MARCH')
nam=[[] for _ in range(len(march))]
for s in S:
    if s[0] in march:
        nam[march.index(s[0])].append(s)
ans=0
for i in range(5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            ans+=len(nam[i])*len(nam[j])*len(nam[k])
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, acos, atan, asin
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
def input(): return sys.stdin.readline().strip()
def STR(): return input()
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 = sys.maxsize
mod = 10 ** 9 + 7

n = INT()
num = [0 for _ in range(5)]
arr = ['M', 'A', 'R', 'C', 'H']
for _ in range(n):
    s = STR()
    if s[0] in arr:
        num[arr.index(s[0])] += 1
ans = 0
arr2 = list(combinations(range(5), 3))
for i in range(len(arr2)):
    tmp = 1
    for j in arr2[i]:
        tmp *= num[j]
    ans += tmp
print(ans)

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

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

name_dir = {"M":0,"A":0,"R":0,"C":0,"H":0}
for name in l:
    for alphabet in name_dir.keys():
        if name[0] == alphabet:
            name_dir[alphabet] += 1

name_counter = list(name_dir.values())
non0_name_counter = [s for s in name_counter if s != 0]

ans = 0
if name_counter.count(0) > 2:
    pass
elif name_counter.count(0) == 2:
    ans = non0_name_counter[0] * non0_name_counter[1] *non0_name_counter[2]
elif name_counter.count(0) == 1:
    for i in range(0,4):
        tmp = [s for s in list(range(0,4)) if s != i]
        ans += non0_name_counter[tmp[0]] * non0_name_counter[tmp[1]] * non0_name_counter[tmp[2]]
elif name_counter.count(0) == 0:
    for i in range(0,4):
        for j in range(i+1,5):
            tmp = [s for s in list(range(0,5)) if s != i and s != j]
            ans += non0_name_counter[tmp[0]] * non0_name_counter[tmp[1]] * non0_name_counter[tmp[2]]
print(ans)

Solution (Python):
from itertools import combinations

begin_with = list('MARCH')
num_of_begin_with = [0] * 5

n = int(input())
for _ in range(n):
    s = input()
    if s[0] in begin_with:
        num_of_begin_with[begin_with.index(s[0])] += 1

num_of_begin_with = [i for i in num_of_begin_with if i != 0]
cnt = 0
for a, b, c in combinations(num_of_begin_with, 3):
    cnt += a * b * c

print(cnt)

Solution (Python):
n=int(input())
s=['M','A','R','C','H']
for i in range(n):
    i=input()
    s.append(i[0])

import collections
c = collections.Counter(s)
d=['M','A','R','C','H']
ans=0
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            ans+=(c[d[i]]-1)*(c[d[j]]-1)*(c[d[k]]-1)
print(ans)

Solution (Python):
import sys
import numpy as np


n = int(input())


num = np.zeros(5)
for ii in range(n):
    nm = input()
    if nm[0] == "M":
        num[0] += 1
    if nm[0] == "A":
        num[1] += 1
    if nm[0] == "R":
        num[2] += 1
    if nm[0] == "C":
        num[3] += 1
    if nm[0] == "H":
        num[4] += 1
comb = 0
for i in range(5):
    for j in range(i+1, 5):
        for k in range(j+1, 5):
            cb = num[i] * num[j] * num[k]
            comb += cb
print(int(comb))

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


if __name__ == '__main__':
    solve()

Solution (Python):
import itertools


N = int(input())
ARR = []

for i in range(N):
    S = list(input())
    ARR.append(S)


def calculate(n,arr):
    brr = {
        "M":0,
        "A":0,
        "R":0,
        "C":0,
        "H":0,
    }

    for ar in arr:
        if ar[0] == "M":
            brr.__setitem__("M",brr.get("M") + 1)

        if ar[0] == "A":
            brr.__setitem__("A",brr.get("A") + 1)

        if ar[0] == "R":
            brr.__setitem__("R",brr.get("R") + 1)

        if ar[0] == "C":
            brr.__setitem__("C",brr.get("C") + 1)

        if ar[0] == "H":
            brr.__setitem__("H",brr.get("H") + 1)

    m = brr.values()

    ssk = []
    for k in m:
        ssk.append(k)


    result = []
    for ss in itertools.combinations(ssk,3):
        result.append(ss[0] * ss[1] * ss[2])


    print(sum(result))



calculate(N,ARR)