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 math

import itertools
from collections import deque
from collections import Counter




n=int(input())
s=[input() for _ in range(n)]
d={"M":0,"A":0,"R":0,"C":0,"H":0}
l=itertools.combinations(["M","A","R","C","H"],3)
for i in range(n):
    if s[i][0] in d:
        d[s[i][0]]+=1
ans=0
for i in l:
    a,b,c=i
    ans+=d[a]*d[b]*d[c]
print(ans)

Solution (Python):



import itertools

n = int(input())
names = []
march = {
    'M': 0,
    'R': 0,
    'A': 0,
    'C': 0,
    'H': 0
}

while True:
    try:
        names.append(input())
    except EOFError:
        break


for name in names:
    try:
        march[name[0]] += 1
    except KeyError:
        continue

patterns = list(itertools.combinations(['M', 'A', 'R', 'C', 'H'], 3))

total = 0
for pattern in patterns:
    total += march[pattern[0]] * march[pattern[1]] * march[pattern[2]]

print(total)

Solution (Python):
member = []
count = 0
name_count = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
N = int(input())
for i in range(N):
    name = input()
    member.append(name)
for i in range(N):
    if member[i][0] in name_count:
        name_count[member[i][0]] += 1
count += name_count['M'] * name_count['A'] * name_count['R']
count += name_count['M'] * name_count['A'] * name_count['C']
count += name_count['M'] * name_count['A'] * name_count['H']
count += name_count['M'] * name_count['R'] * name_count['C']
count += name_count['M'] * name_count['R'] * name_count['H']
count += name_count['M'] * name_count['C'] * name_count['H']
count += name_count['A'] * name_count['C'] * name_count['R']
count += name_count['A'] * name_count['H'] * name_count['R']
count += name_count['A'] * name_count['H'] * name_count['C']
count += name_count['H'] * name_count['C'] * name_count['R']
print(count)

Solution (Python):
import sys
import itertools

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N = in_n()
    S = [0] * 5

    march = ['M', 'A', 'R', 'C', 'H']
    for i in range(N):
        ts = in_s()
        fs = ts[0]
        if fs in march:
            S[march.index(fs)] += 1

    comb = itertools.combinations(range(5), 3)

    ans = 0
    for com in comb:
        t = 1
        for c in com:
            t *= S[c]
        ans += t

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import bisect,copy,heapq,string
from collections import *
from math import *
from itertools import *
import sys
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
s = list(input() for i in range(n))
t = [0]*5

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

c = combinations(range(5),3)
ans = 0   
for x in c:
        ans += t[x[0]] * t[x[1]] * t[x[2]]

print(ans)

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

march = ("M","A","R","C","H")
prefix = []
d = {}
for _ in range(n):
  pre = input()[0]
  if pre in march:
    if pre not in prefix:
      prefix.append(pre)
      d[pre] = 1
    else:
      d[pre] += 1
      
t = len(prefix)
if t < 3:
  print(0)
  exit()

ans = 0
for i in range(t-2):
  for j in range(i+1, t-1):
    for k in range(j+1,t):
      ans += d[prefix[i]]*d[prefix[j]]*d[prefix[k]]
print(ans)

Solution (Python):
from itertools import combinations
N = int(input())
dic = {}
for _ in range(N):
    x = list(input())[0]
    if x in ("M", "A", "R", "C", "H"):
        if x not in dic:
            dic[x] = 1
        else:
            dic[x] += 1
ans = 0
comb = list(combinations(dic.keys(), 3))
for x, y, z in comb:
    ans += dic[x] * dic[y] * dic[z]
print(ans)

Solution (Python):
from itertools import combinations

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

cnt = dict({'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0})
for name in s:
    if name[0] in cnt:
        cnt[name[0]] += 1

ans = 0
for i, j, k in combinations(cnt, 3):
    ans += cnt[i] * cnt[j] * cnt[k]
print(ans)

Solution (Python):
import itertools
n = int(input())
counters = {"M":0,"A":0,"R":0,"C":0,"H":0}

for _ in range(n):
  s = input()[0]
  
  if s in "MARCH":
  	counters[s] += 1
res = 0
for i in list(itertools.combinations(["M","A","R","C","H"],3)):
  res += counters[i[0]] * counters[i[1]] * counters[i[2]]

print(res)

Solution (Python):
N = int(input())
d = [0]*5
for i in range(N):
    st = input()
    if st[0] == 'M': d[0] += 1
    if st[0] == 'A': d[1] += 1
    if st[0] == 'R': d[2] += 1
    if st[0] == 'C': d[3] += 1
    if st[0] == 'H': d[4] += 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 combinations
N = int(input())
name = [0]*5
ans = 0
for i in range(N):
    a = input()
    if a[0] == 'M': name[0] += 1
    elif a[0] == 'A': name[1] += 1
    elif a[0] == 'R': name[2] += 1
    elif a[0] == 'C': name[3] += 1
    elif a[0] == 'H': name[4] += 1
if sum(name) < 3:
    print(0)
else:
    for i in combinations(name, 3):
        ans += i[0]*i[1]*i[2]
    print(ans)

Solution (Python):
N=int(input())
C=[0]*6

for _ in range(N):
    C['MARCH'.find(input()[0])]+=1

from itertools import*
D=list(combinations(C[:5],3))

ans=0
for i,j,k in D:
    ans+=i*j*k

print(ans)

Solution (Python):
import itertools

n = int(input())

C = [0, 1, 2, 3, 4]

march = [0]*5
for i in range(n):
    a = input()
    if a[0] == "M":
        march[0] += 1
    elif a[0] == "A":
        march[1] += 1
    elif a[0] == "R":
        march[2] += 1
    elif a[0] == "C":
        march[3] += 1
    elif a[0] == "H":
        march[4] += 1
 
tst = list(itertools.combinations(C,3))

ans = 0
for i in range(10):
    ans += march[tst[i][0]] * march[tst[i][1]] * march[tst[i][2]]

print(ans)

Solution (Python):
import sys

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    N = ii()
    S = [input() for i in range(N)]
    MARCH = 'MARCH'
    dic = {
        'M': 0,
        'A': 0,
        'R': 0,
        'C': 0,
        'H': 0
    }
    for i in range(N):
        if S[i][0] in dic:
            dic[S[i][0]] += 1

    ans = 0

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

    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())

m = {}

for i in range(N):
    s = input()
    if s[0] not in "MARCH":
        continue

    m[s[0]] = m.get(s[0], 0) + 1

ans = 0
for i in range(5):
    for j in range(i + 1, 5):
        for k in range(j + 1, 5):
            ans += m.get("MARCH"[i], 0) * m.get("MARCH"[j], 0) * m.get("MARCH"[k], 0)

print(ans)

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

n = int(input())
l = [input()[0] for _ in range(n)]
lc = Counter(l)

con = []
for c in 'MARCH':
  if c in lc:
    con.append(lc[c])

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

Solution (Python):
n = int(input())
dic = {}
march = set(['M', 'A', 'R', 'C', 'H'])
for i in range(n):
  s = input()[0]
  if s in march:
    dic.setdefault(s, 0)
    dic[s] += 1
if len(dic) <= 2:
  print(0)
  exit()
march = ['M', 'A', 'R', 'C', 'H']
for t in march:
  dic.setdefault(t, 0)
march = ['MAR', 'MAC', 'MAH', 'MRC', 'MRH', 'MCH', 'ARC', 'ARH', 'ACH', 'RCH']
res = 0
for t in march:
  res += (dic[t[0]] * dic[t[1]] * dic[t[2]])
print(res)

Solution (Python):
import itertools
import collections
N = int(input())
S = [input() for i in range(N)]
candi = []
for s in S:
    if s[0] == 'M' or s[0] == 'A' or s[0] == 'R' or s[0] == 'C' or s[0] == 'H':
        candi.append(s[0])
col_s = collections.Counter(candi)
combi_s = itertools.combinations(list(col_s),3)
counter = 0 
for i in combi_s:
    counter += col_s[i[0]]*col_s[i[1]]*col_s[i[2]]
print(counter)

Solution (Python):
import sys
import itertools

import time
import math
import heapq
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines




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

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

Solution (Python):
from itertools import combinations

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

comb = combinations(["M", "A", "R", "C", "H"], 3)


ans = 0
for c in comb:  
    ans += cnt[c[0]] * cnt[c[1]] * cnt[c[2]]

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())
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):
D={'M':0,'A':0,'R':0,'C':0,'H':0}
for k in range(int(input())):
  s=input()
  if s[0] in D.keys():
    D[s[0]]+=1

t,v=0,list(D.values())
for i in range(5):
  for j in range(i+1,5):
    for k in range(j+1,5):
      t+=v[i]*v[j]*v[k]

print(t)

Solution (Python):





import math
import fractions
import sys
import bisect
import heapq  
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr



def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod



def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


inf = 10 ** 18
mod = 10 ** 9 + 7

n = ir()
s = [input()[0] for i in range(n)]
dic = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
for c in s:
    if c in dic:
        dic[c]+=1
ans = 0
judge = [dic[c] for c in dic.keys()]
for tmp in itertools.combinations(judge, 3):
    ans += tmp[0]*tmp[1]*tmp[2]
print(ans)

Solution (Python):
from collections import defaultdict
from itertools import combinations
N = int(input())
dic = defaultdict(list)
for _ in range(N):
    s = input()
    if s[0] in "MARCH":
        dic[s[0]].append(s)

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

Solution (Python):
n = int(input())
march =[]

for i in range(n):
    a = input()
    ai = a[0]
    march.append(ai)

import collections
c = collections.Counter(march)

mm = c["M"]
aa = c["A"]
rr = c["R"]
cc = c["C"]
hh = c["H"]

import itertools
seq = [mm,aa,rr,cc,hh]
mmm = list(itertools.combinations(seq,3))

res= 0
for i in range(10):
    aaa = mmm[i]
    res += aaa[0]*aaa[1]*aaa[2]

print(res)

Solution (Python):
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7
import numpy as np

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result
N = i()
S = [s() for _ in range(N)]
m = 0
a = 0
r = 0
c = 0
h = 0
for i in range(N):
    if S[i][0] == 'M':
        m += 1
    elif S[i][0] == 'A':
        a += 1
    elif S[i][0] == 'R':
        r += 1
    elif S[i][0] == 'C':
        c += 1
    elif S[i][0] == 'H':
        h += 1
cmbs = [m,a,r,c,h]
cmbs = itertools.combinations(cmbs,3)
ans = 0
for c in cmbs:
    ans += np.prod(list(c))
print(ans)

Solution (Python):
N=int(input())
cnt={"M":0, "A":0, "R":0, "C":0, "H":0}
for _ in range(N):
    s=input()
    if s[0]=="M":
        cnt["M"]+=1
    elif s[0]=="A":
        cnt["A"]+=1
    elif s[0]=="R":
        cnt["R"]+=1
    elif s[0]=="C":
        cnt["C"]+=1
    elif s[0]=="H":
        cnt["H"]+=1

from itertools import combinations
comb=combinations(["M", "A", "R", "C", "H"], 3)

ans=0
for c in comb:
    ans+=cnt[c[0]]*cnt[c[1]]*cnt[c[2]]

print(ans)

Solution (Python):
n=int(input())
import collections
import itertools
l=['M','A','R','C','H']
x=[]
for i in range(n):
  s=input()
  if s[0] in l:
    x.append(s[0])
c=collections.Counter(x)
ans=0
for p in itertools.combinations('MARCH',3):
  cnt=1
  for j in range(3):
    cnt*=c[p[j]]
  ans+=cnt
print(ans)

Solution (Python):
import itertools

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

cnt = [0]*5
for i in range(n):
    if s[i][0]== 'M':
      cnt[0] += 1
    elif s[i][0]== 'A':
      cnt[1] += 1
    elif s[i][0]== 'R':
      cnt[2] += 1
    elif s[i][0]== 'C':
      cnt[3] += 1
    elif s[i][0]== 'H':
      cnt[4] += 1
cnt.sort()

p = 0
if cnt[2] == 0:
    p = 0
elif cnt[1] == 0:
    p = cnt[2]*cnt[3]*cnt[4]
elif cnt[0] == 0:
    p += cnt[1]*cnt[2]*cnt[3]
    p += cnt[1]*cnt[2]*cnt[4]
    p += cnt[1]*cnt[3]*cnt[4]
    p += cnt[2]*cnt[3]*cnt[4]
else:
    num = [0,1,2,3,4]
    combi = list(itertools.combinations(num,3))
    
    for i in range(len(combi)):
        a,b,c = combi[i][0], combi[i][1], combi[i][2]
        p += cnt[a]*cnt[b]*cnt[c]
print(p)

Solution (Python):


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

for c in s:
    if c[0] not in d:
        d[c[0]] = 1 
    else:
        d[c[0]] += 1

tmp = d.copy()
t = ['M', 'A', 'R', 'C', 'H']
for c in tmp:
    if c not in t:
        d.pop(c)

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

Solution (Python):


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

c = [0 for _ in range(5)]
t = 'MARCH'

for i in range(n):
    for j in range(5):
        if s[i][0] == t[j]:
            c[j] += 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[k]*c[j]
print(ans)

Solution (Python):
from itertools import combinations


n = int(input())

s = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
for i in range(n):
    a = input()
    if a[0] in s.keys():
        s[a[0]] += 1

c = list(combinations(s.keys(), 3))
ans = 0
for i in c:
    ans += s[i[0]] * s[i[1]] * s[i[2]]

print(ans)

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

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

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

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

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

ans = 0
for i, j, k in comb(["M","A","R","C","H"], 3):
    ans += d[i]*d[j]*d[k]
print(ans)

Solution (Python):
import itertools
n=int(input())
s=[input()for i in range(n)]
m,a,r,c,h=0,0,0,0,0
for i in s:
 if i[0]=="M":m+=1
 if i[0]=="A":a+=1
 if i[0]=="R":r+=1
 if i[0]=="C":c+=1
 if i[0]=="H":h+=1
l=[m,a,r,c,h]
ans=0
for i in itertools.combinations(l,3):ans+=i[0]*i[1]*i[2]
print(ans)

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

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

march=[d["M"],d["A"],d["R"],d["C"],d["H"]]
zero=march.count(0)
if zero>=3:
    ans=0
    print(ans)
    sys.exit()

m=[]
for i in march:
    if i>0:
        m.append(i)

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

print(ans)

Solution (Python):
from itertools import combinations
n=int(input())
name=[0]*5
march=['M','A','R','C','H']
for i in range(n):
  s=input()
  if s[0] in march:
    name[march.index(s[0])]+=1
sm=0
for i,j,k in list(combinations(name,3)):
  sm+=i*j*k
print(sm)

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

for i in range(n):
  s = input()
  d[s[0]] = d.get(s[0], 0) + 1

x = 0
x += d["M"] * d["A"] * d["R"]
x += d["M"] * d["A"] * d["C"]
x += d["M"] * d["A"] * d["H"]
x += d["M"] * d["R"] * d["C"]
x += d["M"] * d["R"] * d["H"]
x += d["M"] * d["C"] * d["H"]
x += d["A"] * d["R"] * d["C"]
x += d["A"] * d["R"] * d["H"]
x += d["A"] * d["C"] * d["H"]
x += d["R"] * d["C"] * d["H"]
print(x)

Solution (Python):
import numpy,itertools
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
c = [0] * 5
for _ in range(n):
    s = readline().decode().rstrip()
    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

cm = list(itertools.combinations(c, 3))
arr = numpy.array(cm)

print(sum(list(numpy.prod(arr, axis=1))))

Solution (Python):

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]

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

ans = 0
for i in range(10):
    ans += name[p[i]] * name[q[i]] * name[r[i]]

print(ans)

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


def log(*args):
    print(*args, file=sys.stderr)


def main():
    n = int(input().rstrip())
    s = [input()[0] for _ in range(n)]
    c = Counter(s)
    ans = 0
    for x, y, z in combinations('MARCH', 3):
        ans += c[x] * c[y] * c[z]
    print(ans)


if __name__ == '__main__':
    main()

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


def log(*args):
    print(*args, file=sys.stderr)


def main():
    n = int(input().rstrip())
    s = [input()[0] for _ in range(n)]
    s = [v for v in s if v in 'MARCH']
    c = Counter(s)
    ans = 0
    for x, y, z in combinations(c, 3):
        ans += c[x] * c[y] * c[z]
    print(ans)


if __name__ == '__main__':
    main()

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


def log(*args):
    print(*args, file=sys.stderr)


def main():
    n = int(input().rstrip())
    m = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
    for _ in range(n):
        s = input().rstrip()
        if s[0] in m:
            m[s[0]] += 1
    ans = 0
    for c in combinations(m, 3):
        ans += m[c[0]] * m[c[1]] * m[c[2]]
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from collections import defaultdict
import itertools
d = defaultdict(int)
x='MARCH'
for i in range(5):
  d[x[i]]=i+1
x=[0]*5
N=int(input())
for i in range(N):
  S=input()
  a=d[S[0]]
  if a>0:
    x[a-1]+=1
ans=0
for i,j,k in itertools.combinations([i for i in range(5)], 3):
  ans+=x[i]*x[j]*x[k]
print(ans)

Solution (Python):
import itertools
N = int(input())
S = [input() for _ in range(N)]
d = {'M':[], 'A':[], 'R':[], 'C':[], 'H':[]}

for s in S:
    for c in ['M', 'A', 'R', 'C', 'H']:
        if s.startswith(c):
            d[c] += [s]

num = {k: len(d[k]) for k in ['M', 'A', 'R', 'C', 'H']}

ans = 0
for v in itertools.combinations(['M', 'A', 'R', 'C', 'H'], 3):
    tmp = 1
    for c in v:
        tmp *= num[c]
    ans += tmp
print(ans)

Solution (Python):
n = int(input())
m = []
apple = []
r = []
cat = []
h = []

for _ in range(n):
    s = str(input())
    if s[0]=="M":
        m.append(s)
    elif s[0]=="A":
        apple.append(s)
    elif s[0]=="R":
        r.append(s)
    elif s[0]=="C":
        cat.append(s)
    elif s[0]=="H":
        h.append(s)
    else:
        pass
a = len(m)
b = len(apple)
c = len(r)
d = len(cat)
e = len(h)
print(a*b*c + a*b*d + a*b*e + b*c*d + b*c*e + c*d*e + a*c*d + a*c*e + a*d*e + b*d*e)

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

Solution (Python):
from itertools import combinations
from collections import Counter
n = int(input())
C = Counter()
for i in range(n):
    C[input()[0]] +=1


print(sum(C[a]*C[b]*C[c] for a,b,c in combinations('MARCH',3)
))

Solution (Python):
from itertools import combinations
from collections import Counter
n = int(input())
C = Counter()
for i in range(n):
    C[input()[0]] +=1

print(sum(C[a]*C[b]*C[c] for a,b,c in combinations('MARCH',3)
))

Solution (Python):

import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))



def read_a_int(): return int(read())


MOD = 10**9 + 7
INF = 2**31  

from collections import defaultdict, Counter, deque
from itertools import product, permutations, combinations

N = read_a_int()
cnt = defaultdict(lambda: 0)
march = {'M', 'A', 'R', 'C', 'H'}
for _ in range(N):
    s = read()[0]
    if s in march:
        cnt[s] += 1
ans = 0
for a, b, c in combinations(cnt.values(), r=3):
    ans += a * b * c
print(ans)

Solution (Python):
from itertools import combinations

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

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

Solution (Python):
import itertools
n = int(input())
sl = []

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

lst = []
for com in itertools.combinations(dic.keys(),3):
    lst.append(com)

ans = 0
for v in lst:
    ans += dic[v[0]] * dic[v[1]] * dic[v[2]]
print(ans)

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

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

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

Solution (Python):
from collections import Counter
import itertools

n = int(input())

s = [str(input()) for _ in range(n)]
initial = []
d = ['M', 'A', 'R', 'C', 'H']

for i in range(n):
    if s[i][0] in d:
        initial.append(s[i][0])

reg = Counter(initial)
ele = []

for i, j in reg.items():
    ele.append(i)
ans = 0
for A in itertools.combinations(ele, 3):
    
    cnt = 1
    for s in A:
        cnt *= reg[s]
    ans += cnt

print(ans)

Solution (Python):
import itertools

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

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

print(ans)

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

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

    p = tuple(combinations(['M', 'A', 'R', 'C', 'H'], 3))
    r = 0
    for pe in p:
        t = march[pe[0]] * march[pe[1]] * march[pe[2]]
        r += t
    print(r)

if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
M=A=R=C=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
a=[M,A,R,C,H]
from itertools import combinations
ans=0
for L in list(combinations(a,3)):
    ans+=L[0]*L[1]*L[2]
print(ans)

Solution (Python):
import sys
from collections import defaultdict
import itertools
n = int(input())
dic = defaultdict(lambda : 0)
for _ in range(n):
    s = input()
    if s[0] in 'MARCH':
        dic[s[0]] += 1
if len(dic) <= 2:
    print(0)
    sys.exit()
if len(dic) == 3:
    ans = 1
    for val in dic.values():
        ans *= val
    print(ans)
    sys.exit()

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

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

Solution (Python):
from collections import defaultdict

def main():
    N = int(input())
    MARCH = ['M','A','R','C','H']
    S = [0] * len(MARCH)
    for _ in range(N):
        s = input()
        if not s[0] in MARCH:
            continue
        if s[0] == MARCH[0]: S[0] += 1
        elif s[0] == MARCH[1]: S[1] += 1
        elif s[0] == MARCH[2]: S[2] += 1
        elif s[0] == MARCH[3]: S[3] += 1
        elif s[0] == MARCH[4]: S[4] += 1
    cnt = 0
    for i in range(len(S)-2):
        for j in range(i+1,len(S)-1):
            for k in range(j+1,len(S)):
                cnt += S[i]*S[j]*S[k]
    print(cnt)

if __name__ == '__main__':
    main()

Solution (Python):
import itertools
n = int(input())
Dict = {'M':0,'A':1,'R':2,'C':3,'H':4}

List = [[]for i in range(5)]
for i in range(n):
    tmp = input()
    if tmp[0] in Dict:
        index = Dict[tmp[0]]
        List[index].append(tmp)
List_num = [len(List[i]) for i in range(5)]
ans = 0
for v in itertools.combinations(List_num,3):
    cnt = 1
    for youso in v:
        cnt*=youso
    ans += cnt
print(ans)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
N = int(input())
initials = [0]*5
lis = ['M', 'A', 'R', 'C', 'H']
SET = set(lis)
for _ in range(N):
    s = input()[0]
    if not s in SET:
        continue
    idx = lis.index(s)
    initials[idx] += 1

ans = 0
from itertools import permutations
for a, b, c in permutations(initials, 3):
    ans += a*b*c

print(ans//6)