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()) 
num = [0,0,0,0,0]

for i in range(n):
    s = input()
    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

num_1 = num[0]*num[1]*num[2]
num_2 = num[0]*num[1]*num[3]
num_3 = num[0]*num[1]*num[4]
num_4 = num[1]*num[2]*num[3]
num_5 = num[1]*num[2]*num[4]
num_6 = num[2]*num[3]*num[4]
num_7 = num[0]*num[2]*num[3]
num_8 = num[0]*num[2]*num[4]
num_9 = num[0]*num[3]*num[4]
num_10 = num[1]*num[3]*num[4]

answer = num_1 + num_2 + num_3 + num_4 + num_5 + num_6 + num_7 + num_8 + num_9 + num_10
print(answer)

Submission status: Accepted

Solution code:
n = int(input())
 
M = 0
A = 0
R = 0
C = 0
H = 0
 
res = 0
 
for i in range(n):
    char = input()[0]
    if char == "M":
        M += 1
    elif char == "A":
        A += 1
    elif char == "R":
        R += 1
    elif char == "C":
        C += 1
    elif char == "H":
        H += 1

res += M * A * R;
res += M * A * C;
res += M * A * H;
res += M * R * C;
res += M * R * H;
res += M * C * H;
 
res += A * R * C;
res += A * R * H;
res += A * C * H;
 
res += R * C * H;
 
print(res)

Submission status: Accepted

Solution code:
m_count = 0
a_count = 0
r_count = 0
c_count = 0
h_count = 0

n = input()

for i in range(n):
    name = raw_input()
    if name[0] == 'M':
        m_count += 1
    elif name[0] == 'A':
        a_count += 1
    elif name[0] == 'R':
        r_count += 1
    elif name[0] == 'C':
        c_count += 1
    elif name[0] == 'H':
        h_count += 1

count = 0
count += m_count * a_count * r_count
count += m_count * r_count * c_count
count += m_count * c_count * h_count
count += a_count * r_count * c_count
count += a_count * c_count * h_count
count += r_count * c_count * h_count
count += m_count * a_count * c_count
count += m_count * a_count * h_count
count += m_count * r_count * h_count
count += a_count * r_count * h_count

print count

Submission status: Accepted

Solution code:
N = int(input())
num = [0,0,0,0,0]
for i in range(N):
	a = input()
	if a[0]=='M':
		num[0] += 1
	if a[0]=='A':
		num[1] += 1
	if a[0]=='R':
		num[2] += 1
	if a[0]=='C':
		num[3] += 1
	if a[0]=='H':
		num[4] += 1


num_1 = num[0]*num[1]*num[2]
num_2 = num[0]*num[1]*num[3]
num_3 = num[0]*num[1]*num[4]
num_4 = num[1]*num[2]*num[3]
num_5 = num[1]*num[2]*num[4]
num_6 = num[2]*num[3]*num[4]
num_7 = num[0]*num[2]*num[3]
num_8 = num[0]*num[2]*num[4]
num_9 = num[0]*num[3]*num[4]
num_10 = num[1]*num[3]*num[4]

answer = num_1 + num_2 + num_3 + num_4 + num_5 + num_6 + num_7 + num_8 + num_9 + num_10

print(answer)

Submission status: Accepted

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

def qwe(y):
    m = 0
    a = 0
    r = 0
    c = 0
    h = 0
    for i in y:
        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
        else:
            pass
    q = [m,a,r,c,h]
    return q

def qwer(arr):
    count = 0
    for j in range(len(arr)):
        if arr[j] == 0:
            count += 1
            arr[j] = "D"
    while "D" in arr:
        arr.remove("D")
    if count == 5:
        return 0
    if count == 4:
        return 0
    if count == 3:
        return 0
    if count == 2:
        wer = arr[0] * arr[1] * arr[2]
        return wer
    if count == 1:
        asd_1 = arr[0]*arr[1]*arr[2]
        asd_2 = arr[0]*arr[1]*arr[3]
        asd_3 = arr[0]*arr[2]*arr[3]
        asd_4 = arr[1]*arr[2]*arr[3]
        asde = asd_1 + asd_2 + asd_3 + asd_4
        return asde
    if count == 0:
        asf_1 = arr[0]*arr[1]*arr[2]
        asf_2 = arr[0]*arr[1]*arr[3]
        asf_3 = arr[0]*arr[1]*arr[4]
        asf_4 = arr[0]*arr[2]*arr[3]
        asf_5 = arr[0]*arr[2]*arr[4]
        asf_6 = arr[0]*arr[3]*arr[4]
        asf_7 = arr[1]*arr[2]*arr[3]
        asf_8 = arr[1]*arr[2]*arr[4]
        asf_9 = arr[1]*arr[3]*arr[4]
        asf_10 = arr[2]*arr[3]*arr[4]
        asdf =  asf_1 + asf_2 + asf_3 + asf_4 + asf_5 + asf_6 + asf_7 + asf_8 + asf_9 + asf_10
        return asdf
v = qwe(s)
print(qwer(v))

Submission status: Accepted

Solution code:
import itertools
## 複数行の入力
count = int(input())
ary = [input() for i in range(count)]
ary_abc = {'M': 0 ,'A': 0, 'R': 0, 'C':0, 'H':0}
for i in ary:
    for abc in ary_abc:
        if abc == i[0]:
            ary_abc[abc] = ary_abc[abc] + 1

ary_res = []

for n in ary_abc:
    if ary_abc[n] != 0:
        ary_res.append(ary_abc[n])

# print(ary_res)
# print(len(ary_res))

result = 0

# print(ary_res)

result_rz = 1
for last_ary in itertools.combinations(ary_res, 3):
    for rz in last_ary:
        result_rz *= rz
    result += result_rz
    result_rz = 1
print(result)

# ary_res = []

# for n in ary_abc:
#     if ary_abc[n] != 0:
#         ary_res.append(ary_abc[n])
        
# l = range(1, 6) # [1, 2, 3, 4, 5]

# # lの各要素を取り出したものの2つ組を並べる
# # 重複は考慮する
# # 順序は考慮しない
# for elem in itertools.product(l, repeat=2):
#     print elem

Submission status: Accepted

Solution code:
from itertools import combinations

def main():
    N = int(input())
    S = tuple(input() for _ in [0] * N)

    name = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
    for s in S:
        if s[0] in 'MARCH':
            name[s[0]] += 1

    lst = [i for i in name.values() if i]
    n = len(lst)
    if n < 3:
        print(0)
        return

    i = 0
    for a, b, c in combinations(name.keys(), 3):
        if all((name[a], name[b], name[c])):
            i += name[a] * name[b] * name[c]

    print(i)

main()

Submission status: Accepted

Solution code:
N=int(input())
X=[0,0,0,0,0]
for I in range(N):
	L=input()
	if L[0]=='M':
		X[0]+=1
	elif L[0]=='A':
		X[1]+=1
	elif L[0]=='R':
		X[2]+=1
	elif L[0]=='C':
		X[3]+=1
	elif L[0]=='H':
		X[4]+=1
SUM=0
for J in range(3):
	for K in range(J+1,4):
		for M in range(K+1,5):
			if J!=K and K!=M and (X[J]!=0 or X[K]!=0 or X[M]!=0):
				SUM+=X[J]*X[K]*X[M]
print(SUM)

Submission status: Accepted

Solution code:
N = int(input())

marchNum = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
march = ['M', 'A', 'R', 'C', 'H']
for i in range(N):
    str = input()
    if str[0] in march:
        marchNum[str[0]] += 1

comNum = 0
for i in range(0,5):
    for j in range(i+1,5):
        for k in range(j+1, 5):
            comNum += marchNum[march[i]] * marchNum[march[j]] * marchNum[march[k]]

print(comNum)

Submission status: Accepted

Solution code:
import math
N = int(input())

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

n = 0
for n in range(N):
    X_n = list(input())
    # print(X_n)
    if (X_n[0]) == "M":
        M += 1
    if (X_n[0]) == "A":
        A += 1
    if (X_n[0]) == "R":
        R += 1
    if (X_n[0]) == "C":
        C += 1
    if (X_n[0]) == "H":
        H += 1
    n += 1



lisofnum = [M, A, R, C, H]
#print(lisofnum)
k = 0
cou = 0
for k in range(len(lisofnum)):
    if lisofnum[k] != 0:
        cou += 1
    k += 1
#print(cou)

if cou < 3:
    print(0)
else:
    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 collections import Counter
from itertools import combinations
N = int(input())
S = [input()[0] for i in range(N)]
C = dict(Counter(S))

A = ["M", "A", "R", "C", "H"]
Z = []
for moji, num in C.items():
    if moji in A:
        Z.append(num)

ans = 0
if len(Z) < 3:
    print(0)
else:
    comb = list(combinations(Z, 3))
    for c in comb:
        ans += c[0] * c[1] * c[2]
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())						# 5



from collections import defaultdict
d = defaultdict(int)

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



r = [ d['M'], d['A'], d['R'], d['C'], d['H'] ]

#print(r)

# 3ペア抽出(組み合わせ)
from itertools import combinations
#l = list(combinations(r, 3))
#print( l )
ans=0
for l in list(combinations(r, 3)):
	ans += (l[0] * l[1] * l[2])

print(ans)

Submission status: Accepted

Solution code:
import itertools
import math

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

count_M = 0
count_A = 0
count_R = 0
count_C = 0
count_H = 0

for l in S_list:
    if l.startswith('M'):
        count_M += 1
    elif l.startswith('A'):
        count_A += 1
    elif l.startswith('R'):
        count_R += 1
    elif l.startswith('C'):
        count_C += 1
    elif l.startswith('H'):
        count_H += 1

count = [count_M,count_A,count_R,count_C,count_H]
c = list(itertools.combinations(count,3))
x = 0
for i in c:
    i_list = list(i)
    x += i_list[0]*i_list[1]*i_list[2]
print(x)

Submission status: Accepted

Solution code:
N = int(input())
m, a, r, c, h = 0, 0, 0, 0, 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
init_list = [m, a, r, c, h]
ans_list = []
for i in range(32):
    if bin(i).count("1") == 3:
        ans = 1
        for j in range(5):
            if i >> j & 1 == 1:
                ans *= init_list[j]
        ans_list.append(ans)
print(sum(ans_list))

Submission status: Accepted

Solution code:
import functools

N = int(input())
march = ["M","A","R","C","H"]
S = {}
for m in march:
    S[m] = 0

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

aS = []
for s in S.values():
    if s != 0:
        aS.append(s)

mul = 1
ans = 0
sum = 0
for s in aS:
    mul = mul * s
    sum += 1
if sum == 3:
    ans = mul
elif sum == 4:
    # ans = mul * 4
    for s in aS:
        ans = ans + mul / s
elif sum == 5:
    # ans = mul * 5
    for i in range(5):
        for j in range(i+1,5):
            ans = ans + mul / aS[i] / aS[j]
print(int(ans))

Submission status: Accepted

Solution code:
n=int(input())
s=[]
for i in range(n):
    s.append(input())
march =[0,0,0,0,0]

for s_ in s:
    if   s_[0] == 'M':
        march[0]+=1
    elif s_[0] == 'A':
        march[1]+=1
    elif s_[0] == 'R':
        march[2]+=1
    elif s_[0] == 'C':
        march[3]+=1
    elif s_[0] == 'H':
        march[4]+=1
#print(march)
while 0 in march:
    march.remove(0)
#print(march)

rsl=0
cnt1=0
for c1 in march:
    cnt2=cnt1+1
    for c2 in march[cnt1+1:]:
        for c3 in march[cnt2+1:]:
            rsl+=c1*c2*c3
#            print(c1,c2,c3,':',rsl)
        cnt2+=1
    cnt1+=1

print(rsl)

Submission status: Accepted

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

m = S.count('M')
a = S.count('A')
r = S.count('R')
c = S.count('C')
h = S.count('H')

total = m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h
print(total)

Submission status: Accepted

Solution code:
n = int(input())
ss = [input() for _ in range(n)]
mp = {c:0 for c in "MARCH"}
ans = 0

for i in range(n):
    if ss[i][0] in "MARCH":
        mp[ss[i][0]] += 1
for i in range(2**5):
    cnt = 0
    tmp = 1
    j = i
    for k in range(5):
        if j % 2 == 1:
            cnt += 1
            tmp *= mp["MARCH"[k]]
        j //= 2
    if cnt == 3:
        ans += tmp

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

N = input()
l = [i for i in range(int(N))]
M = 0
A = 0
R = 0
C = 0
H = 0
for j in range(int(N)):
  l[j] = input()
  if l[j][0] =="M":
    M = M+1
  elif l[j][0] =="A":
    A = A+1
  elif l[j][0] =="R":
    R = R+1
  elif l[j][0] =="C":
    C = C+1
  elif l[j][0] =="H":
    H = H+1
  else: pass

a = np.array([M,A,R,C,H])
ch = np.nonzero(a)
ch = ch[0]
re = 0
if len(ch)<3:
  re = 0
else:
  re = M*A*R+M*A*C+M*A*H
  re = re + M*R*C+M*R*H
  re = re + M*C*H
  re = re + A*R*C+A*R*H+A*C*H
  re = re + R*C*H

print(re)

Submission status: Accepted

Solution code:
N = int(input())
S = []
for i in range(N):
    S.append(input())
md = {}
for i in S:
    if i[0] in ["M","A","R","C","H"]:
        md[i[0]] = md.get(i[0],0) + 1
v = 0
for i in ["MAR","MAC","MAH","MRC","MRH","MCH","ARC","ARH","ACH","RCH"]:
    v += md.get(i[0],0) * md.get(i[1],0) * md.get(i[2],0)
print(v)

Submission status: Accepted

Solution code:
import itertools

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

p = list(itertools.combinations(s,3))

dict ={"M":0,"A":0,"R":0,"C":0,"H":0}
n = input()
n = int(n)
names = []
for i in range(n):
        names.append(input())
for i in range(n):
        if names[i][0] in s:
                dict[names[i][0]] += 1
total_sum = 0
for part in p:
        sum = 1
        for j in range(3):
                sum *= dict[part[j]]
        total_sum += sum
print(total_sum)

Submission status: Accepted

Solution code:
n = int(input().strip())
s = [input().strip() for _ in range(n)]
num_m = len([True for _s in s if _s[0] == "M"])
num_a = len([True for _s in s if _s[0] == "A"])
num_r = len([True for _s in s if _s[0] == "R"])
num_c = len([True for _s in s if _s[0] == "C"])
num_h = len([True for _s in s if _s[0] == "H"])
print(num_m * num_a * num_r + num_m * num_a * num_c + num_m * num_a * num_h + num_m * num_r * num_c
      + num_m * num_r * num_h + num_m * num_c * num_h + num_a * num_r * num_c +
      num_a * num_r * num_h + num_a * num_c * num_h + num_r * num_c * num_h)

Submission status: Accepted

Solution code:
import itertools

N = int(input())

Ss = ['M', 'A', 'R', 'C', 'H']
I = set(['M', 'A', 'R', 'C', 'H'])
D = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
l = []
for i in range(N):
    S = str(input())
    s = S[0]
    if (s in I):
        D[s] = D[s]+1

cmbs = itertools.combinations(Ss, 3)

p = 0
for cmb in cmbs:
    i,j,k = cmb
    if (D[i] == 0 or D[j] == 0 or D[k] == 0):
        continue
    else:
        p += D[i] * D[j] * D[k]

k = 0
for _,j in D.items():
    if j != 0:
        k += 1

if k < 3:
    print(0)
else:
    print(int(p))

Submission status: Accepted

Solution code:
import sys
n=int(input())
s=[input()[0] for i in range(n)]
m,a,r,c,h=0,0,0,0,0
for i in range(n):
    if s[i]=="M": m+=1
    elif s[i]=="A": a+=1
    elif s[i]=="R": r+=1
    elif s[i]=="C": c+=1
    elif s[i]=="H": h+=1
t=sorted([m,a,r,c,h])
q,w,e,r,u=0,0,0,0,0
if t[2]==0:
    print(0)
    sys.exit()
if t[1]==0:
    print(t[2]*t[3]*t[4])
    sys.exit()
if t[0]==0:
    q,w,e,r=t[1],t[2],t[3],t[4]
    print(q*w*e+q*w*r+q*e*r+w*e*r)
    sys.exit()
else:
    q,w,e,r,u=t[0],t[1],t[2],t[3],t[4]
    x=q*w*e+q*w*r+q*w*u+q*e*r+q*e*u+q*r*u
    y=w*e*r+w*e*u+w*r*u+e*r*u
    print(x+y)

Submission status: Accepted

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

def comb1(n, r):
    if n == 0 or r == 0: return 1
    return comb1(n, r-1) * (n-r+1) / r

a = int(input())
# スペース区切りの整数の入力
m_members = []
a_members = []
r_members = []
c_members = []
h_members = []

for i in range(a):
    member = input()
    if(member[0:1] == 'M'):
        m_members.append(member)
    elif(member[0:1] == 'A'):
        a_members.append(member)
    elif(member[0:1] == 'R'):
        r_members.append(member)
    elif(member[0:1] == 'C'):
        c_members.append(member)
    elif(member[0:1] == 'H'):
        h_members.append(member)

member_info = []
count = 0
result = 0

if(len(m_members) != 0):
    member_info.append(len(m_members))
    count += 1
if(len(a_members) != 0):
    member_info.append(len(a_members))
    count += 1
if(len(r_members) != 0):
    member_info.append(len(r_members))
    count += 1
if(len(c_members) != 0):
    member_info.append(len(c_members))
    count += 1
if(len(h_members) != 0):
    member_info.append(len(h_members))
    count += 1

if(count >= 3):
    for i in (list(itertools.combinations(member_info, 3))):
        result += i[0] * i[1] * i[2]
    print(result)
else:
    print(0)

Submission status: Accepted

Solution code:
import itertools
N = int(input())
out = 0
num = [0, 0, 0, 0, 0]
for i in range(N):
    name = list(input())
    if name[0] == "M":
        num[0] = num[0] + 1
    elif name[0] == "A":
        num[1] = num[1] + 1
    elif name[0] == "R":
        num[2] = num[2] + 1
    elif name[0] == "C":
        num[3] = num[3] + 1
    elif name[0] == "H":
        num[4] = num[4] + 1
b = 0
e = ()
for n in range(5):
    if num[n] == 0:
        b +=1
    else:
        e += (n,)
if  b >= 3:
    print(0)
else:
    combi = list(itertools.combinations(e,3))
    for c in combi:
        out += num[c[0]]*num[c[1]]*num[c[2]]
    print(out)

Submission status: Accepted

Solution code:
n = int(input())

nm = 0
na = 0
nr = 0
nc = 0
nh = 0

for i in range(n):
    a = input()
    for j in a:
        b = j
        break
    if b == "M":
        nm += 1
    elif b == "A":
        na += 1
    elif b == "R":
        nr += 1
    elif b == "C":
        nc += 1
    elif b == "H":
        nh += 1

count = 0

count += nm * na * nr
count += nm * na * nc
count += nm * na * nh
count += nm * nr * nc
count += nm * nr * nh
count += nm * nc * nh
count += na * nr * nc
count += na * nr * nh
count += na * nc * nh
count += nr * nc * nh

print(count)

Submission status: Accepted

Solution code:
import itertools
n = int(input())
s = []
c=0
for i in range(n):
    s.append(input()[0])
seq = list(itertools.combinations(["M","A","R","C","H"],3))
for l in seq:
    c += s.count(l[0])*s.count(l[1])*s.count(l[2])
print(c)

Submission status: Accepted

Solution code:
def conb(a, b):
    ans = 1
    for i in range(b):
        ans *= (a - i)
        ans /= (i + 1)
    return ans
    
A = {"M":0, "A":0, "R":0, "C":0, "H":0}
N = int(input())
S = [input() for i in range(N)]
S = [c for c in S if c[0] in A]
for c in S:
    A[c[0]] += 1

N = len(S)
if N >= 3:
    zen = conb(N , 3)
    for a in A:
        a = A[a]
        if a > 2:
            zen -= (conb(a, 3) + conb(a, 2) * (N - a))
        elif a > 1:
            zen -= (N - a)
else:
    zen = 0
print(int(zen))

Submission status: Accepted

Solution code:
N = int(input())
S = [str(input()) for i in range(N)]
S_head = []
for i in S:
    S_head.append(i[:1])
M_num = S_head.count("M")
A_num = S_head.count("A")
R_num = S_head.count("R")
C_num = S_head.count("C")
H_num = S_head.count("H")
ans = M_num*A_num*R_num + M_num*A_num*C_num + M_num*A_num*H_num +\
      M_num*R_num*C_num + M_num*R_num*H_num + M_num*C_num*H_num +\
      A_num*R_num*C_num + A_num*R_num*H_num + A_num*C_num*H_num +\
      R_num*C_num*H_num
print(ans)

Submission status: Accepted

Solution code:
from math import *
from itertools import combinations

n = int(input())
s = [input() for _ in range(n)]
s = list(map(lambda x: x[0], s))
s = list(filter(lambda x: x in 'MARCH', s))
t = {}
for x in range(len(s)):
  if s[x] in t: t[s[x]] += 1
  else: t[s[x]] = 1
t = list(t.values())
a = 0
for c in combinations(t, 3):
  m = 1
  for e in c:
    m *= e
  a += m
print(a)

Submission status: Accepted

Solution code:
N=int(input())
M=[]
A=[]
R=[]
C=[]
H=[]
for i in range(N):
  s=input()
  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)
cnt=[len(M),len(A),len(R),len(C),len(H)]
res=sum(cnt)
res=int(res*(res-1)*(res-2)/6)

def dif(n):
  if cnt[n]==0 or cnt[n]==1:
    return 0
  else:
    a=0
    for i in range(5):
      if i!=n:
        a+=cnt[i]
  if cnt[n]==2:
    return a
  else:
    b=cnt[n]*(cnt[n]-1)*(cnt[n]-2)/6
    d=cnt[n]*(cnt[n]-1)/2
    d*=a
    return int(d+b)
for i in range(5):
  res-=dif(i)
c=0
for j in range(5):
  if cnt[j]==0:
    c+=1
if c>2:
  print(0)
else:
  print(res)

Submission status: Accepted

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

m = [[] for _ in range(5)]
for i in range(n):
    if s[i][:1] == "M":
        m[0].append(s[i])
    elif s[i][:1] == "A":
        m[1].append(s[i])
    elif s[i][:1] == "R":
        m[2].append(s[i])
    elif s[i][:1] == "C":
        m[3].append(s[i])
    elif s[i][:1] == "H":
        m[4].append(s[i])
    else:
        pass
    
for i in range(5):
    m[i] = len(list(set(m[i])))

print(m[0] * m[1] * m[2] + m[0] * m[1] * m[3] + m[0] * m[1] * m[4] + m[0] * m[2] * m[3] + m[0] * m[2] * m[4] + m[0] * m[3] * m[4] + m[1] * m[2] * m[3] + m[1] * m[2] * m[4] + m[1] * m[3] * m[4] + m[2] * m[3] * m[4])

Submission status: Accepted

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

ans = 0
for i in range(5):
    for j in range(5):
        if(i == j):
            break
        for k in range(5):
            if(j == k):
                break
            ans += s[i] * s[j] * s[k]
print(ans)

Submission status: Accepted

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

M = 0
A = 0
R = 0
C = 0
H = 0
res = 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

for m in range(2):
    for a in range(2):
        for r in range(2):
            for c in range(2):
                for h in range(2):
                    if m+a+r+c+h == 3:
                        temp = 1
                        if m == 1:
                            temp *= M
                        if a == 1:
                            temp *= A
                        if r == 1:
                            temp *= R
                        if c == 1:
                            temp *= C
                        if h == 1:
                            temp *= H
                        res += temp
                            
print(res)

Submission status: Accepted

Solution code:
from collections import Counter
from math import factorial
N = int(input())
S = [input()[0:1:] for i in range(N)]

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

ans = 0
if len(list) >= 3:
    for i in range(len(list)):
        for j in range(len(list)-1):
            for k in range(len(list)-2):
                if (i != j+1) and (j+1 != k+2) and (k+2 != i) and (i<j+1) and (j<k+1):
                    ans += list[i] * list[j+1] * list[k+2]

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
C - March
https://beta.atcoder.jp/contests/abc089/tasks/abc089_c

"""
import sys
from sys import stdin
from itertools import combinations
input = stdin.readline


def main(args):
    N = int(input())
    names = dict()
    for _ in range(N):
        tmp = input().strip()
        if not tmp in names:
            if tmp[0] in 'MARCH':
                names[tmp] = 1

    m_names = [0] * 5
    for k, v in names.items():
        if k[0] == 'M':
            m_names[0] += 1
        elif k[0] == 'A':
            m_names[1] += 1
        elif k[0] == 'R':
            m_names[2] += 1
        elif k[0] == 'C':
            m_names[3] += 1
        elif k[0] == 'H':
            m_names[4] += 1

    if len(names) < 3:
        print(0)
    else:
        ans = 0
        for c in combinations(m_names, 3):
            t = c[0] * c[1] * c[2]
            ans += t
        print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
from collections import Counter
N=int(input())
X=[]
for i in range(N):
    X.append(input())
Y=[X[i][0] for i in range(N)]
c = Counter(Y)
count=0
count=c.get('M',0)*c.get('A',0)*c.get('R',0)+ c.get('M',0)*c.get('A',0)*c.get('C',0)+ c.get('M',0)*c.get('A',0)*c.get('H',0)+ c.get('M',0)*c.get('R',0)*c.get('C',0)+\
      c.get('M',0)*c.get('R',0)*c.get('H',0)+ c.get('M',0)*c.get('C',0)*c.get('H',0)+ c.get('A',0)*c.get('R',0)*c.get('C',0)+ c.get('A',0)*c.get('R',0)*c.get('H',0)+\
      c.get('A',0)*c.get('C',0)*c.get('H',0)+ c.get('R',0)*c.get('C',0)*c.get('H',0)
print(count)

Submission status: Accepted

Solution code:
N = int(input())
S = []
for i in range(N):
    S.append(str(input()))
    
from collections import Counter
import numpy as np
import itertools
initial = np.array([list(i)[0] for i in S])

counter = Counter(initial)
iflist = np.array(["M","A","R","C","H"])
num = []
for word, cnt in counter.most_common():
    if any(word == iflist):
        num.append(cnt)
        
ans = 0
for i in itertools.combinations(num,3):
    ans += np.array(i).prod()
    
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

N = input()
m = 0
a = 0
r = 0
c = 0
h = 0
for i in range(N):
	S = raw_input()
	if S[:1] == "M":
		m += 1
	elif S[:1] == "A":
		a += 1
	elif S[:1] == "R":
		r += 1
	elif S[:1] == "C":
		c += 1
	elif S[:1] == "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 collections import Counter
import itertools
n = int(input())
march = Counter()
is_march = ['M', 'A', 'R', 'C', 'H']
for i in range(n):
    head = input()[0]
    if head in is_march:
        march[head] += 1
ans = 0
for c in itertools.combinations(march.keys(), 3):
    t = 1
    for x in c:
        t *= march[x]
    ans += t
print(int(ans))

Submission status: Accepted

Solution code:
import sys

N=int(raw_input())
list_S=[raw_input() for i in range(N)]

list_MARCH=["M", "A", "R", "C", "H"]
list_only_MARCH=[i for i in list_S if i[0] in list_MARCH]

num_MARCH=len(list_only_MARCH)
list_num=[0, 0, 0, 0, 0]
for i in list_only_MARCH:
  if   i[0]=="M": list_num[0]=list_num[0]+1
  elif i[0]=="A": list_num[1]=list_num[1]+1
  elif i[0]=="R": list_num[2]=list_num[2]+1
  elif i[0]=="C": list_num[3]=list_num[3]+1
  elif i[0]=="H": list_num[4]=list_num[4]+1

ans_num=num_MARCH*(num_MARCH-1)*(num_MARCH-2)/6
if ans_num==0:
  print 0
  sys.exit()

for i in list_num:
  if i==2: ans_num=ans_num-(num_MARCH-2)
  elif i>=3:
    ans_num=ans_num-(i*(i-1)*(i-2)/6)
    ans_num=ans_num-((num_MARCH-i)*i*(i-1)/2)

print ans_num

Submission status: Accepted

Solution code:
N = int(input())

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




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

Submission status: Accepted

Solution code:
import itertools
import operator

def product(iterable):
    return reduce(operator.mul, iterable, 1)

def main():
    n = int(raw_input())
    table = dict((c, 0) for c in 'MARCH')

    for _ in xrange(n):
        s = raw_input()
        if s[0] in table:
            table[s[0]] += 1

    m = 0
    for comb in itertools.combinations('MARCH', 3):
        m += product(table[c] for c in comb)
    print m

main()

Submission status: Accepted

Solution code:
import itertools
from collections import Counter

L=['M','A','R','C','H']
N=int(input())
a =[input()[0] for i in range(N)]
A=dict(Counter([x for x in a if x in L]))

res = list(map(dict, itertools.combinations(A.items(), 3)))

ans=0
for r in res:
	tmp=1
	for k in r.values():
		tmp*=k
	ans+=tmp
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = {"M":0,"A":0,"R":0,"C":0,"H":0}
for i in range(N):
    s = input()
    if s[0] in ["M","A","R","C","H"]:
        S[s[0]] += 1

print(S["M"] * S["A"] * (S["R"] + S["C"] + S["H"])
      + S["M"] * S["R"] * (S["C"] + S["H"])
      + S["M"] * S["C"] * S["H"]
      + S["A"] * S["R"] * (S["C"] + S["H"])
      + S["A"] * S["C"] * S["H"]
      + S["R"] * S["C"] * S["H"])

Submission status: Accepted

Solution code:
N = int(input())

name_capital = {
    'M': 0,
    'A': 0,
    'R': 0,
    'C': 0,
    'H': 0,
}
name_list = ['M', 'A', 'R', 'C', 'H']
for _ in range(N):
    name = input()
    for word in name_list:
        if name[0] == word:
            name_capital[word] += 1
            break

nv = list(name_capital.values())
N2 = len(nv)
answer = 0
for i in range(N2-2):
    for j in range(i+1, N2-1):
        for k in range(j+1, N2):
            answer += nv[i] * nv[j] * nv[k]

print(answer)

Submission status: Accepted

Solution code:
import numpy as np
num=int(input())
#valid=["M","A","R","C","H"]
arr=np.zeros(5)
#print(arr)

for i in range(num):
    chara=list(input())[0]
    if chara == "M":
        arr[0]+=1
    if chara == "A":
        arr[1]+=1
    if chara == "R":
        arr[2]+=1
    if chara == "C":
        arr[3]+=1
    if chara == "H":
        arr[4]+=1

ans=0
for i in range(3):
    for k in range(3-i):
        for j in range(3-k-i):
            ans+=arr[i]*arr[1+i+k]*arr[2+i+k+j]
            #print(arr[i]*arr[1+i+k]*arr[2+i+k+j])
print(int(ans))

Submission status: Accepted

Solution code:
def ACBC_089_C():
    _num = int(input())
    _namelist = []
    _countM = 0
    _countA = 0
    _countR = 0
    _countC = 0
    _countH = 0

    for i in range(0, _num):
        _name = str(input())
        _namelist.append(_name)
        if _name[0] == "M":
            _countM += 1
        elif _name[0] == "A":
            _countA += 1
        elif _name[0] == "R":
            _countR += 1
        elif _name[0] == "C":
            _countC += 1
        elif _name[0] == "H":
            _countH += 1
    print(_countM * _countA * _countR + \
          _countM * _countA * _countC + \
          _countM * _countA * _countH + \
          _countM * _countR * _countC + \
          _countM * _countR * _countH + \
          _countM * _countC * _countH + \
          _countA * _countR * _countC + \
          _countA * _countR * _countH + \
          _countA * _countC * _countH + \
          _countR * _countC * _countH)


ACBC_089_C()

Submission status: Accepted

Solution code:
N = int(input())
count = [0,0,0,0,0]
for i in range(N):
    S = input()
    if S[0] == "M":
        count[0] = count[0] + 1
    if S[0] == "A":
        count[1] = count[1] + 1
    if S[0] == "R":
        count[2] = count[2] + 1
    if S[0] == "C":
        count[3] = count[3] + 1
    if S[0] == "H":
        count[4] = count[4] + 1
a = 0
a = a + count[0]*count[1]*count[2]
a = a + count[0]*count[1]*count[3]
a = a + count[0]*count[1]*count[4]
a = a + count[0]*count[2]*count[3]
a = a + count[0]*count[2]*count[4]
a = a + count[0]*count[3]*count[4]
a = a + count[1]*count[2]*count[3]
a = a + count[1]*count[2]*count[4]
a = a + count[1]*count[3]*count[4]
a = a + count[2]*count[3]*count[4]
print(a)