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:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
INF = float("inf")
import sys
sys.setrecursionlimit(10000)


def solve(N, S):
    d = Counter([s[0] for s in S if s[0] in "MARCH"])
    ans = 0
    for comb in combinations("MARCH", 3):
        a = 1
        for c in comb:
            a *= d[c]
        ans += a
    return ans


def main():
    N = int(input())
    S = []
    for i in range(0, N):
        S.append(input())
    print(solve(N, S))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())

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

order = "MARCH"

initial_array = [name[0] for name in s]
nums = [initial_array.count(order[i]) for i in range(len(order))]

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

Submission status: Accepted

Solution code:
n = int(input())

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

order = "MARCH"

nums = [[name[0] for name in s].count(order[i]) for i in range(len(order))]

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

Submission status: Accepted

Solution code:
import sys
import itertools

with sys.stdin as f:
    s_input = f.read()

    s_args = s_input.splitlines()
    n = int(s_args[0])
    s = s_args[1:]

    a = len([nm for nm in s if nm.startswith("A")])
    c = len([nm for nm in s if nm.startswith("C")])
    h = len([nm for nm in s if nm.startswith("H")])
    m = len([nm for nm in s if nm.startswith("M")])
    r = len([nm for nm in s if nm.startswith("R")])
    
    #print([m, a, r, c, h])

    cmb = []
    if m > 0:
        cmb.append("m")
    if a > 0:
        cmb.append("a")
    if r > 0:
        cmb.append("r")
    if c > 0:
        cmb.append("c")
    if h > 0:
        cmb.append("h")

    res = 0
    pats = list(itertools.combinations(cmb, 3))
    for pat in pats:
        p_res = 1
        if 'm' in pat:
            p_res *= m
        if 'a' in pat:
            p_res *= a
        if 'r' in pat:
            p_res *= r
        if 'c' in pat:
            p_res *= c
        if 'h' in pat:
            p_res *= h
        res += p_res
        
    print(res)
            
sys.exit(0)

Submission status: Accepted

Solution code:
from collections import defaultdict
from itertools import combinations

d = defaultdict(int)

n = int(input())

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

a = list(d.values())

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
lis = [0,0,0,0,0]
n = int(input())
for i in range(n):
    a = input()
    if a[0] == "M":lis[0] += 1
    if a[0] == "A":lis[1] += 1
    if a[0] == "R":lis[2] += 1
    if a[0] == "C":lis[3] += 1
    if a[0] == "H":lis[4] += 1
ans = 0
for m in range(5):
    for l in range(5):
        if l > m:
            for h in range(5):
                if h > l:
                    ans += lis[m] * lis[l] *lis[h]
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import defaultdict
from itertools import combinations

d = defaultdict(int)

n = int(input())

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

a = list(d.items())

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
member = [0,0,0,0,0]
ans = 0
for _ in range(N):
    a = list(input())
    if a[0] == "M":
        member[0] += 1
    elif a[0] == "A":
        member[1] += 1
    elif a[0] == "R":
        member[2] += 1
    elif a[0] == "C":
        member[3] += 1
    elif a[0] == "H":
        member[4] += 1
 
for i in range(3):
    for j in range(i+1, 4):
        for k in range(j+1, 5):
            ans += member[i]*member[j]*member[k]

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
name_list = [input() for name in range(N)]
char_list = ['M', 'A', 'R', 'C', 'H']
count_list = [0 for _ in range(len(char_list))]

flag = False

for name in name_list:
    if name[0] in char_list:
        count_list[char_list.index(name[0])] += 1
score = 0
for x in range(5):
    for y in range(x + 1, 5):
        for z in range(y + 1, 5):
            score += count_list[x] * count_list[y] * count_list[z]

print(score)

Submission status: Accepted

Solution code:
import itertools
n = int(input())
arr = [input()[0] for i in range(n)]
word = ['M','A','R','C','H']
ans = 0
con = list(itertools.combinations(word,3))
for i in con:
    ans += arr.count(i[0]) * arr.count(i[1]) * arr.count(i[2])
print(ans)

Submission status: Accepted

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

S0 = list(map(lambda s:s[0],S))
M,A,R,C,H = 0,0,0,0,0

for i in range(len(S0)):
    if S0[i] == 'M':
        M = M + 1
    elif S0[i] == 'A':
        A = A + 1
    elif S0[i] == 'R':
        R = R + 1
    elif S0[i] == 'C':
        C = C + 1
    elif S0[i] == 'H':
        H = H + 1

Num = [M,A,R,C,H]


c = list(itertools.combinations(Num,3));
sum =0
for w in range(len(c)):
    sum = sum +c[w][0]*c[w][1]*c[w][2]
print(sum)

Submission status: Accepted

Solution code:
N = int(input())
num = [0,0,0,0,0]
answer = 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

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

print(answer)

Submission status: Accepted

Solution code:
#abc089c

n=int(raw_input())
m=a=r=c=h=0
for i in xrange(n):
 temp=raw_input()
 if temp[0]=='M':
  m+=1
 elif temp[0]=='A':
  a+=1
 elif temp[0]=='R':
  r+=1
 elif temp[0]=='C':
  c+=1
 elif temp[0]=='H':
  h+=1
s=[m,a,r,c,h]
res=0
for i in xrange(5):
 for j in xrange(i):
  for k in xrange(j):
   res+=s[i]*s[j]*s[k]
print res

Submission status: Accepted

Solution code:
import itertools
N = int(input())
S = [input() for i in range(N)]
listWork = list(set(S))
listMARCH = ["M","A","R","C","H"]
# print(int(listPat[0][0]))
listPat = list(itertools.combinations("01234", 3))
m,a,r,c,h = 0,0,0,0,0

def nCr():
    cnt = 0
    for i in range(len(listPat)):
        cnt += listMARCHcnt[int(listPat[i][0])] * listMARCHcnt[int(listPat[i][1])] * listMARCHcnt[int(listPat[i][2])]
    return cnt


for i in range(N):
    if listWork[i][0] in listMARCH[0]:
        m += 1
    elif listWork[i][0] in listMARCH[1]:
        a += 1
    elif listWork[i][0] in listMARCH[2]:
        r += 1
    elif listWork[i][0] in listMARCH[3]:
        c += 1
    elif listWork[i][0] in listMARCH[4]:
        h += 1

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

print(nCr())

Submission status: Accepted

Solution code:
import itertools as it
# -*- coding: utf-8 -*-
# 個数の入力
N = int(input())
# 改行区切りの名前の入力
S = []
for i in range(N):
    S.append(input())
# データの加工
for i in range(N):
	S[i] = S[i][0]

# 文字列カウント
count = [S.count('M'), S.count('A'), S.count('R'), S.count('C'), S.count('H')]

# 数え上げ
answer = count[0]*count[1]*count[2]
answer = count[0]*count[1]*count[3] + answer
answer = count[0]*count[1]*count[4] + answer
answer = count[0]*count[2]*count[3] + answer
answer = count[0]*count[2]*count[4] + answer
answer = count[0]*count[3]*count[4] + answer
answer = count[1]*count[2]*count[3] + answer
answer = count[1]*count[2]*count[4] + answer
answer = count[1]*count[3]*count[4] + answer
answer = count[2]*count[3]*count[4] + answer

# 出力
print(answer)

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
import sys
if __name__ == "__main__":
    n = int(input())
    s = [ input() for tmp in range(n) ]
    alphabetDic = { alphabet : 0 for alphabet in [ chr(tmp) for tmp in range(ord('A'), ord('A')+26) ] }
    ans = 0
    for word in s:
        alphabetDic[word[0]] += 1
    factors = [ alphabetDic[tmp] for tmp in ['M', 'A', 'R', 'C', 'H'] if alphabetDic[tmp] > 0 ]
    if len(factors) <= 2:
        print(ans)
        sys.exit()
    for tmp in range(len(factors)):
        for tmp2 in range(tmp+1, len(factors)):
            for tmp3 in range(tmp2+1, len(factors)):
                ans += factors[tmp]*factors[tmp2]*factors[tmp3]
    else:
        print(ans)

Submission status: Accepted

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

if __name__ == "__main__":
	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
	# 3人を選ぶ方法を全探索する
	ans  = m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h
	ans += a*r*c + a*r*h + a*c*h
	ans += r*c*h
	print(ans)

Submission status: Accepted

Solution code:
import re

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

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

for i in S:
    M = re.match("M",i)
    A = re.match("A",i)
    R = re.match("R",i)
    C = re.match("C",i)
    H = re.match("H",i)

    if M:
        m += 1
    if A:
        a += 1
    if R:
        r += 1
    if C:
        c += 1
    if 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 ="MARCH"
S2 = [0]*len(S)
n=0

for i in range(N):
    s = input()
    for k, j in enumerate(S):
        if s[0] == j:
            S2[k]+=1
            
for i in range(len(S2)):
    for j in range(i+1,len(S2)):
        for k in range(j+1,len(S2)):
            n +=S2[i]*S2[j]*S2[k]
    
print(n)

Submission status: Accepted

Solution code:
N = int(raw_input())
Names = []
n_M, n_A, n_R, n_C, n_H = 0,0,0,0,0
for i in range(N):
	Name = raw_input()
	if Name[0] == "M":
		n_M += 1
	if Name[0] == "A":
		n_A += 1
	if Name[0] == "R":
		n_R += 1
	if Name[0] == "C":
		n_C += 1
	if Name[0] == "H":
		n_H += 1

C = (n_M * n_A * n_R + 
	n_M * n_A * n_C +
	n_M * n_A * n_H +
	n_M * n_R * n_C +
	n_M * n_R * n_H +
	n_M * n_C * n_H +
	n_A * n_R * n_C +
	n_A * n_R * n_H +
	n_A * n_C * n_H +
	n_R * n_C * n_H
	)

print C

Submission status: Accepted

Solution code:
import itertools

n = int(input())

T = 'MARCH'
ct = [0 for _ in range(5)]
for _ in range(n):
    s = input()
    if s[0] not in T:
        continue
    ct[T.find(s[0])] += 1

ans = 0
for x,y,z in itertools.combinations(ct,3):
    ans += x*y*z
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
N = int(input())
march = ['M','A','R','C','H']
dic = {}
for i in range(N):
	s = input()
	if s[0] in march:
		if s[0] in dic:
			dic[s[0]] += 1
		else:
			dic[s[0]] = 1

ans = 0
if len(dic.keys()) < 3:
	print(0)
else:
	for tup in combinations(dic.values(),3):
		#print(tup)
		ans += (tup[0] * tup[1] * tup[2])

	print(ans)

Submission status: Accepted

Solution code:
import itertools

N = int(input())
key = "MARCH"
S = [x for x in [input() for i in range(N)] if x[0] in key]
march = {}
for x in S:
    march.setdefault(x[0], []).append(x)

sizes = [len(x) for x in march.values()]
print(sum([a*b*c for a, b, c in itertools.combinations(sizes, 3)]))

Submission status: Accepted

Solution code:
import itertools
import sys

N = int(input())
key = "MARCH"
S = [x for x in [input() for i in range(N)] if x[0] in key]
march = {}
for x in S:
    march.setdefault(x[0], []).append(x)

if len(march) < 3:
    print(0)
    sys.exit()
    
sizes = [len(x) for x in march.values()]
print(sum([a*b*c for a, b, c in itertools.combinations(sizes, 3)]))

Submission status: Accepted

Solution code:
import itertools
import sys

N = int(input())
key = ["M", "A", "R", "C", "H"]
S = [x for x in [input() for i in range(N)] if x[0] in key]
march = {}
for x in S:
    march.setdefault(x[0], []).append(x)

if len(march) < 3:
    print(0)
    sys.exit()

sizes = [len(x) for x in march.values()]

print(sum([a*b*c for a, b, c in itertools.combinations(sizes, 3)]))

Submission status: Accepted

Solution code:
from itertools import combinations as c
from operator import mul
d = {k: 0 for k in 'MARCH'}
for _ in xrange(input()):
    n = raw_input()[0]
    if n in 'MARCH':
        d[n] += 1
r = [k for k, v in d.iteritems() if v]
print sum([reduce(mul, [d[k] for k in _]) for _ in c(r, 3)])

Submission status: Accepted

Solution code:
import math
import numpy as np
from operator import mul

# 整数Nを桁ごとのリストにする
# l = [int(x) for x in list(str(N))]

# 入力が文字のリスト
# S = list(input().split())

#入力が数字のリスト
# A = list(map(int, input().split()))

# 入力がリストのリスト
# S = [list(input()) for i in range(H)]


# リストliから重複を削除したリストli_uniqを作成
#li_uniq = []
#for i in li:
#    if x not in li_uniq:
#        li_uniq.append(x)

# 複数行のinput - list版
#list = [list(map(int, input().split())) for i in range(N)]
# 複数行のinput - dictionary版
# key = a, value = b
#for i in range(N):
#    a, b = map(int, input().split())
#    dict[a] = b


N = int(input())

# 名前の頭文字のリスト
S = [input()[0] for i in range(N)]

# M, A, R, C, Hで始まる人の人数
headers = [0,0,0,0,0]

# M, A, R, C, Hから3文字選ぶ組み合わせ＝10通り
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 i in range(N):
    if S[i] == 'M':
        headers[0] += 1
    if S[i] == 'A':
        headers[1] += 1
    if S[i] == 'R':
        headers[2] += 1
    if S[i] == 'C':
        headers[3] += 1
    if S[i] == 'H':
        headers[4] += 1

count = 0

for i in range(10):
    count += headers[P[i]] * headers[Q[i]] * headers[R[i]]

print(count)

Submission status: Accepted

Solution code:
import math
def kumi(s, n):
    count = 1
    for x in range(s, s - n, -1):
        count *= x
    ret = count // math.factorial(n)
    return ret

def main():
    N = int(input().strip())
    S = []
    D = {}
    for _ in range(N):
        in_s = (input().strip())[0]
        if in_s in ['M','A','R','C','H']:
            S.append(in_s)
            D[in_s] = D.get(in_s, 0) + 1

    if not S or len(D.keys()) < 3:
        return 0

    
    # 組み合わせ数
    count = kumi(len(S), 3)
    # 重複削除
    for v in D.values():
        if v < 2:
            continue
        elif v == 2:
            count -= len(S) - v
        else:
            count -= kumi(v, 2) * (len(S) - v)
            count -= kumi(v, 3)
    return count

if __name__ == '__main__':
    print(main())

Submission status: Accepted

Solution code:
N = int(input())
march = [0]*5
for i in range(N):
    tmp = input()
    if tmp[0]=='M':
        march[0] +=1
    elif tmp[0]=='A':
        march[1] +=1
    elif tmp[0]=='R':
        march[2] +=1
    elif tmp[0]=='C':
        march[3] +=1
    elif tmp[0]=='H':
        march[4] +=1
sum = 0
sum += march[0]*march[1]*march[2]
sum += march[0]*march[1]*march[3]
sum += march[0]*march[1]*march[4]
sum += march[0]*march[2]*march[3]
sum += march[0]*march[2]*march[4]
sum += march[0]*march[3]*march[4]
sum += march[1]*march[2]*march[3]
sum += march[1]*march[2]*march[4]
sum += march[1]*march[3]*march[4]
sum += march[2]*march[3]*march[4]
print(sum)

Submission status: Accepted

Solution code:
import itertools
def main():
    n = int(input())
    A = [0 for i in range(5)]
    for _ in range(n):
        s = input()
        if s[0] in "MARCH":
            A["MARCH".index(s[0])] += 1
    ans = 0
    for i, j, k in itertools.combinations(range(5), 3):
        ans += A[i] * A[j] * A[k]
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import itertools
def main():
    n = int(input())
    A = [0 for i in range(5)]
    for _ in range(n):
        s = input()
        if s[0] in "MARCH":
            A["MARCH".index(s[0])] += 1
    ans = 0
    for i, j, k in itertools.combinations(range(5), 3):
        ans += A[i] * A[j] * A[k]
    print(ans)



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import itertools
def main():
    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

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

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())

march = [0, 0, 0, 0, 0]

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

result = 0
result += march[0] * march[1] * march[2]
result += march[0] * march[1] * march[3]
result += march[0] * march[1] * march[4]

result += march[0] * march[2] * march[3]
result += march[0] * march[2] * march[4]

result += march[0] * march[3] * march[4]

result += march[1] * march[2] * march[3]
result += march[1] * march[2] * march[4]

result += march[1] * march[3] * march[4]

result += march[2] * march[3] * march[4]

print(result)

Submission status: Accepted

Solution code:
import itertools
n = int(input())

array = []
dict = {}
dict["M"] = dict["A"] = dict["R"] = dict["C"] = dict["H"] = 0
for i in range(n):
    tmp = input()
    dict[tmp[0]] = dict.get(tmp[0], 0) + 1

m = dict["M"]
a = dict["A"]
r = dict["R"]
c = dict["C"]
h = dict["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:
N = int(input())
M=0
A=0
R=0
C=0
H=0
namelist=[]
for _ in range(N):
    namelist.append(str(input()))
for i in range(N):
    if namelist[i][0] == "M":
      M += 1
    elif namelist[i][0] == "A":
      A += 1
    elif namelist[i][0] == "R":
      R += 1
    elif namelist[i][0] == "C":
      C += 1
    elif namelist[i][0] == "H":
      H += 1
    else:
       pass
num= 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(num)

Submission status: Accepted

Solution code:
N = int(input())
S = [input() for i in range(N)]
a = [0] * 5
for i in range(N):
    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

ans = 0
for i in range(1<<5):
    if bin(i).count('1') != 3:
        continue
    tmp = 1
    for j in range(5):
        if i & (1<<j):
            tmp *= a[j]
    ans += tmp
print(ans)

Submission status: Accepted

Solution code:
import itertools
n=int(input())
data=[0,0,0,0,0]
for i in range(n):
    s=input()
    if(s[0]=='M'):
        data[0]+=1
    if(s[0]=='A'):
        data[1]+=1
    if(s[0]=='R'):
        data[2]+=1
    if(s[0]=='C'):
        data[3]+=1
    if(s[0]=='H'):
        data[4]+=1
ans=0
for x,y,z in itertools.combinations(range(5),3):
    ans+=data[x]*data[y]*data[z]
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
U=list()
for i in range(n):
	i=input()
	U.append(i)
m=a=r=c=h=0
for x in U:
	if x[0]=='M':
		m+=1
	if x[0]=='A':
		a+=1
	if x[0]=='R':
		r+=1
	if x[0]=='C':
		c+=1
	if x[0]=='H':
		h+=1
sig=(m+a+r)*c*h+m*a*(r+c+h)+(m+a)*r*(c+h)
print(sig)

Submission status: Accepted

Solution code:
def kaijou(a):
    kai = 1
    for i in range(a):
        kai = kai * (i+1)
    return kai

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

    count = [0,0,0,0,0]
    initial = "MARCH"

    for i in range(5):
        for s in S:
            if s[0] == initial[i]:
                count[i] += 1

    k = 3
    kumiawase = 0
    for i in range(len(initial)-(k-1)):
        for j in range(i+1, len(initial)-1):
            kumiawase += count[i]*count[j]*sum(count[j+1:])

    return int(kumiawase)

if __name__ == "__main__":
    print(main())

Submission status: Accepted

Solution code:
N=int(input())
s=['M','A','R','C','H']
a=[]
b=[]
ans=0
for i in range(N):
    buf=str(input())
    a.append(buf[0])

for i in s:
    b.append(a.count(i))

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
march_count = [0 for i in range(5)]
march_dict = {'M': 0, 'A': 1, 'R': 2, 'C': 3, 'H': 4}


for i in range(N):
    c = input()[0]
    if c in march_dict:
        march_count[march_dict[c]] += 1

count = 0


def calc(a, b, c):
    return march_count[a] * march_count[b] * march_count[c]

# 10通りの組み合わせをすべて計算
count = calc(0, 1, 2) + calc(0, 1, 3) + calc(0, 1, 4) \
    + calc(0, 2, 3) + calc(0, 2, 4) + calc(0, 3, 4) \
    + calc(1, 2, 3) + calc(1, 2, 4) + calc(1, 3, 4) \
    + calc(2, 3, 4)

print(count)

Submission status: Accepted

Solution code:
N = int(raw_input())

line = ['a' for i in range(N)]

lis = [ 0 for i in range(5)]

for i in range(N):
    lit = raw_input()
    if lit[0] == 'M':
        lis[0] += 1
    elif lit[0] == 'A':
        lis[1] += 1
    elif lit[0] == 'R':
        lis[2] += 1
    elif lit[0] == 'C':
        lis[3] += 1
    elif lit[0] == 'H':
        lis[4] += 1

tot = (lis[0] * lis[1] * (lis[2] + lis[3] + lis[4]) + lis[0] * lis[2] * (lis[3] + lis[4]) + lis[0] * lis[3] * lis[4] + 
       lis[1] * lis[2] * (lis[3] + lis[4]) + lis[1] * lis[3] * lis[4] + lis[2] * lis[3] * lis[4])

print tot

Submission status: Accepted

Solution code:
N = int(input())
S = [input() for i in range(N)]
L = [[],[],[],[],[]]
for i in S:
    if i[0]=="M":
        L[0].append(i)
    elif i[0]=="A":
        L[1].append(i)
    elif i[0]=="R":
        L[2].append(i)
    elif i[0]=="C":
        L[3].append(i)
    elif i[0]=="H":
        L[4].append(i)
import itertools
a = [i for i in range(5)]
T = list(itertools.combinations(a,3))
M = 0
for k in T:
    M += len(L[k[0]])*len(L[k[1]])*len(L[k[2]])
print(M)

Submission status: Accepted

Solution code:
import itertools
import collections
n = int(input())
c = collections.Counter([input()[0] for i in range(n)])
s = [c[x] for x in 'MARCH']

cnt = 0
for x in itertools.combinations(s, 3):
    cnt += x[0] * x[1] * x[2]
print(cnt)

Submission status: Accepted

Solution code:
from itertools import combinations
from functools import reduce
from operator import mul

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

count = [0] * 5
for i, c in enumerate("MARCH"):
    count[i] = len(list(filter(lambda n: n[0] == c, S_row)))

print(sum(map(lambda x: reduce(mul, x), combinations(count, 3))))

Submission status: Accepted

Solution code:
n=int(input())
s=[]
m=0
a=0
r=0
c=0
h=0
for i in range(n):
  b=str(input())[0]
  if b=="M":m+=1
  elif b=="A":a+=1
  elif b=="R":r+=1
  elif b=="C":c+=1
  elif b=="H":h+=1
  s.append(b)

ans=0

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

Submission status: Accepted

Solution code:
N=int(input())
S=[input() for i in range(N)]
m=len([s for s in S if s[0]=='M'])
a=len([s for s in S if s[0]=='A'])
r=len([s for s in S if s[0]=='R'])
c=len([s for s in S if s[0]=='C'])
h=len([s for s in S if s[0]=='H'])
count=0
march=[m,a,r,c,h]
for x in range(0,3):
    for y in range(x+1,4):
          for z in range(y+1,5):
                count+=march[x]*march[y]*march[z]
print(count)

Submission status: Accepted

Solution code:
N = int(input())
relevant = {"M":0,
            "A":0,
            "R":0,
            "C":0,
            "H":0}

for i in range(N):
    name = input()
    try:
        relevant[name[0]] += 1
    except:
        pass

chars = [key for key in relevant.keys() if relevant[key] != 0]
ans = 0
for i in range(len(chars)):
    for j in range(i+1,len(chars)):
        for k in range(j+1,len(chars)):
            ans += relevant[chars[i]] * relevant[chars[j]] * relevant[chars[k]]
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict                              

n = int(input())
name_count_dic = defaultdict(int)

for i in range(n):
    name = input()
    if name.startswith('M'):
        name_count_dic['M'] += 1
    elif name.startswith('A'):
        name_count_dic['A'] += 1
    elif name.startswith('R'):
        name_count_dic['R'] += 1
    elif name.startswith('C'):
        name_count_dic['C'] += 1
    elif name.startswith('H'):
        name_count_dic['H'] += 1

count_list = list(name_count_dic.values())
char_num = len(count_list)
if char_num < 3:
    num = 0 
else:
    num = 0 
    for i in range(char_num - 2): 
        for j in range(i + 1, char_num - 1): 
            for k in range(j + 1, char_num):
                num += count_list[i] * count_list[j] * count_list[k]

print(num)

Submission status: Accepted

Solution code:
n = int(input())
d = {}
for _ in range(n):
    h = input()[0]
    if h in 'MARCH':
        d[h] = d.get(h, 0) + 1
a = list(d.values())
r = 0
for i in range(len(a)):
    for j in range(i+1, len(a)):
        for k in range(j+1, len(a)):
            r += a[i]*a[j]*a[k]
print(r)

Submission status: Accepted

Solution code:
from collections import Counter
from itertools import combinations

n = int(input())
l = Counter(input()[0] for _ in range(n))
con = [l[c] for c in 'MARCH' if c in l]
print(sum(a * b * c for a, b, c in combinations(con, 3)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

nM = 0
nA = 0
nR = 0
nC = 0
nH = 0
Ans = 0

for i in range(N):
    S = input()
    Word = S[0]
    
    if Word =='M':
        nM += 1 
    elif Word =='A':
        nA += 1 
    elif Word =='R':
        nR += 1 
    elif Word =='C':
        nC += 1 
    elif Word =='H':
        nH += 1 

Ans = nM * (nA * (nR + nC + nH) + nR * (nC + nH) + nC * nH) + nA * (nR * (nC + nH) + nC * nH) + nR * nC * nH

print(Ans)

Submission status: Accepted

Solution code:
import itertools

n = int(raw_input())
li = list()
for m in range(0,n):
    li.append(raw_input())

m = len(filter(lambda x: x[0]=="M" ,li))
a = len(filter(lambda x: x[0]=="A" ,li))
r = len(filter(lambda x: x[0]=="R" ,li))
c = len(filter(lambda x: x[0]=="C" ,li))
h = len(filter(lambda x: x[0]=="H" ,li))

con = [m, a, r, c, h]
print sum(map(lambda x: x[0]*x[1]*x[2] , list(itertools.combinations(con, 3))))

Submission status: Accepted

Solution code:
from collections import Counter
from itertools import combinations

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

xs = Counter(s[0] for s in S)

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

Submission status: Accepted

Solution code:
n=int(input())
s=[input()for i in range(n)]
count_m=count_a=count_r=count_c=count_h=0
for i in s:
    if i[0]=="M":
        count_m+=1
    if i[0]=="A":
        count_a+=1
    if i[0]=="R":
        count_r+=1
    if i[0]=="C":
        count_c+=1
    if i[0]=="H":
        count_h+=1
ans_1=count_m*count_a*count_r
ans_2=count_m*count_a*count_c
ans_3=count_m*count_a*count_h
ans_4=count_m*count_r*count_c
ans_5=count_m*count_r*count_h
ans_6=count_m*count_c*count_h
ans_7=count_a*count_r*count_c
ans_8=count_a*count_r*count_h
ans_9=count_a*count_c*count_h
ans_10=count_r*count_c*count_h
print(ans_1+ans_2+ans_3+ans_4+ans_5+ans_6+ans_7+ans_8+ans_9+ans_10)

Submission status: Accepted

Solution code:
import sys

N = int(input())
S=[]

m = 0
a = 0
r = 0
c = 0
h = 0
for i in range(N):
    tmp = input()
    if tmp[0:1] == "M": # 先頭一文字
      m += 1
      S.append(tmp[0:1]) 
    elif tmp[0:1] == "A":
      a += 1
      S.append(tmp[0:1]) 
    elif tmp[0:1] == "R":
      r += 1
      S.append(tmp[0:1]) 
    elif tmp[0:1] == "C":
      c += 1
      S.append(tmp[0:1]) 
    elif tmp[0:1] == "H":
      h += 1
      S.append(tmp[0:1]) 

# 重複を削除
editedArray = list(set(S))

if len(editedArray) < 3:
  print(0)
  sys.exit()

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

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 = [s for s in S.values() if s != 0]

mul = functools.reduce(lambda a, x: a * x, aS, 1)
ans = 0
if len(aS) == 3:
    ans = mul
elif len(aS) == 4:
    ans = functools.reduce(lambda a, x: a + mul/x, aS, 0)
elif len(aS) == 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:
from collections import defaultdict
from itertools import combinations

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

CHARS = "MARCH"

xs = defaultdict(int)

for s in S:
    xs[s[0]] += 1

def calc(xs):
    return sum(xs[a] * xs[b] * xs[c] for a, b, c in combinations(CHARS, 3))

print(calc(xs))

Submission status: Accepted

Solution code:
from itertools import combinations

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

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

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

print(res)