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



Sample input:
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI


Sample output:
2

Submission status: Accepted

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

key = "MARCH"
C = [0] * 5

for i in range(len(S)):
  for j in range(5):
    if S[i][0] == key[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[j] * C[k]

print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import Counter
from itertools import combinations
n = int(sys.stdin.readline().strip())
s_ls = []
cnt = Counter()
for i in range(n):
    s = sys.stdin.readline().strip()
    cnt.update(s[0])
_sum = 0
for combi in combinations("MARCH", 3):
    score = 1
    for c in combi:
        score *= cnt[c]
    _sum += score
print(_sum)

Submission status: Accepted

Solution code:
n = int(input())
a = b = c = d = e = 0
for _ in range(n):
    s = input()
    if s[0] == 'M':
        a += 1
    elif s[0] == 'A':
        b += 1
    elif s[0] == 'R':
        c += 1
    elif s[0] == 'C':
        d += 1
    elif s[0] == 'H':
        e += 1
print(a * b * c + a * b * d + a * b * e + a * c * d + a * c * e + a * d * e +
      b * c * d + b * c * e + b * d * e + c * d * e)

Submission status: Accepted

Solution code:
from collections import defaultdict
from itertools import combinations
N = int(input())
S = defaultdict(set)
march = 'MARCH'
for i in range(N):
    a = input()
    for j in range(5):
        if a[0] == march[j]:
            S[j].add(a)
sv = []
for i in S.values():
    sv.append(len(i))
if len(sv) < 3:
    print(0)
else:
    ans = 0
    for a,b,c in combinations(sv,3):
        ans += a*b*c
    print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
N = int(input())
S = defaultdict(set)
march = 'MARCH'
for i in range(N):
    a = input()
    for j in range(5):
        if a[0] == march[j]:
            S[j].add(a)
sv = []
for i in S.values():
    sv.append(len(i))
if len(sv) < 3:
    print(0)
else:
    ans = 0
    for i in range(len(sv)-2):
        for j in range(i+1,len(sv)-1):
            for k in range(j+1,len(sv)):
                ans += sv[i]*sv[j]*sv[k]
    print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
N = int(input())
S = defaultdict(set)
for i in range(N):
    a = input()
    if a[0] ==  'M':
        S[0].add(a)
    if a[0] == 'A':
        S[1].add(a)
    if a[0] == 'R':
        S[2].add(a)
    if a[0] == 'C':
        S[3].add(a)
    if a[0] == 'H':
        S[4].add(a)
d = 1
count = 0
sv = []
for i in S.values():
    sv.append(len(i))
if len(sv) < 3:
    print(0)
else:
    ans = 0
    for i in range(len(sv)-2):
        for j in range(i+1,len(sv)-1):
            for k in range(j+1,len(sv)):
                ans += sv[i]*sv[j]*sv[k]
    print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
from itertools import combinations
N = int(input())
d = defaultdict(int)
strlist = ["M","A","R","C","H"]
for i in range(N):
    S = input()
    for s in strlist:
        if S[0] == s:
            d[s] += 1
combs = list(combinations(strlist,3))
ans = 0
for s1,s2,s3 in combs:
    ans += d[s1] * d[s2] * d[s3]
print(ans)

Submission status: Accepted

Solution code:
import itertools
n = int(input())
S = "MARCH"
d = {s:0 for s in S}
ans = 0
for i in range(n):
  f = input()[0]
  if f in S:
    d[f] += 1
for x,y,z in itertools.combinations(d.keys(),3):
  ans += d[x] * d[y] * d[z]
print(ans)

Submission status: Accepted

Solution code:
import itertools
n = int(input())
S = [input() for _ in range(n)]
M,A,R,C,H = 0,0,0,0,0
ans = 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
U = [M,A,R,C,H]
for x,y,z in itertools.combinations(U,3):
  ans += x * y * z
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
m, a, r, c, h = [0, 0, 0, 0, 0]
for _ in range(N):
    s = input()
    if s[0] == "M":
        m += 1
    elif s[0] == "A":
        a += 1
    elif s[0] == "R":
        r += 1
    elif s[0] == "C":
        c += 1
    elif s[0] == "H":
        h += 1
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)

Submission status: Accepted

Solution code:
from itertools import  combinations as c
n=int(input())
l=[0]*5
for i in range(n):
  s=input()
  s=s[0]
  if s in "MARCH":
    l["MARCH".index(s)]+=1
ans=0
for x,c,v in c(range(5),3):
  ans+=l[x]*l[c]*l[v]
print(ans)

Submission status: Accepted

Solution code:
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
  if S[0]=='A':
    a+=1
  if S[0]=='R':
    r+=1
  if S[0]=='C':
    c+=1
  if S[0]=='H':
    h+=1
    
nums=[m, a, r, c, h]

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

n = int(input())
from collections import defaultdict
d = defaultdict(int)

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

march = []
for k,v in d.items():
    if k in ["M","A","R","C","H"]:
        march.append(v)

#iter_tools
#組み合わせ(重複なし)
from itertools import combinations
from operator import mul
ret = 0
if len(march) <= 2:
    print(0)
else:
    ret = 0
    for i in combinations(march,3):
        mul_of_i = 1
        for j in i:
            mul_of_i *= j
        ret += mul_of_i
    print(ret)

Submission status: Accepted

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

march='MARCH'
h = []
for x in s:
  if x[0] in march:
    h.append(x[0])

d = {}
for c in march:
  d[c]=0

for x in h:
  d[x] += 1

ans=0
import itertools
for com in itertools.combinations(d.values(), r=3):
  pro=1
  for x in com:
    pro *= x
  ans+=pro

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
D={}
for i in range(n):
      s=input()[0]
      if s in D:
            D[s]+=1
      else:
            D[s]=1
L=[]
for p in "MARCH":
      if p in D:
            L.append(D[p])
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 +=L[i]*L[j]*L[k]
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
n = int(input())
dic = defaultdict(int)
for i in range(n):
    dic[input()[0]] += 1
L = []
for s in "MARCH":
    if s in dic:
        L.append(dic[s])

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

Submission status: Accepted

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

f = [a for a in s if a.startswith('M')]
g = [b for b in s if b.startswith('A')]
h = [c for c in s if c.startswith('R')]
i = [d for d in s if d.startswith('C')]
j = [e for e in s if e.startswith('H')]

k = len(f)*len(g)*len(h)
l = len(f)*len(g)*len(i)
m = len(f)*len(g)*len(j)
n = len(f)*len(h)*len(i)
o = len(f)*len(h)*len(j)
p = len(f)*len(i)*len(j)
q = len(g)*len(h)*len(i)
r = len(g)*len(h)*len(j)
s = len(g)*len(i)*len(j)
t = len(h)*len(i)*len(j)

sum = k+l+m+n+o+p+q+r+s+t
print(sum)

Submission status: Accepted

Solution code:
import itertools

A = "MARCH"
c = {a: 0 for a in A}
N = int(input())
for _ in range(N):
    S = input()
    if S[0] in A:
        c[S[0]] += 1

print(sum([c[cb[0]] * c[cb[1]] * c[cb[2]]
           for cb in itertools.combinations(A, 3)]))

Submission status: Accepted

Solution code:
n=int(input())
A=["M","A","R","C","H"]
B=[0,0,0,0,0]
s=[]
for i in range(n):
    S=input()
    if S[0] in A:
        s.append(S)
#print(s)
for i in s:
    for j in range(5):
        if A[j]==i[0]:
            B[j]+=1
            break
c=B.count(0)
if c>2:
    print(0)
else:
    c=0
    for i in range(3):
        for j in range(i+1,4):
            for k in range(j+1,5):
                c+=(B[i]*B[j]*B[k])
    print(c)
#print(B)

Submission status: Accepted

Solution code:
import itertools
'''
　 ∧_,,∧    究極奥義「WAがACになーれ！！」
　（`・ω・)つ━☆・*。
　⊂　　 ノ 　　　・゜+.
　 し’´Ｊ　　*・ 
'''
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 itertools.combinations(range(5),3):
    ans+=cnt[i[0]]*cnt[i[1]]*cnt[i[2]]
print(ans)

Submission status: Accepted

Solution code:
import itertools
'''
　 ∧_,,∧    究極奥義「WAがACになーれ！！」
　（`・ω・)つ━☆・*。
　⊂　　 ノ 　　　・゜+.
　 し’´Ｊ　　*・ 
'''
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 itertools.combinations(range(5),3):
    ans+=cnt[i[0]]*cnt[i[1]]*cnt[i[2]]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = [0]*6
for i in range(n):
    s=input()
    if   s[:1] == "M":j=0
    elif s[:1] == "A":j=1
    elif s[:1] == "R":j=2
    elif s[:1] == "C":j=3
    elif s[:1] == "H":j=4
    else:j=5
    
    a[j]+=1
#print(a)
ans=0
for i in range(5):
    for j in range(5):
        for k in range(5):
            if j == k or i ==k or j==i : f=0
            else:
              f=1
              #z=a[i]* a[j] * a[k] * f
              #if z > 0:print(i,j,k,z)
            ans += a[i]* a[j] * a[k] * f

print(ans//6)

Submission status: Accepted

Solution code:
n = int(input())
s = [input() for _ in range(n)]
prefix = ['M', 'A', 'R', 'C', 'H']
cnt = [0] * 5
ans = 0
for i in range(n):
    for j in range(5):
        if s[i][0] == prefix[j]:
            cnt[j] += 1
for i in range(2 ** 5):
    flag = [False] * 5
    for j in range(5):
        if (i >> j) & 1:
            flag[j] = True
    if flag.count(True) == 3:
        tmp = 1
        for k in range(5):
            if flag[k]:
                tmp *= cnt[k]
        ans += tmp
print(ans)

Submission status: Accepted

Solution code:
import sys
from itertools import combinations as comb
n, *S = open(0).read().split()
s = [i[0] for i in S]
c = [s.count(i) for i in 'MARCH']
ret = sum(x * y * z for x, y, z in comb(c, 3))
print(ret)

Submission status: Accepted

Solution code:
n = int(input())
lst = [0] * 5
march = ['M', 'A', 'R', 'C', 'H']
for i in range(n):
  nf = input()[0]
  if nf in march:
    lst[march.index(nf)] += 1
ret = 0
for a in range(0, 3):
  for b in range(a + 1, 4):
    for c in range(b + 1, 5):
      ret += lst[a] * lst[b] * lst[c]
print(ret)

Submission status: Accepted

Solution code:
from itertools import combinations
n=int(input())
march=[0,0,0,0,0]
for i in range(n):
  k=input()
  if k[0]=="M":
    march[0]+=1
  if k[0]=="A":
    march[1]+=1
  if k[0]=="R":
    march[2]+=1
  if k[0]=="C":
    march[3]+=1
  if k[0]=="H":
    march[4]+=1
ans=0
for (i,j,k) in combinations(march,3):
  ans+=i*j*k
print(ans)

Submission status: Accepted

Solution code:
import sys
from operator import mul
from functools import reduce

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

MARCH = 'MARCH'
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()
S = [input().rstrip() for _ in range(N)]

S = [s for s in S if s[0] in MARCH]

A = [0]*5
for s in S:
	A[MARCH.index(s[0])] += 1

#print(A)

if sum(A) < 3:
	print(0)
	sys.exit()

ans = cmb(sum(A), 3)
#print(ans)

for a in A:
	if a<=1:continue
	if a>=3:
		ans -= cmb(a, 3)
	ans -= cmb(a, 2) * (sum(A)-a)

print(ans)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
import itertools
N = int(input())
dic = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
for i in range(N):
  s = input()
  if s[0] in dic:
    dic[s[0]] += 1
lst = list(dic.values())
ans = list(itertools.combinations(lst, 3))
cnt = 0
for i in ans:
    if 0 in ans:
        break
    else:
        cnt += i[0]*i[1]*i[2]

print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
l = [0]*5
l1 = [[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]]
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(len(l1)):
  ans += l[l1[i][0]]*l[l1[i][1]]*l[l1[i][2]]
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=[input() for i in range(n)]
m,a,r,c,h=0,0,0,0,0
for i in range(len(s)):
    x=s[i][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
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)

Submission status: Accepted

Solution code:
n = int(input())
s = [input()[0] for _ in range(n)]

cnt = [s.count(v) for v in ("M", "A", "R", "C", "H")]
ans = 0
for i in range(5):
    for j in range(i):
        for k in range(j):
            ans += cnt[i] * cnt[j] * cnt[k]
            
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
names = [0] * 5
pattern = []

def make_pattern(arr, cnt):
    if len(arr) == 5:
        if cnt == 3 :
            pattern.append(arr)
        return
    make_pattern(arr + '1', cnt + 1)
    make_pattern(arr + '0', cnt)

for _ in range(N):
    name = input()
    initial = name[0]
    if 'M' == initial:
        names[0] += 1
    elif 'A' == initial:
        names[1] += 1
    elif 'R' == initial:
        names[2] += 1
    elif 'C' == initial:
        names[3] += 1
    elif 'H' == initial:
        names[4] += 1
    else:
        continue

make_pattern('', 0)

ans = 0
for p in pattern:
    ret = 1
    for i in range(5):
        if p[i] == '1':
            ret *= names[i]
    ans += ret
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

s = [0, 0, 0, 0, 0]    
for i 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
        
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
import itertools

n = int(input())
S = []
for _ in range(n):
    S.append(str(input()))

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

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

ans = 0

for first_cmb in itertools.combinations(First, 3):
    temp = 1
    for i in first_cmb:
        if i == 'M':
            temp = temp*len(M)
        elif i == 'A':
            temp = temp*len(A)
        elif i == 'R':
            temp = temp*len(R)
        elif i == 'C':
            temp = temp*len(C)
        elif i == 'H':
            temp = temp*len(H)
        
    ans += temp


print(ans)

Submission status: Accepted

Solution code:
# ABC089b
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n = int(input())
d = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
for _ in range(n):
    s = input()[:-1]
    if not s[0] in d.keys():
        continue
    d[s[0]] += 1

ans = 0
l = list(d.values())
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)

Submission status: Accepted

Solution code:
N = int(input())
NameList = []
CharCnt = [0] * 5
CharList = ["M","A","R","C","H"]
for _ in range(N):
    S = input()
    for i in range(5):
        if S[0] == CharList[i]:
            CharCnt[i] += 1
ans = 0
#print(CharCnt)
for i in range(3):
    for j in range(i + 1, 4):
        for k in range(j + 1, 5):
            tmp_ans = CharCnt[i] * CharCnt[j] * CharCnt[k]
            if tmp_ans != 0:
                ans += tmp_ans
if sum(CharCnt) < 3:
    print("0")
else:
    print(ans)

Submission status: Accepted

Solution code:
num = int(input())

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

P1 = [0 ,0 ,0 ,0 ,0 ,0 ,1 ,1 ,1 ,2]
P2 = [1 ,1 ,1 ,2 ,2 ,3 ,2 ,2 ,3 ,3]
P3 = [2 ,3 ,4 ,3 ,4 ,4 ,3 ,4 ,4 ,4]


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

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

sum = 0
for d in range(10):
    sum += D[P1[d]] * D[P2[d]] * D[P3[d]]

print(sum)

Submission status: Accepted

Solution code:
N = int(input())
S = [input() for i in range(N)]
# M A R C H
num = [0] * 5
for s in S:
    if s[0] == "M":
        num[0] += 1
    elif s[0] == "A":
        num[1] += 1
    elif s[0] == "R":
        num[2] += 1
    elif s[0] == "C":
        num[3] += 1
    elif s[0] == "H":
        num[4] += 1
non_zero = []
for n in num:
    if n != 0:
        non_zero.append(n)
if len(non_zero) < 3:
    print(0)
    exit()
ans = 0
for i in range(len(non_zero)):
    for j in range(i + 1, len(non_zero)):
        for k in range(j+1, len(non_zero)):
            ans += non_zero[i] * non_zero[j] * non_zero[k]
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
dic={"M":0,"A":1,"R":2,"C":3,"H":4}
S=[0,0,0,0,0]

for i in range(N):
    si=str(input())
    if si[0] in dic:
        S[dic[si[0]]]+=1
result=S[0]*S[1]*S[2]+S[0]*S[1]*S[3]+S[0]*S[1]*S[4]+S[0]*S[2]*S[3]+S[0]*S[2]*S[4]+S[0]*S[3]*S[4]+\
    S[1]*S[2]*S[3]+S[1]*S[2]*S[4]+S[1]*S[3]*S[4]+S[2]*S[3]*S[4]

print(result)

Submission status: Accepted

Solution code:
N = int(input())
S = [input() for i in range(N)]
MARCH = ['M', 'A', 'R', 'C', 'H']
p = {i:0 for i in MARCH}

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

from itertools import combinations
ans = 0
for t in combinations(MARCH, 3):
    ans += p[t[0]] * p[t[1]] * p[t[2]]

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
cntM, cntA, cntR, cntC, cntH = 0, 0, 0, 0, 0
for i in range(N):
    s = input()
    if s[0] == "M":
        cntM += 1
    elif s[0] == "A":
        cntA += 1
    elif s[0] == "R":
        cntR += 1
    elif s[0] == "C":
        cntC += 1
    elif s[0] == "H":
        cntH += 1
Names = [cntM,cntA,cntR,cntC,cntH]
ans = 0
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            if k <= 4:
                ans += Names[i]*Names[j]*Names[k]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

for i in range(N):
    s = input()
    if s[0] in 'MARCH':
        d[s[0]]+=1

v = list(d.values())
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
d = {'M':0,'A':0,'R':0,'C':0,'H':0}
for i in range(N):
    s = input()
    if s[0] in 'MARCH':
        d[s[0]] += 1
v = list(d.values())
ans = 0
for i in range(5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            ans += v[i]*v[j]*v[k]
print(ans)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
from collections import defaultdict
from itertools import combinations

D = defaultdict(list)
N = int(input())
for i in range(N):
    s = input().strip()
    if s[0] in 'MARCH':
        D[s[0]].append(s)

if len(D.keys()) < 3:
    print(0)
    exit()

C = combinations(list(D.keys()), 3)

ans = 0
for c in C:
    ans += len(D[c[0]]) * len(D[c[1]]) * len(D[c[2]])

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
from itertools import combinations

D = defaultdict(list)
N = int(input())
for i in range(N):
    s = input().strip()
    if s[0] in ('M', 'A', 'R', 'C', 'H'):
        D[s[0]].append(s)

if len(D.keys()) < 3:
    print(0)
    exit()

C = combinations(list(D.keys()), 3)

ans = 0
for c in C:
    ans += len(D[c[0]]) * len(D[c[1]]) * len(D[c[2]])

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = [list(input())[0] for i in range(N)]

A=[]
A.append(S.count("M"))
A.append(S.count("A"))
A.append(S.count("R"))
A.append(S.count("C"))
A.append(S.count("H"))
ans=0

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

Submission status: Accepted

Solution code:
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)
args = sys.argv


def dump_impl(*objects):
    print(*objects, file=sys.stderr)


def dump_dummy(*objects):
    pass


dump = dump_impl if len(args) == 2 and args[1] == "DEBUG" else dump_dummy
N = int(input())
S = [input() for i in range(N)]

D = {'M': [], 'A': [], 'R': [], 'C': [], 'H': []}
for Si in S:
    if Si[0] in D:
        D[Si[0]].append(Si)

dump(D)

ans = 0
for x in it.combinations("MARCH", 3):
    x0, x1, x2 = x
    dump(x0, x1, x2)
    ans += len(D[x0])*len(D[x1])*len(D[x2])
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
from itertools import combinations

n = int(input())

mydict = defaultdict(lambda: 0)
s = []
for i in range(n):
	s.append(input())


for word in s:
	mydict[word[0]] += 1

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

total = 0
for way in ways:
	temp = mydict[way[0]]*mydict[way[1]]*mydict[way[2]]
	#print(way, temp)
	total += temp

print(total)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

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

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

count = defaultdict(int)

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

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

Submission status: Accepted

Solution code:
n = int(input())
m = 0
a = 0
r = 0
c = 0
h = 0
for i in range(n):
  name = input()
  if name[0]=='M':
    m+=1
  elif name[0]=='A':
    a+=1
  elif name[0]=='R':
    r+=1
  elif name[0]=='C':
    c+=1
  elif name[0]=='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)

Submission status: Accepted

Solution code:
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)
args = sys.argv


def dump_impl(*objects):
    print(*objects, file=sys.stderr)
def dump_dummy(*objects):
    print(*objects, file=sys.stderr)
    
dump = dump_impl if len(args) == 2 and args[1] == "DEBUG" else dump_dummy

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

D={'M':[],'A':[],'R':[],'C':[],'H':[]}
for Si in S:
    if Si[0] in D:
        D[Si[0]].append(Si)

dump(D)

ans=0
for x in it.combinations("MARCH", 3):
    x0,x1,x2=x
    dump(x0,x1,x2)
    ans += len(D[x0])*len(D[x1])*len(D[x2])
print(ans)

Submission status: Accepted

Solution code:
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)
args = sys.argv


def dump(*objects):
    if len(args) == 2 and args[1] == "DEBUG":
        print(*objects, file=sys.stderr)

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

D={'M':[],'A':[],'R':[],'C':[],'H':[]}
for Si in S:
    if Si[0] in D:
        D[Si[0]].append(Si)

dump(D)

ans=0
for x in it.combinations("MARCH", 3):
    x0,x1,x2=x
    dump(x0,x1,x2)
    ans += len(D[x0])*len(D[x1])*len(D[x2])
print(ans)

Submission status: Accepted

Solution code:
import itertools
import numpy as np

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

seq = ('m', 'a', 'r', 'c', 'h')

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

for i in Names:
    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
        
Seq=[M,A,R,C,H]
Combi=list(itertools.combinations(Seq,3)) #3つ選ぶ組み合わせ列挙

Ans=0
for i in Combi:
    Ans+=np.prod(i)
print(Ans)

Submission status: Accepted

Solution code:
n = int(input())
s = "MARCH"
d = { i:0 for i in s }
for _ in range(n):
  f =  input()[0]
  if f in s:
    d[f] += 1
ans = 0
for i in range(3):
  for j in range(i+1, 4):
    for k in range(j+1, 5):
      ans += d[s[i]]*d[s[j]]*d[s[k]]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

MARCH = ["M", "A", "R", "C", "H"]
S = dict()
for i in range(N):
    tmp = input()
    if tmp[0] in S:
        S[tmp[0]] += 1
    elif tmp[0] in MARCH:
        S[tmp[0]] = 1
    else:
        pass
    
S_values = []
for value in S.values():
    S_values.append(value)
        
if len(S) == 3:
    ans = 1
    for i in range(len(S)):
        ans *= S_values[i]
elif len(S) == 4:
    ans = 0
    ans += S_values[0] * S_values[1] * S_values[2]
    ans += S_values[0] * S_values[1] * S_values[3]
    ans += S_values[1] * S_values[2] * S_values[3]
    ans += S_values[0] * S_values[2] * S_values[3]
elif len(S) ==  5:
    ans = 0
    ans += S_values[0] * S_values[1] * S_values[2]
    ans += S_values[0] * S_values[2] * S_values[3]
    ans += S_values[0] * S_values[3] * S_values[4]
    ans += S_values[0] * S_values[1] * S_values[3]
    ans += S_values[0] * S_values[1] * S_values[4]
    ans += S_values[0] * S_values[2] * S_values[4]
    ans += S_values[1] * S_values[2] * S_values[3]
    ans += S_values[1] * S_values[3] * S_values[4]
    ans += S_values[1] * S_values[2] * S_values[4]
    ans += S_values[2] * S_values[3] * S_values[4]
else:
    print(0)
    exit()


#print(len(S))
#print(S)
#print(S_values)
print(ans)

Submission status: Accepted

Solution code:
import itertools

n = int(input())
s = [input() for _ in range(n)]
m = a = r = c = h = 0
ans = 0

for name in s:
    if name[0] == 'M':
        m += 1

    elif name[0] == 'A':
        a += 1

    elif name[0] == 'R':
        r += 1

    elif name[0] == 'C':
        c += 1

    elif name[0] == 'H':
        h += 1

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

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

print(ans)

Submission status: Accepted

Solution code:
#89c
import collections
import itertools

N = int(input())
S_list = []
for i in range(N):
    S = str(input())
    S_list.append(S[0])

counted = collections.Counter(S_list)
char_comb_list = list(itertools.combinations(["M","A","R","C","H"],3))

ans = 0

for char_comb in char_comb_list:
    ans += counted[char_comb[0]] * counted[char_comb[1]] * counted[char_comb[2]]
    
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

dic = {"M":[], "R":[], "A":[], "C":[], "H":[]}

for _ in range(n):
    s = input()
    if s[0] in dic:
        dic[s[0]].append(s)


import itertools
a = [i for i in range(5)]
per = list(itertools.combinations(a, 3))

ans = 0
for a,b,c in per:
    aa = ["M", "R", "A", "C", "H"]
    ans += len(set(dic[aa[a]])) * len(set(dic[aa[b]])) * len(set(dic[aa[c]]))
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
N=int(input())
L = [str(input()) for i in range(N)]
count_M=0
count_A=0
count_R=0
count_C=0
count_H=0
for i in L:
    if i[0]=='M':count_M+=1
    elif i[0]=='A':count_A+=1
    elif i[0]=='R':count_R+=1
    elif i[0]=='C':count_C+=1
    elif i[0]=='H':count_H+=1
name_list=[count_M,count_A,count_R,count_C,count_H]
sum_list=list(combinations(name_list,3))
s_list=[i[0]*i[1]*i[2] for i in sum_list]
print(sum(s_list))

Submission status: Accepted

Solution code:
N = int(input())
X = {c:0 for c in 'MARCH'}
for _ in range(N):
    c = input()[0]
    if c in X: X[c]+=1

ans = 0
for i1 in range(5):
    for i2 in range(i1+1,5):
        for i3 in range(i2+1,5):
            ans += X['MARCH'[i1]]*X['MARCH'[i2]]*X['MARCH'[i3]]
print(ans)

Submission status: Accepted

Solution code:
def examC():
    N = I()
    St = [S() for _ in range(N)]
    d = defaultdict(int)
    ans = 0
    march = ["M","A","R","C","H"]
    for s in St:
        if s[0] in march:
            d[s[0]] +=1
    if len(d)>=3:
        for comb in itertools.permutations(march):
            ans += d[comb[0]]*d[comb[1]]*d[comb[2]]
        ans //=12
    print(ans)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

Submission status: Accepted

Solution code:
N = int(input())
name = [input() for i in range(N)]
nameList = [0 for i in range(5)]

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]

for n in name:
  if n[0] == 'M':
    nameList[0] += 1
  elif n[0] == 'A':
    nameList[1] += 1
  elif n[0] == 'R':
    nameList[2] += 1
  elif n[0] == 'C':
    nameList[3] += 1
  elif n[0] == 'H':
    nameList[4] += 1

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