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

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

M = 0
A = 0
R = 0
C = 0
H = 0
for s in S:
	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
res = 0
if M * A * R != 0:
	res += M * A * R
if M * A * C != 0:
	res += M * A * C
if M * A * H != 0:
	res += M * A * H
if M * R * C != 0:
	res += M * R * C
if M * R * H != 0:
	res += M * R * H
if M * C * H != 0:
	res += M * C * H

if A * R * C != 0:
	res += A * R * C
if A * R * H != 0:
	res += A * R * H
if A * C * H != 0:
	res += A * C * H
if R * C * H != 0:
	res += R * C * H

print(res)

Solution (Python):
import collections
import itertools
from pprint import pprint as pp

N = int(input())
S = collections.defaultdict(int)
for _ in range(N):
  s = input()
  if s[0] not in ('MARCH'):
    continue
  S[s[0]] += 1
cnt = 0
for (a,b,c) in itertools.combinations('MARCH', 3):
  cnt += S[a] * S[b] * S[c]
print(cnt)

Solution (Python):
N=int(input())
Mlen=Alen=Rlen=Clen=Hlen=0

for i in range(N):
	IN=list(input())
	if IN[0]=="M":
		Mlen+=1
	elif IN[0]=="A":
		Alen+=1
	elif IN[0]=="R":
		Rlen+=1
	elif IN[0]=="C":
		Clen+=1
	elif IN[0]=="H":
		Hlen+=1
	else:
		pass

name=[Mlen,Alen,Rlen,Clen,Hlen]
ans=0

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

print(ans)

Solution (Python):
n = int(input())
m=0
a=0
r=0
c=0
h=0
name = [list(str(input().split())) for i in range(n)]
for i in range(n):
    if name[i][2] == "M":
        m = m+1
    elif name[i][2] == "A":
        a = a+1
    elif name[i][2] == "R":
        r = r+1
    elif name[i][2] == "C":
        c = c+1
    elif name[i][2] == "H":
        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):
count=int(input())

data=[]
for i in range(count):
    data.append(input()[0])

counts=[0,0,0,0,0]

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

for i in data:
    if i=='M':
        counts[0]+=1
    if i=='A':
        counts[1]+=1
    if i=='R':
        counts[2]+=1
    if i=='C':
        counts[3]+=1
    if i=='H':
        counts[4]+=1

ans=0

select=[(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 select:
    ans+=counts[i[0]]*counts[i[1]]*counts[i[2]]
    
print(ans)

Solution (Python):
def solve():
    n = int(input())
    s = [0,0,0,0,0]
    for i in range(n):
        name = input()
        if name[0] == 'M':
            s[0] += 1
        if name[0] == 'A':
            s[1] += 1
        if name[0] == 'R':
            s[2] += 1
        if name[0] == 'C':
            s[3] += 1
        if name[0] == 'H':
            s[4] += 1

    u = []
    for i in range(5):
        if s[i] > 0:
            u.append(i)

    import itertools
    ans = 0

    if len(u) < 3:
        print(ans)
        return
    
    
    for com in itertools.combinations(u, 3):
        
        ans += s[com[0]]*s[com[1]]*s[com[2]]
    print(ans)

solve()

Solution (Python):
n = int(input())
s = []
for i in range(n):
    s.append(str(input()))
m = 0
a = 0
r = 0
c = 0
h = 0
for i in range(n):
    if s[i].startswith("M"):
        m = m + 1
    if s[i].startswith("A"):
        a = a + 1
    if s[i].startswith("R"):
        r = r + 1
    if s[i].startswith("C"):
        c = c + 1
    if s[i].startswith("H"):
        h = h + 1
march = [m, a, r, c, h]
choice = 0
for i in range(5):
    for j in range(5):
        for k in range(5):
            if i != j and i != k and j != k:
                choice = choice + march[i] * march[j] * march[k]
print(int(choice/6))

Solution (Python):
import itertools

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

for _ in range(N):
    S.append(input()[0])
    
num = [S.count(char) for char in ['M', 'A', 'R', 'C', 'H']]

if num.count(0) >= 3:
    print(0)
else:
    nonzero = [n for n in num if n != 0]
    case = list(itertools.combinations(nonzero, 3))
    total = sum([tpl[0]*tpl[1]*tpl[2] for tpl in case])
    
    print(total)

Solution (Python):
import itertools
n=int(input())
dict={'M':0,'A':0,'R':0,'C':0,'H':0}
tmp=['M','A','R','C','H']
for i in range(n):
  name=input()
  if name[0] in tmp:
    dict[name[0]]+=1
num=list(dict.values())
c=list(itertools.combinations(num,3))
ans=0
for i in c:
  ans+=i[0]*i[1]*i[2]
print(ans)

Solution (Python):
import sys
N=int(input())
S=[]
for i in range(N):
    S.append(input()[0])
    
Count=[]
Count.append(S.count("M"))
Count.append(S.count("A"))
Count.append(S.count("R"))
Count.append(S.count("C"))
Count.append(S.count("H"))

Zero=Count.count(0)
if(Zero>=3):print(0)
elif(Zero==2):
    Count.remove(0)
    Count.remove(0)
    pat=1
    for i in Count:pat*=i
    print(pat)
elif(Zero==1):
    Count.remove(0)
    patA=1
    for i in Count:patA*=i
    pat=0
    for i in Count:pat+=patA//i
    print(pat)
elif(Zero==0):
    patA=1
    for i in Count:patA*=i
    pat=0
    for i in range(5):
        for j in range(5):
            if(i==j):continue
            else:
                pat+=patA//Count[i]//Count[j]
    print(pat//2)

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

names = [input()[0] for i in range(n)]
prefix = 'MARCH'
cnt = [names.count(c) for c in prefix]

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

Solution (Python):
from collections import Counter
n = int(input())
s = []
for i in range(n):
    temp = input()[0]
    if temp in 'MARCH':
        s.append(temp)
c = Counter(s)
if len(c) < 3:
    print(0)
else:
    num = []
    for i in c:
        num.append(c[i])
    l = len(num)
    ans = 0
    for i in range(0, l):
        for j in range(i+1, l):
            for k in range(j+1, l):
                ans += num[i]*num[j]*num[k]
    print(ans)

Solution (Python):
from sys import exit, setrecursionlimit
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

setrecursionlimit(1000000)

N = read()
dic = defaultdict(int)

for i in range(N):
  s = input()
  dic[s[0]] += 1

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

print(result)

Solution (Python):
import itertools
from collections import Counter
n=int(input())
a0=[input()[0] for i in range(n)]
a =[i for i in a0 if i in ["M","A","R","C","H"]]
c = dict(Counter(a))

if len(set(a))<=2:
  print(0)
else:
  x=0
  for i1, i2, i3 in itertools.combinations(set(a), 3):
    x+=c[i1]*c[i2]*c[i3]
  print(x)

Solution (Python):
import collections
n=int(input())
name = [input()[0] for x in range(n)]
c = collections.Counter(name)
march = [c['M'],c['A'],c['R'],c['C'],c['H']]

s = sum(march)
s2 = sum([x**2 for x in march])
s3 = sum([x**3 for x in march])
print((s**3-3*s2*s+2*s3)//6)

Solution (Python):
n = int(input())
table = "MARCH"
arr = [0] * len(table)

for i in range(n):
    A = input()
    for j in range(len(table)):
        if A[0] == table[j]:
            arr[j]+=1

res = 0
for i in range(len(table)):
    for j in range(i+1,len(table)):
        for k in range(j+1,len(table)):
            res+=arr[i]*arr[j]*arr[k]

print(res)

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 S:
    if i[0] == 'M':
        M += 1
    elif i[0] == 'A':
        A += 1
    elif i[0] == 'R':
        R += 1
    elif i[0] == 'C':
        C += 1
    elif i[0] == 'H':
        H += 1


def baai(X, x):
    if x == 0:
        return 1
    if x == 1:
        return X
    else:
        return -1
    


num = 0
for m in range(2):
    for a in range(2):
        for r in range(2):
            for c in range(2):
                for h in range(2):
                    if (m + a + r + c + h) == 3:
                        num += baai(M,m)*baai(A,a)*baai(R,r)*baai(C,c)*baai(H,h)
print(num)

Solution (Python):
import itertools as it

def c(n,k):
  if k>n:
    return 0
  ret = 1
  for i in range(n, n-k, -1):
    ret *= i
  for i in range(k, 1, -1):
    ret /= i
  return ret


n = int(input())
dic = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
for person in range(n):
  name = input()
  if name[0] in 'MARCH':
    dic[name[0]] += 1

answer = 0
for a,b,c in it.combinations('MARCH', 3):
  answer += dic[a] * dic[b] * dic[c]
print(answer)

Solution (Python):
from itertools import combinations

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

cand = ['M', 'A', 'R', 'C', 'H']
count = [0 for _ in range(5)]
for s in S:
    for i, c in enumerate(cand):
        if c == s[0]:
            count[i] += 1

if count.count(0) < 3:
    for i in list(range(5))[::-1]:
        if count[i] == 0:
            del count[i]
    P = list(combinations(count, 3))
    result = 0
    for p in P:
        result += p[0] * p[1] * p[2]
else:
    result = 0

print(int(result))

Solution (Python):


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

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

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

Solution (Python):
def main():
    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
    march_sum = 0
    for i in range(0, 3):
        for j in range(i+1, 4):
            for k in range(j+1, 5):
                march_sum += march[i] * march[j] * march[k]
    print(march_sum)


if __name__ == '__main__':
    main()

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

fields = [0 for x in "MARCH"]
index = {v:i for i, v in enumerate("MARCH")}

for i in a:
    try:
        fields[index[i[0]]] += 1
    except:
        pass

import itertools
result = 0
for i in itertools.combinations(fields, 3):
    result += list(itertools.accumulate(i, lambda l, r: l * r))[-1]
print(result)

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

c=defaultdict(int)
for _ in range(n):
    s=input()
    if s[0] in 'MARCH':
        c[s[0]]+=1
res=0
for comb in combinations('MARCH',3):
    res+=c[comb[0]]*c[comb[1]]*c[comb[2]]
print(res)

Solution (Python):

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

ch = "MARCH"
xs = [0] * 5

for s in S:
    if s[0] in ch:
        i = ch.index(s[0])
        xs[i] += 1

from itertools import combinations

def calc(xs):
    r = 0
    for ys in combinations([0, 1, 2, 3, 4], 3):
        r += xs[ys[0]] * xs[ys[1]] * xs[ys[2]]
    return r

print(calc(xs))

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

A = [0] * 5
for i in range(N):
    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

ans = A[0]*A[1]*A[2] + A[0]*A[1]*A[3] + A[0]*A[1]*A[4] + A[0]*A[2]*A[3] + A[0]*A[2]*A[4] + A[0]*A[3]*A[4] + A[1]*A[2]*A[3] + A[1]*A[2]*A[4] + A[1]*A[3]*A[4] + A[2]*A[3]*A[4]

print(ans)

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

A = [input()[0] for i in range(n)]
for i in A:
    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
B = [m,a,r,c,h]
for b in list(itertools.combinations(B,3)):
    ans += b[0]*b[1]*b[2]

print(ans)

Solution (Python):
N = int(input())
S = [input()[0] for i in range(N)]
B = {}
for c in S:
    if c not in 'MARCH':
        continue
    B[c] = B.get(c, 0) + 1
A = sum(B.values())
ans = A*(A-1)*(A-2)//6
for c1 in B:
    ans -= B[c1] * (B[c1]-1) * (B[c1]-2) // 6
    for c2 in B:
        if not c1 < c2:
            continue
        ans -= B[c1] * (B[c1]-1) * B[c2] // 2
        ans -= B[c2] * (B[c2]-1) * B[c1] // 2
print(ans)

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

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


k=[]
k.append(number[0]*number[1]*number[2])
k.append(number[0]*number[1]*number[3])
k.append(number[0]*number[1]*number[4])
k.append(number[0]*number[2]*number[3])
k.append(number[0]*number[2]*number[4])
k.append(number[0]*number[3]*number[4])

k.append(number[1]*number[2]*number[3])
k.append(number[1]*number[2]*number[4])
k.append(number[1]*number[3]*number[4])
k.append(number[2]*number[3]*number[4])

print(sum(k))

Solution (Python):
ini_list = \
    [('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')]

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

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

result = 0

for a, b, c in ini_list:
    result += name_dict[a] * name_dict[b] * name_dict[c]

print(result)

Solution (Python):


import os
import sys
import math
import numpy as np
import collections
import itertools
import functools
import operator

N = int(input())
names = collections.defaultdict(list)


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

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

ans = 0
prod = functools.partial(functools.reduce, operator.mul)

for heads in itertools.combinations(march, 3):
    nums = [len(names[head]) for head in heads]
    ans += prod(nums)

print(ans)

Solution (Python):
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
n=i1()
from collections import Counter
a=[]
for i in range(n):
 s=input()
 if s[0]=="M" or s[0]=="A" or s[0]=="R" or s[0]=="C" or s[0]=="H":
   a.append(s[0])
c= Counter(a)
cv=list(c.values())
import itertools
b=list(itertools.combinations(range(len(cv)),3))
d=0
for i in b:
 d+=cv[i[0]]*cv[i[1]]*cv[i[2]]
print(d)

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

Solution (Python):
from itertools import combinations


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

    f(S)


def f(S):
    march = list("MARCH")
    n = {k: 0 for k in march}
    for s in S:
        if s[0] in march:
            n[s[0]] += 1

    ans = 0
    for a, b, c in combinations(march, 3):
        ans += n[a] * n[b] * n[c]

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import itertools
m = a = r = c = h = 0
for i in xrange(input()):
    s = raw_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
for i in itertools.combinations((m,a,r,c,h), 3):
    ans += i[0]*i[1]*i[2]
print ans

Solution (Python):
n = int(input())
data = []
init = [0, 0, 0, 0, 0]
ans=0
for i in range(0, n):
    data.append(input())
    if data[i][0] == "M":
        init[0] += 1
    elif data[i][0] == "A":
        init[1] += 1
    elif data[i][0] == "R":
        init[2] += 1
    elif data[i][0] == "C":
        init[3] += 1
    elif data[i][0] == "H":
        init[4] += 1
ans+=init[0]*init[1]*init[2]
ans+=init[0]*init[1]*init[3]
ans+=init[0]*init[1]*init[4]
ans+=init[0]*init[2]*init[3]
ans+=init[0]*init[2]*init[4]
ans+=init[0]*init[3]*init[4]
ans+=init[1]*init[2]*init[3]
ans+=init[1]*init[2]*init[4]
ans+=init[1]*init[3]*init[4]
ans+=init[2]*init[3]*init[4]
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.startswith(march[i]):
            c[i] += 1
            break

s = 0
for i in range(5):
    for j in range(i + 1, 5):
        for k in range(j + 1, 5):
            s += c[i]*c[j]*c[k]

print(s)

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

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

cnt = {}
for c in 'MARCH':
    cnt[c] = 0
for s in S:
    c = s[0]
    if c not in 'MARCH':
        continue
    cnt[c] += 1


s = 'MARCH'
ans = 0
for i in range(3**5):
    a = i % 5
    b = i // 5 % 5
    c = i // 25 % 5
    if a == b or b == c or c == a:
        continue

    ans += cnt[s[a]] * cnt[s[b]] * cnt[s[c]]

print(ans // 12)

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

Solution (Python):
n = int(input())
s = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}

for i in [0]*n:
  t = input()
  if t[0] in s:
    s[t[0]] += 1
print(s['M']*(s['A']*(s['R']+s['C']+s['H'])+s['R']*(s['C']+s['H'])+s['C']*s['H']) + s['A']*(s['R']*(s['C']+s['H'])+s['C']*s['H'])+s['R']*s['C']*s['H'])

Solution (Python):
from itertools import combinations
n = int(input())
name = [0 for i in range(5)]
for i in range(n):
    a = input()
    if a[0] in "MARCH":
        name[list("MARCH").index(a[0])] += 1
ans = 0
for h, j, k in combinations("01234", 3):
    ans += (name[int(h)] * name[int(j)] * name[int(k)])
print(ans)

Solution (Python):

import math
from collections import Counter
N = int(input())

S = []
for n in range(N):
    S.append(input()[0])

S_cnt = Counter(S)

cond = [['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']]

ans = 0
for li in cond:
    ans += S_cnt[li[0]] * S_cnt[li[1]] * S_cnt[li[2]]
print(ans)

Solution (Python):
import itertools

n = int(input())

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

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

candidate = []
for combi in itertools.combinations(s_dict.keys(), 3):
    if s_dict[combi[0]] != 0 and s_dict[combi[1]] != 0 and s_dict[combi[1]] != 0:
            candidate.append(combi)
            
cnt = 0
for x in candidate:
    cnt += s_dict[x[0]] * s_dict[x[1]] * s_dict[x[2]]
    
print(cnt)

Solution (Python):



import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string

N = int(input())
S = Counter()
for n in range(N):
    s = input()
    if s[0] in 'MARCH':
        S[s[0]] += 1

if len(S) < 3:
    print(0)
else:
    keys = S.keys()
    ans = 0
    for comb in combinations(keys, 3):
        ans += S[comb[0]] * S[comb[1]] * S[comb[2]]
    print(ans)

Solution (Python):
N = input()
C = [0]*5
for _ in range(N):
  s = raw_input()[0]
  if s in "MARCH":
    C["MARCH".index(s)] += 1
ans = 0
for i in range(5):
  for j in range(i):
    for k in range(j):
      ans += C[i]*C[j]*C[k]
print ans

Solution (Python):
N = int(input())
count = {}
for i in range(N):
  s = input()[0]
  count[s] = count.get(s, 0) + 1

ans = 0
m = 'MARCH'
for i in range(5):
  mi = m[i]
  for j in range(i+1, 5):
    mj = m[j]
    for k in range(j+1, 5):
      mk = m[k]
      ans += count.get(mi, 0) * count.get(mj, 0) * count.get(mk, 0)

print(ans)

Solution (Python):
import itertools

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

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

Solution (Python):
n = int(input())
d = {'M':0,'A':0,'R':0,'C':0,'H':0}
march = 'MARCH'
for _ in range(n):
    s = input()
    if s[0] in march:
        d[s[0]] += 1
s = 0
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            s += d[march[i]]*d[march[j]]*d[march[k]]
print(s)

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

num = 0
for i, j, k in itertools.combinations(R, 3):
    num += dic[i]* dic[j] * dic[k]

print(num)

Solution (Python):
from collections import Counter
import itertools

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

ctr = Counter()
for s in src:
    ctr.update(s[0])

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

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

d = [0]*5

for a in range(n):
  s = raw_input()
  if s[0] == "M":
    d[0] += 1
  elif s[0] == "A":
    d[1] += 1
  elif s[0] == "R":
    d[2] += 1
  elif s[0] == "C":
    d[3] += 1
  elif s[0] == "H":
    d[4] += 1

ans = 0
for a in range(0,3):
  for b in range(a+1,4):
    for c in range(b+1,5):
      ans += d[a]*d[b]*d[c]
print ans

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

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

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

con = []
for c in ('M', 'A', 'R', 'C', 'H'):
    k = d[c]
    if k:
        con.append(k)

ans = 0
for a, b, c in combinations(con, 3):
    ans += a * b * c

print(ans)

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

N = int(raw_input())
c = Counter(raw_input()[0] for _ in range(N))

ans = 0
for (l1, l2, l3) in combinations("MARCH", 3):
  ans += c[l1] * c[l2] * c[l3]

print(ans)

Solution (Python):
N = int(input())
M, A, R, C, H = 0, 0, 0, 0 ,0
for i in range(N):
  s = input()
  if s[0] == "M": M+=1
  if s[0] == "A": A+=1
  if s[0] == "R": R+=1
  if s[0] == "C": C+=1
  if s[0] == "H": H+=1
ans = 0
ans += M*A*R
ans += M*A*C
ans += M*A*H
ans += M*R*C
ans += M*R*H
ans += M*C*H

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

ans += R*C*H

print(ans)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    a = [S() for _ in range(n)]
    c = collections.defaultdict(int)
    for s in a:
        if s[0] in 'MARCH':
            c[s[0]] += 1

    r = 0
    t = 'MARCH'
    for i in range(5):
        for j in range(i+1,5):
            for k in range(j+1,5):
                r += c[t[i]] * c[t[j]] * c[t[k]]

    return r


print(main())

Solution (Python):
import sys

stdin = sys.stdin

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

n = ni()
dic = [0] * 128
for i in range(n):
    s = ns()
    dic[ord(s[0])] += 1

x = [
    ord("M"),
    ord("A"),
    ord("R"),
    ord("C"),
    ord("H"),
]

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