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 sys import stdin,setrecursionlimit
from math import factorial

setrecursionlimit(10 ** 7)

n = int(stdin.readline().rstrip())

li = [stdin.readline().rstrip() for i in range(n)]

name_list = [0]*5

for i in li:
    if i[0] in "MARCH":
        name_list["MARCH".index(i[0])] += 1

point = sum(1 for i in name_list if i != 0)

def combinations_count(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

from itertools import combinations
lin = list(combinations(name_list, 3))

count = 0

for i in lin:
    if 0 not in i:
        po = 1
        for j in i:
            po *= j
        count += po
print(count)

Solution (Python):
n = int(input())
ls = {'M':0,'A':0,'R':0,'C':0,'H':0}
head = set(["M","A","R","C","H"])

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

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

Solution (Python):
from itertools import combinations
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
res=0
for x in combinations([m,a,r,c,h],3):
    res+=x[0]*x[1]*x[2]
print(res)

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

judge = [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):
      ans += judge[i]*judge[j]*judge[k]
print(ans)

Solution (Python):
n = int(input())
march = ["M", "A", "R", "C", "H"]
num = [0] * 5
for i in range(n):
    s = input()
    if s[0] in march:
        num[march.index(s[0])] += 1
ans = 0
for i in range(0,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):
def main():
    N = int(input())
    A = [input() for i in range(N)]
    from itertools import combinations
    S = {"M": 0, "A": 1, "R": 2, "C": 3, "H": 4}
    ans = 0
    cnt = [0]*5
    for a in A:
        c = a[0]
        if c in S.keys():
            cnt[S[c]] += 1
    for comb in combinations(range(5), 3):
        ans += cnt[comb[0]]*cnt[comb[1]]*cnt[comb[2]]
    print(ans)


if __name__ == '__main__':
    main()

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

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
from decimal import Decimal
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
d = defaultdict(int)
s = ['M','A','R','C','H']
for _ in range(n):
    a = input()
    for i,t in enumerate(s):
        if a[0] == t:
            d[i] += 1
res = 0
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            res += d[i]*d[j]*d[k]
print(res)

Solution (Python):
from itertools import permutations


def main():
    n = int(input())
    l = ["M", "A", "R", "C", "H"]
    count = {x: 0 for x in l}
    for _ in range(n):
        s = input()[0]
        if s in count:
            count[s] += 1
    answer = 0
    for p in permutations(l, 3):
        answer += count[p[0]] * count[p[1]] * count[p[2]]
    print(answer // 6)


if __name__ == '__main__':
    main()

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

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

l = [0,0,0,0,0]
for i in range(N):
  if ls[i][0] == "M":
    l[0] += 1
  if ls[i][0] == "A":
    l[1] += 1
  if ls[i][0] == "R":
    l[2] += 1
  if ls[i][0] == "C":
    l[3] += 1
  if ls[i][0] == "H":
    l[4] += 1        

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

Solution (Python):
from operator import mul
from functools import reduce


def cmb(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


N = int(input())

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


combs = [
    ['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 c1, c2, c3 in combs:
    ans += cnt[c1] * cnt[c2] * cnt[c3]

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
if m*a*r != 0:
    ans += m*a*r
if m*a*c != 0:
    ans += m*a*c
if m*a*h != 0:
    ans += m*a*h
if m*r*c != 0:
    ans += m*r*c
if m*r*h != 0:
    ans += m*r*h
if m*c*h != 0:
    ans += m*c*h
if a*r*c != 0:
    ans += a*r*c
if a*r*h != 0:
    ans += a*r*h
if a*c*h != 0:
    ans += a*c*h
if r*c*h != 0:
    ans += r*c*h
print(ans)

Solution (Python):
n = int(input())
m_num = 0
r_num = 0
c_num = 0
a_num = 0
h_num = 0
for i in range(n):
    tmp = input()
    if tmp[0] == 'C':
        c_num += 1
        
    elif tmp[0] == 'R':
        r_num += 1
    
    elif tmp[0] == 'M':
        m_num += 1
        
    elif tmp[0] == 'A':
        a_num += 1
    
    elif tmp[0] == 'H':
        h_num += 1
        
print(m_num*c_num*r_num + a_num*c_num*r_num + h_num*c_num*r_num + m_num*r_num*a_num 
      + m_num*r_num*h_num + m_num*c_num*a_num +  m_num*c_num*h_num + a_num*h_num*m_num + a_num*h_num*r_num + a_num*h_num*c_num )

Solution (Python):

import itertools
n = int(input())
li = ['M','A','R','C','H']
d = {}
for l in li:
    d[l] = 0
ans = 0

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

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

print(ans)

Solution (Python):






def main():
    N = int(input())
    S = [None] * N
    for i in range(N):
        S[i] = input()[0]
    
    march = {s: 0 for s in "MARCH"}

    for s in S:
        if s in "MARCH":
            march[s] += 1
    
    march_filter = []
    for k, v in march.items():
        if v > 0:
            march_filter.append(v)
    
    n = len(march_filter)

    if n < 3:
        return 0

    members = []

    def rec(i, limit, member):
        if i == limit:
            if len(member) == 3:
                members.append(member)
            return None

        member_1 = member[:]
        member_2 = member[:]
        member_1.append(i)

        rec(i+1, n, member_1)
        rec(i+1, n, member_2)

    rec(0, n, [])

    ans = 0
    for member in members:
        tmp = 1
        for m in member:
            tmp *= march_filter[m]
        ans += tmp
    
    return ans


print(main())

Solution (Python):
from collections import Counter
n = int(input())
s = list()
li = [0]*5
for _ in range(n):
    k = input()[0]
    if k=="M":
        li[0]+=1
    elif k=="A":
        li[1]+=1
    elif k=="R":
        li[2]+=1
    elif k=="C":
        li[3]+=1
    elif k=="H":
        li[4]+=1

import itertools
li = itertools.combinations(li,3)
ans = 0
for k in li:
    cnt  =1
    for i in k:
        cnt*=i
    ans += cnt
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

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")
comb = list(combinations(march, 3))

ans = 0
for a, b, c in comb:
    ans += dic[a] * dic[b] * dic[c]
print(ans)

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

n, *s = [s[0] for s in sys.stdin.read().split()]

def main():
    c = Counter(s)
    res = 0
    for i, j, k in combinations('MARCH', 3):
        res += c[i] * c[j] * c[k]
    print(res)

if __name__ ==  '__main__':
    main()

Solution (Python):
from itertools import *
N = int(input())
m,a,r,c,h = 0,0,0,0,0
for _ in range(N):
  H =str(input())
  if H[0] == 'M':
    m += 1
  elif H[0] == 'A':
    a += 1
  elif H[0] == 'R':
    r += 1
  elif H[0] == 'C':
    c += 1
  elif H[0] == 'H':
    h += 1

L = [m,a,r,c,h]
L = [i for i in L if i > 0]

if len(L) < 3:
  print(0)
  exit()
else:
  ans = 0
  for l in combinations(L,3):
    a,b,c = l
    ans += (a*b*c)
    
print(ans)

Solution (Python):
from itertools import combinations as cmb

n=int(input())

idx=[0,0,0,0,0]

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

ans=0
for a,b,c in cmb(idx,3):
    ans+=a*b*c

print(ans)

Solution (Python):
n = int(input())
M = 0
A = 0
R = 0
C = 0
H = 0
for _ in range(n):
    x = input()[0]
    if x == "M":
        M += 1
    elif x == "A":
        A += 1
    elif x == "R":
        R += 1
    elif x == "C":
        C += 1
    elif x == "H":
        H += 1
    else:
        pass
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):
import sys
import itertools
sys.setrecursionlimit(10000)
def resolve():
    N = int(input())
    d = {
        "M": 0,
        "A": 0,
        "R": 0,
        "C": 0,
        "H": 0
    }
    for i in range(N):
        name = input()
        if name[0] in d:
            d[name[0]] += 1
    
    import itertools
    combs = list(itertools.combinations(d.keys(), 3))

    cnt = 0
    for comb in combs:
        cnt += d[comb[0]] * d[comb[1]] * d[comb[2]]
    
    print(cnt)

if '__main__' == __name__:
    resolve()

Solution (Python):
from itertools import *
N = int(input())
march = []
for _ in range(N):
  H =str(input())
  if H[0] == 'M' or H[0] == 'A' or H[0] == 'R' or H[0] == 'C' or H[0] == 'H':
    march.append(H[0])
march = ''.join(march)
m = march.count('M')
a = march.count('A')
r = march.count('R')
c = march.count('C')
h = march.count('H')
l = [m,a,r,c,h]
L = []
for i in range(len(l)):
  if l[i] > 0:
    L.append(l[i])
if len(L) < 3:
  print(0)
  exit()
else:
  ans = 0
  for l in combinations(L,3):
    a,b,c = l
    ans += (a*b*c)
    
print(ans)

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

a=["M","A","R","C","H"]
cnt=[0]*5
for i in range(n):
    s=input()
    for i in range(5):
        if s[0]==a[i]:
            cnt[i]+=1
ans=0
for i in range(3):
  for j in range(i+1,4):
    for k in range(j+1,5):
      ans+=cnt[i]*cnt[j]*cnt[k]
print(ans)

Solution (Python):

import sys
input = sys.stdin.readline









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

from collections import defaultdict
d = defaultdict(int)

for s in S:
    key = s[0]
    d[key] += 1

from itertools import combinations
c = combinations("MARCH",3)
ans = 0
for x,y,z in c:
    ans += d[x]*d[y]*d[z]

print(ans)

Solution (Python):
n=int(input())
m=[]
a=[]
r=[]
c=[]
h=[]
for i in range(n):
    k=input()
    if k[0]=="M":
        m.append(k)
    elif k[0]=="A":
        a.append(k)
    elif k[0]=="R":
        r.append(k)
    elif k[0]=="C":
        c.append(k)
    elif k[0]=="H":
        h.append(k)
s=0
s=s+len(m)*len(a)*len(r)+len(m)*len(a)*len(c)+len(m)*len(a)*len(h)+len(m)*len(r)*len(c)+len(m)*len(r)*len(h)+len(m)*len(c)*len(h)+len(a)*len(r)*len(c)+len(a)*len(r)*len(h)+len(a)*len(c)*len(h)+len(r)*len(c)*len(h)
print(s)

Solution (Python):
from itertools import combinations
from collections import Counter
s = 0
n = int(input())
l = Counter(list(input()[0] for _ in range(n)))
for a,b,c in combinations("MARCH",3):
  s += l[a]*l[b]*l[c]
print(s)

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


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


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


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


from itertools import combinations
base = list(combinations(arr,3))
ans = 0
for c in base:
    ans += c[0] * c[1] * c[2]

print(ans)

Solution (Python):
import itertools

N=int(input())
m = [0] * 5
for i in range(N):
  S = input()
  if S[0] == 'M':
    m[0] += 1
  elif S[0] == 'A':
    m[1] += 1
  elif S[0] == 'R':
    m[2] += 1
  elif S[0] == 'C':
    m[3] += 1
  elif S[0] == 'H':
    m[4] += 1
ans = 0
for (a,b,c) in itertools.combinations([0,1,2,3,4], 3):
  ans += m[a] * m[b] * m[c]
print(ans)

Solution (Python):
from itertools import permutations
from collections import defaultdict
n = int(input())
d = defaultdict(int)
for _ in range(n):
    name = input()
    d[name[0]] += 1

prefix = list('MARCH')
path = []
for i in range(5):
    for j in range(i + 1, 5):
        for k in range(j + 1, 5):
            path.append((prefix[i], prefix[j], prefix[k]))
ans = 0
for a, b, c in path:
    ans += d.get(a, 0) * d.get(b, 0) * d.get(c, 0)
print(ans)

Solution (Python):
url = "https://atcoder.jp/contests/abc089/tasks/abc089_c"
import itertools
import math

def main():
    mojiretu = ('M', 'A', 'R', 'C', 'H')
    dic = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
    t = input()
    count = 0
    for i in range(int(t)):
        tmp = input()
        if tmp[0] in mojiretu:
            dic[tmp[0]] += 1
    for l in itertools.combinations(mojiretu, 3):
        count += dic[l[0]] * dic[l[1]] * dic[l[2]]
    print(count)
if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
d = {}
s = "MARCH"
for c in s:
    d[c] = 0
for _ in range(N):
    c = input().strip()[0]
    if c in d:
        d[c] += 1

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

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

p = [0, 0, 0, 0, 0, 0, 1, 1, 1, 2]
q = [1, 1, 1, 2, 2, 3, 2, 2, 3, 3]
r = [2, 3, 4, 3, 4, 4, 3, 4, 4, 4]

d = [0] * 5

for i in range(n):
    if s[i][0] == "M":
        d[0] += 1
    elif s[i][0] == "A":
        d[1] += 1
    elif s[i][0] == "R":
        d[2] += 1
    elif s[i][0] == "C":
        d[3] += 1
    elif s[i][0] == "H":
        d[4] += 1
        
ans = 0
for i in range(0,10):
    ans += (d[p[i]] * d[q[i]] * d[r[i]])
print(ans)

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

l=[i[0] for i in s if i[0]=="M" or i[0]=="A" or i[0]=="R" or i[0]=="C" or i[0]=="H"]
c=collections.Counter(l)
v=list(c.values())
vn=len(v)

if vn<3:print(0)
if vn==3:print(v[0]*v[1]*v[2])
if vn==4:print(v[0]*v[1]*v[2]+v[0]*v[1]*v[3]+v[0]*v[2]*v[3]+v[1]*v[2]*v[3])
if vn==5:print(v[0]*v[1]*v[2]+v[0]*v[1]*v[3]+v[0]*v[1]*v[4]+v[0]*v[2]*v[3]+v[0]*v[2]*v[4]+v[0]*v[3]*v[4]+v[1]*v[2]*v[3]+v[1]*v[2]*v[4]+v[1]*v[3]*v[4]+v[2]*v[3]*v[4])

Solution (Python):
import itertools
from collections import Counter

n = int(input())
c = Counter()
for i in range(n):
    tmp = input().strip()
    if tmp[0] in ['M', 'A', 'R', 'C', 'H']:
        c[tmp[0]] += 1

result = 0
for v in itertools.permutations(c.values(), 3):
    result += v[0] * v[1] * v[2]

print(result // 6)

Solution (Python):
from itertools import combinations
n = int(input())
w = [0] * 5
march = 'MARCH'
for i in range(n):
  s = input()[0]
  if s in march:
    w[march.index(s)] += 1
print(sum(map(lambda a:a[0]*a[1]*a[2], combinations(w, 3))))

Solution (Python):
from itertools import combinations as c
n=int(input())
s=[input() for _ 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
print(sum(i*j*k for i, j, k in c(march, 3)))

Solution (Python):
n = int(input())
list_N = [input() for _ in range(n)]
list_N = list(set(list_N))
cnt = [0 for _ in range(5)]

for i in range(len(list_N)):
    l = list(list_N[i])
    if l[0] in "M":
        cnt[0] += 1
    elif l[0] in "A":
        cnt[1] += 1
    elif l[0] in "R":
        cnt[2] += 1
    elif l[0] in "C":
        cnt[3] += 1
    elif l[0] in "H":
        cnt[4] += 1

ans = 0
l  = []
if cnt.count(0) == 2:
    for num in cnt:
        if num != 0:
            l.append(num)
    ans += l[0]*l[1]*l[2]
if cnt.count(0) == 1:
    for num in cnt:
        if num != 0:
            l.append(num)
    ans += l[0] * l[1] * l[2]
    ans += l[0] * l[1] * l[3]
    ans += l[0] * l[2] * l[3]
    ans += l[2] * l[1] * l[3]
if cnt.count(0) == 0:
    l = cnt
    ans += l[0] * l[1] * l[2]
    ans += l[0] * l[1] * l[3]
    ans += l[0] * l[1] * l[4]
    ans += l[0] * l[2] * l[3]
    ans += l[0] * l[2] * l[4]
    ans += l[0] * l[3] * l[4]
    ans += l[1] * l[2] * l[3]
    ans += l[1] * l[2] * l[4]
    ans += l[1] * l[3] * l[4]
    ans += l[2] * l[3] * l[4]

if cnt.count(0) > 2:
    print(0)
else:
    print(ans)

Solution (Python):
from collections import defaultdict
march = "MARCH"
n = int(input())
dic = defaultdict(int)
for i in range(n):
    s = input()
    for j in range(5):
        if s[0] == march[j]:
            dic[march[j]] += 1
            break
        

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


print(ans)

Solution (Python):
n = int(input())
s = [input()[0] for i in range(n)]
work = [0, 0, 0, 0, 0]
for el in s:
    if el == "M":
        work[0] += 1
    elif el == "A":
        work[1] += 1
    elif el == "R":
        work[2] += 1
    elif el == "C":
        work[3] += 1
    elif el == "H":
        work[4] += 1
temp = sum(work)
result = temp*(temp-1)*(temp-2)//6
for el in work:
    result -= el*(el-1)*(temp-el)//2
    result -= el*(el-1)*(el-2)//6
print(result)

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



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

initial = ['M', 'A', 'R', 'C', 'H']
combi = []
for i in range(len(initial)):
    for j in range(i + 1, len(initial)):
        for k in range(j + 1, len(initial)):
            combi.append((initial[i], initial[j], initial[k]))

ans = 0
for a, b, c in combi:
    x, y, z = d.get(a), d.get(b), d.get(c)
    ans += x * y * z
print(ans)

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

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

Solution (Python):
import itertools
n = int(input())
d = {}
for i in range(n):
  s = str(input())[0]
  if (s == 'M') or (s == 'A') or (s == 'R') or (s == 'C') or (s == 'H') :
    if s in d:
      d[s] += 1
    else:
      d[s] = 1
if len(d) <= 2:
  print(0)
else:
  d = sorted(d.values())
  ans = 0
  for team in itertools.combinations(d, 3):
    cnt = 1
    for i in team:
      cnt *= i
    ans += cnt
  print(ans)

Solution (Python):
import itertools
n = int(input())
d = {}
for i in range(n):
  s = str(input())[0]
  if (s == 'M') or (s == 'A') or (s == 'R') or (s == 'C') or (s == 'H') :
    if s in d:
      d[s] += 1
    else:
      d[s] = 1
if len(d) <= 2:
  print(0)
else:
  d = sorted(d.values())
  if len(d) == 3:
    ans = 1
    for i in d:
      ans *= i
    print(ans)
  else:
    ans = 0
    for team in itertools.combinations(d, 3):
      cnt = 1
      for i in team:
        cnt *= i
      ans += cnt
    print(ans)

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

Solution (Python):
N = int(input())
S = [[] for i in range(N)]
march = [[] for i in range(5)]
for i in range(N):
    S[i] = input()
for i in range(N):
    if S[i][0] == "M":
        march[0].append(S[i])
    elif S[i][0] == "A":
        march[1].append(S[i])
    elif S[i][0] == "R":
        march[2].append(S[i])
    elif S[i][0] == "C":
        march[3].append(S[i])
    elif S[i][0] == "H":
        march[4].append(S[i])
        
c = [0]*5
for i in range(5):
    c[i] = len(march[i])

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):
import itertools
N = int(input())
S = [0]*5
for i in range(N):
    a = input()
    if a[0] == 'M':
        S[0] += 1
    if a[0] == 'A':
        S[1] += 1
    if a[0] == 'R':
        S[2] += 1
    if a[0] == 'C':
        S[3] += 1
    if a[0] == 'H':
        S[4] += 1
S.sort(reverse=True)
if S[2] == 0:
    print(0)
elif S[3] == 0:
    print(S[0]*S[1]*S[2])
elif S[4] == 0:
    print(S[0]*S[1]*S[2]+S[3]*S[1]*S[2]+S[0]*S[1]*S[3]+S[0]*S[2]*S[3])
else:
    ans = 0
    for x,y,z in itertools.combinations([0,1,2,3,4], 3):
        ans += S[x]*S[y]*S[z]
    print(ans)

Solution (Python):
from itertools import product

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

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

res = 0
for pattern in product([0, 1], repeat=5):
    if sum(pattern) == 3:
        p = 1
        for i, j in enumerate(pattern):
            if j == 1:
                p *= name[i]
        res += p
print(res)

Solution (Python):
import numpy as np
from functools import reduce
from operator import add,sub,mul,truediv
from fractions import gcd
import itertools

n = int(input())


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

x = ['m','a','r','c','h']

cnt = [0,0,0,0,0]
for i in range(n):
    s = str(input())
    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 v in itertools.combinations(cnt,3):
    t = v[0] 
    for i in range(1,3):
        t*=v[i]

    ans+=t

print(ans)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import Counter
import itertools

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

Solution (Python):
from itertools import combinations as c
n = int(input())
S = [input().replace("\n", "")[0] for _ in range(n)]
cnt = [S.count(i) for i in "MARCH"]
print(sum(i*j*k for i, j, k in c(cnt, 3)))

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

cnt =  [i for i in march_l if i != 0]
len_cnt = len(cnt)
ans = 0

if len_cnt > 3:
    for i in range(2**len_cnt):
        tmp = 1
        if str(bin(i)).count('1') == 3:
            for j in range(len_cnt):
                if ((i>>j) & 1):
                    tmp *= cnt[j]
            ans += tmp
elif len_cnt == 3:
    ans = 1
    for i in cnt:
        ans *= i
        
print(ans)

Solution (Python):
from itertools import combinations
def main():
    s = [i[0] for i in open(0).read().split()[1:]]
    c = [s.count(i) for i in "MARCH"]
    a = sum(x*y*z for x, y, z in combinations(c, 3))
    print(a)
main()

Solution (Python):
from itertools import combinations
def main():
    s = [i[0] for i in open(0).read().split()[1:]]
    c = (s.count("M"),s.count("A"),s.count("R"),s.count("C"),s.count("H"))
    a = sum(x*y*z for x, y, z in combinations(c, 3))
    print(a)
main()

Solution (Python):
def main():
    s = [i[0] for i in open(0).read().split()[1:]]
    c = (s.count("M"),s.count("A"),s.count("R"),s.count("C"),s.count("H"))
    a = 0
    for i in range(3):
        for j in range(3-i):
            for k in range(3-i-j):
                a += c[i]*c[i+j+1]*c[i+j+k+2]
    print(a)

main()

Solution (Python):
import sys
_,*s = sys.stdin.read().strip().split("\n")
s = [i[0] for i in s]
c = [s.count("M"),s.count("A"),s.count("R"),s.count("C"),s.count("H")]
a = 0
for i in range(3):
    for j in range(3-i):
        for k in range(3-i-j):
            a += c[i]*c[i+j+1]*c[i+j+k+2]
print(a)

Solution (Python):
from itertools import combinations
n = int(input())
dic = {i:0 for i in 'MARCH'}
for i in range(n):
    s = input()
    if s[0] in ('MARCH'):
        dic[s[0]] += 1
result = 0
for i, j, k in combinations('MARCH', 3):
    result += dic[i]*dic[j]*dic[k]
print(result)

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

e=list()
for i in d:
  if i=="M" or i=="A" or i=="R" or i=="C" or i=="H":
    e.append(d[i])


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

Solution (Python):
import itertools
n=int(input())
s=dict()
for i in ["M","A","R","C","H"]:
    s[i]=0
for i in range(n):
    _s=input()
    if _s[0] in ["M","A","R","C","H"]:
        s[_s[0]]+=1
s=list(s.items())
ans=0
for i in range(5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            ans+=(s[i][1]*s[j][1]*s[k][1])
print(ans)

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

Solution (Python):
import math

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

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


P = [0,0,0,0,0,0,1,1,1,2]
Q = [1,1,1,2,2,3,2,2,3,3]
R = [2,3,4,3,4,4,3,4,4,4]

ans = 0
for i in range(10):
    ans += lst[P[i]]*lst[Q[i]]*lst[R[i]]
print(ans)

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

li=[m,a,r,c,h]
ans=0
for ai in range(5):
  for bi in range(5):
    for ci in range(5):
      if ci>bi>ai:
        ans+=li[ai]*li[bi]*li[ci]
print(ans)

Solution (Python):
N=int(input())
S=[]
for _ in range(N):
    S.append(input())
def cnt(c):
    temp=0
    for val in S:
        if val[0]==c:
            temp+=1
    return temp

lst=['M','A','R','C','H']
march=list(map(cnt, lst))



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

Solution (Python):
from sys import stdin
inp = stdin.readline

N = int(inp().rstrip())
S = [inp().rstrip() for _ in range(N)]

cnt = [0, 0, 0, 0, 0]

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 in range(3):
    for j in range(i + 1, 4):
        for k in range(j + 1, 5):
            ans += cnt[i] * cnt[j] * cnt[k]

print(ans)

Solution (Python):
n=int(input())
cnt=0
from collections import Counter
cc=Counter()
for _ 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':
        cc[s[0]]+=1
l=[]
for i in cc:
    l.append(cc[i])

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

Solution (Python):
def main():
    from collections import Counter as CNT
    from itertools import combinations as COM

    n, *s = open(0).read().split()
    i = [x[0] for x in s]
    d = CNT(i)
    c = [d.get(i) if d.get(i) != None else 0 for i in 'MARCH']
    ans = sum(a * b * c for a, b, c in COM(c, 3))
    print(ans)

    
if __name__ == '__main__':
    main()