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:
import itertools
N=int(input())
l=[0]*5
m=list('MARCH')
for i in range(N):
    S=input()
    if S[0] in m:
        l[m.index(S[0])]+=1
ans=0
for i in list(itertools.combinations(l,3)):
    m=1
    for j in i:
        m*=j
    ans+=m
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve():
    from collections import defaultdict
    from itertools import combinations
    n = int(input())
    d = defaultdict(int)
    for i in range(n):
        s = input()
        d[s[0]] += 1
    ans = 0
    for x, y, z in combinations(["M", "A", "R", "C", "H"], 3):
        ans += d[x] * d[y] * d[z]
    print(ans)
    return


solve()

Submission status: Accepted

Solution code:
import itertools
n=int(input())
m,a,r,c,h=0,0,0,0,0
for i in range(n):
  x=input()
  if x[0]=='M':
    m+=1
  elif x[0]=='A':
    a+=1
  elif x[0]=='R':
    r+=1
  elif x[0]=='C':
    c+=1
  elif x[0]=='H':
    h+=1
    
ans=0

for lst in itertools.combinations([m,a,r,c,h],3):
  cnt=1
  for i in lst:
    cnt*=i
    
  ans+=cnt
  
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations

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

indices = [0, 1, 2, 3, 4]
letters = ["M", "A", "R", "C", "H"]
mapping = dict(zip(letters, indices))

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

cnt = 0
for combo in combinations(c, 3):
    cnt += combo[0]*combo[1]*combo[2]

print(cnt)

Submission status: Accepted

Solution code:
from itertools import combinations

n=int(input())
cnt=[0]*26

for i in range(n):
    s=input()
    cnt[ord(s[0])-ord('A')]+=1

ans=0

for c1,c2,c3 in combinations(["M","A","R","C","H"],3):
    c1=ord(c1)-ord("A")
    c2=ord(c2)-ord("A")
    c3=ord(c3)-ord("A")

    ans+=cnt[c1]*cnt[c2]*cnt[c3]

print(ans)

Submission status: Accepted

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

march=[0]*5
string="MARCH"

for i in range(n):
    for j in range(5):
        if s[i][0]==string[j]:
            march[j] +=1

if march.count(0)>=3:
    print(0)
    exit()

while march.count(0):
    march.remove(0)

ans=0
for i_0 in range(len(march)):
    for i_1 in range(i_0+1,len(march)):
        for i_2 in range(i_1+1,len(march)):
            ans = ans + march[i_0]*march[i_1]*march[i_2]
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import defaultdict
n = int(input())
name_d = dict()
name_d["M"] = 0
name_d["A"] = 0
name_d["R"] = 0
name_d["C"] = 0
name_d["H"] = 0

for _ in range(n):
    s = input()
    if s[0] in "MARCH":
        name_d[s[0]] += 1
#print(name_d)
name_patturn = ["MAR", "MRC", "MCH", "MAH", "MAC", "MRH", "ARC", "ARH", "ACH", "RCH"]
ans = 0
for patturn in name_patturn:
    ans += name_d[patturn[0]]*name_d[patturn[1]]*name_d[patturn[2]]

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import itertools
N = int(input())
Name = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}


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

l = []
for k, v in Name.items():
    l.append(v)

ret = 0

for x in itertools.combinations(l, 3):
    ret += x[0]*x[1]*x[2]

print(ret)

Submission status: Accepted

Solution code:
from itertools import combinations
n = int(input())
d = {}
for _ in range(n):
  s = input()[0]
  if s in ["M","A","R","C","H"]:
    if s in d: d[s] += 1
    else: d[s] = 1

t = []
for k in d.keys(): t.append(k)
if len(t) < 3:
  print(0)
  exit()
  
ans = 0
for i in combinations(t, 3):
  ans += d[i[0]]*d[i[1]]*d[i[2]]
print(ans)

Submission status: Accepted

Solution code:
import sys
from itertools import combinations

input = sys.stdin.readline


def main():
    N = int(input())
    S = [""] * N
    for i in range(N):
        S[i] = input().rstrip()

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

    ans = 0
    for c1, c2, c3 in combinations("MARCH", 3):
        ans += count[c1] * count[c2] * count[c3]

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
d = dict()
for i in range(n):
    s = list(input())
    if s[0] == "M" or s[0] == "A" or s[0] == "R" or s[0] == "C" or s[0] == "H":
        if s[0] not in d:
            d[s[0]] = 1
        else:
            d[s[0]] += 1
count = 0
d = list(d.values())
if len(d) == 3:
    count += d[0] * d[1] * d[2]
elif len(d) == 4:
    count += d[0] * d[1] * d[2]
    count += d[3] * d[1] * d[2]
    count += d[0] * d[1] * d[3]
    count += d[0] * d[3] * d[2]
elif len(d) == 5:    
    count += d[0] * d[1] * d[2]
    count += d[3] * d[1] * d[2]
    count += d[0] * d[1] * d[3]
    count += d[0] * d[3] * d[2]

    # count += d[0] * d[1] * d[2]
    count += d[4] * d[1] * d[2]
    count += d[0] * d[1] * d[4]
    count += d[0] * d[4] * d[2]

    # count += d[4] * d[1] * d[2]
    # count += d[3] * d[1] * d[2]
    count += d[4] * d[1] * d[3]
    count += d[4] * d[3] * d[2]

    # count += d[0] * d[4] * d[2]
    # count += d[3] * d[4] * d[2]
    count += d[0] * d[4] * d[3]
    # count += d[0] * d[3] * d[2]


print(count)

Submission status: Accepted

Solution code:
MARCH = list('MARCH')
# print(MARCH)
N = int(input())
S = [input() for _ in range(N)]
# print(S)

namect = []
for i in range(5):
    st = [s for s in S if s.startswith(MARCH[i])]
    namect.append(len(st))
ans = 0
for i in range(5):
    for j in range(i+1, 5):
        for k in range(j+1, 5):
            ans += namect[i]*namect[j]*namect[k]
print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import Counter

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    S = [readline().strip() for _ in range(N)]

    initials = set('MARCH')
    counter = Counter()
    for s in S:
        if s[0] in initials:
            counter[s[0]] += 1

    vec = list(counter.values())
    ans = 0
    for i in range(len(vec) - 2):
        for j in range(i + 1, len(vec) - 1):
            for k in range(j + 1, len(vec)):
                ans += vec[i] * vec[j] * vec[k]

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
M=0
A=0
R=0
C=0
H=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*C*H+A*R*H+R*C*H)

Submission status: Accepted

Solution code:
n = int(input())
s = [0] * 5
for i in range(n):
    l = input()
    l = l[0]
    if l == 'M':
        s[0] += 1
    elif l == 'A':
        s[1] += 1
    elif l == 'R':
        s[2] += 1
    elif l == 'C':
        s[3] += 1
    elif l == 'H':
        s[4] += 1
    else:
        pass
ans = 0
a = [[0,1,2],[0,1,3],[0,1,4],[0,2,3],[0,2,4],[0,3,4],[1,2,3],[1,2,4],[1,3,4],[2,3,4]]
for i in range(10):
    ans += s[a[i][0]] * s[a[i][1]] * s[a[i][2]]
print(ans)

Submission status: Accepted

Solution code:
import itertools
from functools import reduce

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

counter = [len(list(filter(lambda s: s[0] == l, S))) for l in 'MARCH']

ans = 0
for pat in itertools.combinations(range(5), 3):
    ans += reduce(lambda a, b: a * b, [counter[p] for p in pat], 1)

print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
N = int(input())
X = ["M","A","R","C","H"]
Y = [0 for _ in range(5)]
for _ in range(N):
  S = input()
  for i, x in enumerate(X):
    if x == S[0]:
      Y[i] += 1
      break
    
ans = 0
for y in combinations(Y, 3):
  ans += y[0] * y[1] * y[2]
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
from itertools import combinations

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

c = defaultdict(int)

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

if len(c) < 3:
  print(0)
  exit()

if len(c)==3:
  ans=1
  for k in c.keys():
    ans *= c[k]
  print(ans)
  exit()

else:
  ans = 0
  l = len(c)
  keys = list(c.keys())
  for C in combinations(range(l),3):
    tmp = c[keys[C[0]]]*c[keys[C[1]]]*c[keys[C[2]]]
    ans += tmp
  print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
from itertools import combinations
def main():
    n = int(input())
    d = defaultdict(int)
    for _ in range(n):
        s = input()
        d[s[0]] += 1
    ans = 0
    for i, j, k in combinations('MARCH', 3):
        ans += d[i] * d[j] * d[k]
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import collections

N = int(input())
S = [str(input())[0] for _ in range(N)]
ref_lst = [["M",0],["A",0],["R",0],["C",0],["H",0]]

for i in range(5):
    ref_lst[i][1] = S.count(ref_lst[i][0])

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
MARCH = {'M':0,'A':0,'R':0,'C':0,'H':0}
N=int(input())
for i in range(N):
  s=str(input())
  if s[0]=='M':
    MARCH['M']+=1
  elif s[0]=='A':
    MARCH['A']+=1
  elif s[0]=='R':
    MARCH['R']+=1
  elif s[0]=='C':
    MARCH['C']+=1
  elif s[0]=='H':
    MARCH['H']+=1
ans = MARCH['M']*MARCH['A']*MARCH['R']\
  +MARCH['M']*MARCH['A']*MARCH['C']\
  +MARCH['M']*MARCH['A']*MARCH['H']\
  +MARCH['M']*MARCH['R']*MARCH['C']\
  +MARCH['M']*MARCH['R']*MARCH['H']\
  +MARCH['M']*MARCH['C']*MARCH['H']\
  +MARCH['A']*MARCH['R']*MARCH['C']\
  +MARCH['A']*MARCH['R']*MARCH['H']\
  +MARCH['A']*MARCH['C']*MARCH['H']\
  +MARCH['R']*MARCH['C']*MARCH['H']
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
from itertools import combinations

STR = "MARCH"

N = int(input())
s = [input() for _ in range(N)]
dd = defaultdict(int)
for i in range(N):
  dd[s[i][0]] += 1
t = tuple(dd[S]  for S in STR)
p = combinations(t,3)
ans = sum(x[0]*x[1]*x[2] for x in p)
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import itertools


def main():
    N = int(input())
    S = [input() for i in range(N)]
    S_cnt = [0]*5
    E = ["M", "A", "R", "C", "H"]
    for s in S:
        for i in range(5):
            if s[0] ==E[i]:
                S_cnt[i] += 1
    E_list = list(itertools.combinations(E, 3))
    tmp = 1
    ans = 0
    for e in E_list:
        for i in range(3):
            for j in range(5):
                if e[i] == E[j]:
                    tmp *= S_cnt[j]
        ans += tmp
        tmp = 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict
from itertools import groupby, accumulate, product, permutations, combinations
def solve():
  d = defaultdict(lambda: 0)
  N = int(input())
  for i in range(N):
    S = input()
    d[S[0]] += 1
  s = 'MARCH'
  s = list(s)
  cnt = 0
  for com in combinations(s,3):
    prod = 1
    for c in com:
      prod *= d[c]
    cnt += prod
  return cnt
print(solve())

Submission status: Accepted

Solution code:
import sys
import itertools

N = int(sys.stdin.readline())

count = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for _ in range(N):
    s = sys.stdin.readline().strip()
    if s[0] in count:
        count[s[0]] += 1

ans = 0
for perm in itertools.combinations(count.keys(), 3):
    tmp = 1
    for i in perm:
        tmp *= count[i]
    ans += tmp

print(ans)

Submission status: Accepted

Solution code:
import itertools
n = int(input())
s = [input() for _ in range(n)]
a = [0,0,0,0,0]
for i in range(len(s)):
    if (s[i][0]=="M"):
        a[0] += 1
    elif (s[i][0]=="A"):
        a[1] += 1
    elif (s[i][0]=="R"):
        a[2] += 1
    elif (s[i][0]=="C"):
        a[3] += 1
    elif (s[i][0]=="H"):
        a[4] += 1

l = [0,1,2,3,4]
p = list(itertools.combinations(l, 3))
ans = 0
for i in range(len(p)):
    x,y,z = p[i][0],p[i][1],p[i][2]
    ans += a[x]*a[y]*a[z]
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations

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

memo = {}
for i in 'MARCH':
    memo[i] = 0

for i in S:
    if i[0] in 'MARCH':
        memo[i[0]] += 1

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
M,A,R,C,H = 0,0,0,0,0
for i in range(N):
    S = input()
    if S[0] == "M":
        M += 1
    elif S[0] == "A":
        A += 1
    elif S[0] == "R":
        R += 1
    elif S[0] == "C":
        C += 1
    elif S[0] == "H":
        H += 1
ans = 0
MARCH = [M,A,R,C,H]
for i in range(5):
    for j in range(i+1, 5):
        for k in range(j+1, 5):
            ans += MARCH[i]*MARCH[j]*MARCH[k]
print(ans)

Submission status: Accepted

Solution code:
import collections
def dfs(i, cumul, cc, k, s): return (cumul if k == 0 else 0) if (i == len(s) or k == 0) else (dfs(i+1,  cumul * cc[s[i]], cc,k - 1, s) +dfs(i+1,  cumul, cc, k, s))
print dfs(0,  1 , collections.Counter([raw_input()[0] for _ in range(int(raw_input()))]), 3, 'MARCH')

Submission status: Accepted

Solution code:
import collections
cc = collections.Counter([raw_input()[0] for _ in range(int(raw_input()))])


def dfs(i, total ,cumul, cc, k, s):
	if i == len(s) or k == 0:
		if k == 0: total[0] += cumul
		return 
	
	dfs(i+1, total, cumul * cc[s[i]], cc,k - 1, s)
	dfs(i+1, total, cumul, cc, k, s)

total = [0]
dfs(0, total, 1 , cc, 3, 'MARCH')
print total[0]

Submission status: Accepted

Solution code:
import collections
cc = collections.Counter()
for _ in range(int(raw_input())): 
	cc[raw_input()[0]] +=1	

def dfs(i, total ,cumul, cc, k, s):
	if i == len(s) or k == 0:
		if k == 0: total[0] += cumul
		return 
	if k:
		dfs(i+1, total, cumul * cc[s[i]], cc,k - 1, s)

	dfs(i+1, total, cumul, cc, k, s)

total = [0]
dfs(0, total, 1 , cc, 3, 'MARCH')
print total[0]

Submission status: Accepted

Solution code:
import collections
cc = collections.Counter()
for _ in range(int(raw_input())): 
	s = raw_input()
	cc[s[0]] +=1	

def dfs(i, total ,cumul, cc, k, s):
	if i == len(s):
		if k == 0:
			total[0] += cumul
		return 

	if k:
		dfs(i+1, total, cumul * cc[s[i]], cc,k - 1, s)
	dfs(i+1, total, cumul, cc, k, s)

total = [0]
dfs(0, total, 1 , cc, 3, 'MARCH')
print total[0]

Submission status: Accepted

Solution code:
import collections
cc = collections.Counter()
for _ in range(int(raw_input())): 
	s = raw_input()
	cc[s[0]] +=1	

def dfs(i, total ,cumul, cc, k, s):
	if i == len(s):
		if k == 0:
			total[0] += cumul
		return 

	dfs(i+1, total, cumul * cc[s[i]], cc,k - 1, s)
	dfs(i+1, total, cumul, cc, k, s)

total = [0]
dfs(0, total, 1 , cc, 3, 'MARCH')
print total[0]

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [input()[0] for i in range(N)]
    from collections import Counter
    from itertools import combinations
    c = Counter(A)
    d = ('M', 'A', 'R', 'C', 'H')
    ans = 0
    for (a1, a2, a3) in combinations(d, 3):
        ans += c[a1] * c[a2] * c[a3]
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import collections
import itertools

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	n = int(input())
	#b , c = tin()
	#s = input()
	al = collections.defaultdict(lambda :0)
	for _ in range(n):
		s=input()
		al[s[0]] += 1
	ret = 0
	for cl in itertools.combinations('MARCH', 3):
		r=1
		for c in cl:
			#pa(c)
			r *= al[c]
		ret += r
	print(ret)
	
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

Solution code:
import itertools

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

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

ans = 0
for i, j, k in itertools.combinations(cnt, r=3):
    ans += i * j * k

print(ans)

Submission status: Accepted

Solution code:
import itertools
N = int(input())
X = [input()[0] for _ in range(N)]
M = X.count("M")
A = X.count("A")
R = X.count("R")
C = X.count("C")
S = 0
H = X.count("H")
for s in itertools.combinations([M, A, R, C, H], 3):
  S += s[0]*s[1]*s[2]
print(S)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from itertools import combinations

_, *s = open(0).read().split()
d = defaultdict(int)
for i in s:
    d[i[0]] += 1
ans = 0
for a, b, c in combinations(["M", "A", "R", "C", "H"], 3):
    ans += d[a] * d[b] * d[c]
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
initials = {'M':0,'A':0,'R':0,'C':0,'H':0}
for _ in range(int(input())):
  name = input()
  initials[name[0]] = initials.get(name[0],0)+1
answer = 0
for initial in combinations('MARCH',3):
  answer += initials[initial[0]]*initials[initial[1]]*initials[initial[2]]
print(answer)

Submission status: Accepted

Solution code:
import sys
import itertools

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n = I()
    march = [0]*5
    for _ in range(n):
        s = input()[0]
        if s == 'M':
            march[0] += 1
        elif s == 'A':
            march[1] += 1
        elif s == 'R':
            march[2] += 1
        elif s == 'C':
            march[3] += 1
        elif s == 'H':
            march[4] += 1
    ans = 0
    for idx in itertools.combinations([0, 1, 2, 3, 4], 3):
        ans += march[idx[0]] * march[idx[1]] * march[idx[2]]
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools
N = int(input())
S = [input()[0] for T in range(N)]
MARCH = [S.count('M'),S.count('A'),S.count('R'),S.count('C'),S.count('H')]
Total = 0
for T in itertools.combinations(MARCH,3):
    Total += T[0]*T[1]*T[2]
print(Total)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools

N = int(input())

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

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

ans = 0
for i in itertools.combinations(["M","A","R","C","H"],3):
    ans+= len(dic[i[0]])*len(dic[i[1]])*len(dic[i[2]])

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

march = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
for name in s:
    if name[0] in march.keys():
        march[name[0]] += 1
#(m,a,r)(m,a,c)(m,a,h)
#(m,r,c)(m,r,h)
#(m,c,h)
ans = march['M']*march['A']*march['R']
ans += march['M']*march['A']*march['C']
ans += march['M']*march['A']*march['H']
ans += march['M']*march['R']*march['C']
ans += march['M']*march['R']*march['H']
ans += march['M']*march['C']*march['H']
#(a,r,c)(a,r,h)
#(a,c,h)
ans += march['A']*march['R']*march['C']
ans += march['A']*march['R']*march['H']
ans += march['A']*march['C']*march['H']
#(r,c,h)
ans += march['R']*march['C']*march['H']

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter 
from itertools import combinations
n=int(input())
s=[]
count=0
for _ in range(n):
    si=list(input())
    if si[0]=="M" or si[0]=="R" or si[0]=="A" or si[0]=="C" or si[0]=="H":

        s.append(si[0])
s_counter=Counter(s)
s_key=s_counter.keys()
if len(s_key)>=3:
    for i,j,k in combinations(s_key,3):
        count+=s_counter[i]*s_counter[j]*s_counter[k]
print(count)

Submission status: Accepted

Solution code:
import itertools

n = int(input())
m = 0
a = 0
r = 0
c = 0
h = 0
d = []
for i in range(5):
    d.append(i)
p_list = list(itertools.combinations(d, 3))

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
con = [m,a,r,c,h]
ans = 0
for i in range(len(p_list)):
    ans += con[p_list[i][0]] * con[p_list[i][1]] * con[p_list[i][2]]
    
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations

N=int(input())
P={"M","A","R","C","H"}
X={x:0 for x in P}

for _ in range(N):
    S=input()
    if S[0] in P:
        X[S[0]]+=1

K=0
for (a,b,c) in combinations(P,3):
    K+=X[a]*X[b]*X[c]
print(K)

Submission status: Accepted

Solution code:
from itertools import permutations
S = [0] * 5
B = [False, False, True, True, True]
N = int(input())
for _ 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
res = 0
for p in set(permutations(B)):
    t = 1
    for i in range(5):
        if p[i]:
            t *= S[i]
    res += t
print(res)

Submission status: Accepted

Solution code:
from itertools import combinations
from collections import Counter
N=int(input())
S=Counter()
for i in range(N):
    S[input()[0]]+=1
print(sum([S[a]*S[b]*S[c] for a,b,c in combinations("MARCH",3)]))

Submission status: Accepted

Solution code:
N = int(input())
S = [input()[0] for i in range(N)]
m = S.count("M")
a = S.count("A")
r = S.count("R")
c = S.count("C")
h = S.count("H")
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:
# abc089_c.py
import collections
N = int(input())
M = []
for i in range(N):
    c = input()[0]
    if c == 'M' or c == 'A' or c == 'R' or c == 'C' or c == 'H':
        M.append(c)
C = collections.Counter(M)
ans = 0
march = list('MARCH')
for i in range(5):
    for j in range(i+1, 5):
        for k in range(j+1, 5):
            ans += C[march[i]]*C[march[j]]*C[march[k]]
print(ans)

Submission status: Accepted

Solution code:
from itertools import *
N = int(input())
D = {"M":0,"A":0,"R":0,"C":0,"H":0}

for n in range(N):
  s = input()
  if s[0] in "MARCH":
    D[s[0]]+=1

print(sum(a*b*c for a,b,c in combinations(D.values(),3)))

Submission status: Accepted

Solution code:
from itertools import *
N = int(input())
S = [input() for n in range(N)]
D = {"M":0,"A":0,"R":0,"C":0,"H":0}

for s in S:
  if s[0] in "MARCH":
    D[s[0]]+=1

print(sum(a*b*c for a,b,c in combinations(D.values(),3)))

Submission status: Accepted

Solution code:
from itertools import *
N = int(input())
S = [input() for n in range(N)]
D = {"M":0,"A":0,"R":0,"C":0,"H":0}
ans = 0

for s in S:
  if s[0] in "MARCH":
    D[s[0]]+=1

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

print(ans)

Submission status: Accepted

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

c = [s.count(i) for i in 'MARCH']
ans = sum(c[i]*c[j]*c[k] for i,j,k in itertools.combinations(range(5), 3))
print(ans)

Submission status: Accepted

Solution code:
# abc089c
import itertools
import sys
n = int(input())
s = [input() for i in range(n)]
'''
1.
M,A,R,C,Hから始まる名前を抽出する
2.
MARCHの5文字から3文字選ぶ
3.
選んだ文字ごとに、人数の掛け算を行う
'''
m = 0
a = 0
r = 0
c = 0
h = 0
for si in s:
    if si[0] == 'M':
        m += 1
    elif si[0] == 'A':
        a += 1
    elif si[0] == 'R':
        r += 1
    elif si[0] == 'C':
        c += 1
    elif si[0] == 'H':
        h += 1
if m == 0 and a == 0 and r == 0 and c == 0 and h == 0:
    print(0)
else:
    p = itertools.combinations(['M','A','R','C','H'], 3)
    ans = 0
    for i in p:
        ans_ = 1
        if 'M' in i:
            ans_ *= m
        if 'A' in i:
            ans_ *= a
        if 'R' in i:
            ans_ *= r
        if 'C' in i:
            ans_ *= c
        if 'H' in i:
            ans_ *= h
        ans += ans_
    print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
import itertools

n = int(input())
s = [input()[:1] for _ in range(n)]
s = Counter([i for i in s if i in ['M', 'A', 'R', 'C', 'H']])

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

if len(s)<3:
    print(0)
    exit()

ans = 0
for i, j, k in li:
    ans += s[i]*s[j]*s[k]
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())

march = ("M", "A", "R", "C", "H")
cnt = Counter()
for _ in range(N):
    S = input()
    if S[0] in march:
        cnt[S[0]] += 1

res = 0

for m in range(2):
    for a in range(2):
        for r in range(2):
            for c in range(2):
                for h in range(2):
                    if m+a+r+c+h == 3:
                        x = 1
                        if m:
                            x *= cnt["M"]
                        if a:
                            x *= cnt["A"]
                        if r:
                            x *= cnt["R"]
                        if c:
                            x *= cnt["C"]
                        if h:
                            x *= cnt["H"]
                        res += x

print(res)

Submission status: Accepted

Solution code:
from itertools import combinations
n = int(input())
s = [input()[0] for _ in range(n)]
c = [s.count(i) for i in 'MARCH']
print(sum(c[i]*c[j]*c[k] for i, j, k in combinations(range(5), 3)))

Submission status: Accepted

Solution code:
import itertools
from collections import Counter
n = int(input())
s = [input()[0] for _ in range(n)]
cnt = Counter(s)
#print(cnt)

ans = 0
for x,y,z in itertools.combinations("MARCH",3):
 # print(x,y,z)
  ans += cnt[x]*cnt[y]*cnt[z]
  #print(cnt[x],cnt[y],cnt[z])
        
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
c = {s: 0 for s in 'MARCH'}
for i in range(n):
    s = input()[0]
    if s in 'MARCH':
        c[s]+=1

c = [v for k, v in c.items()]

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

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    import collections
    import itertools
    N = int(input())
    Ss = [input()[0] for _ in range(N)]

    march_letter = [item for item in Ss if item in ['M', 'A', 'R', 'C', 'H']]
    march_cnt = collections.Counter(march_letter)

    if len(march_cnt) < 3:
        res = 0
    else:
        res_list = itertools.combinations(march_cnt.values(),3)

        res = 0
        for element in res_list:
            res += element[0]*element[1]*element[2]
    print(res)

if __name__ == "__main__":
    resolve()