Problem:


Score : 300 points

Problem Statement

There are N people. The name of the i-th person is S_i.

We would like to choose three people so that the following conditions are met:

The name of every chosen person begins with M, A, R, C or H.

There are no multiple people whose names begin with the same letter.

How many such ways are there to choose three people, disregarding order?

Note that the answer may not fit into a 32-bit integer type.

Constraints

1 \leq N \leq 10^5

S_i consists of uppercase English letters.

1 \leq |S_i| \leq 10

S_i \neq S_j (i \neq j)

Input

Input is given from Standard Input in the following format:

N
S_1
:
S_N

Output

If there are x ways to choose three people so that the given conditions are met, print x.

Sample Input 1

5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI

Sample Output 1

2

We can choose three people with the following names:

MASHIKE, RUMOI, HABORO

MASHIKE, RUMOI, HOROKANAI

Thus, we have two ways.

Sample Input 2

4
ZZ
ZZZ
Z
ZZZZZZZZZZ

Sample Output 2

0

Note that there may be no ways to choose three people so that the given conditions are met.

Sample Input 3

5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO

Sample Output 3

7



Sample input:
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI


Sample output:
2

Submission status: Accepted

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

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

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

# print(count)

H=['M','A','R','C','H']
res = 0
for i in range(0,5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            cnt = count[H[i]] * count[H[j]] * count[H[k]]
            # print(i,j,k,cnt)
            res += cnt

print(res)

Submission status: Accepted

Solution code:
# 人数を入力する
N = int(input())
# 名前を入力する
S = [input() for _ in range(N)]
# 単語をwordとする
word = "MARCH"
# 単語の文字数をsとする
n = len(word)
# 単語の各文字を頭文字とする人数を格納する辞書を初期化する
dic_initial = dict()
for letter in word:
    dic_initial[letter] = 0
# 単語の各文字を頭文字とする人数を調べる
for i in range(N):
    # 頭文字が単語の各文字のいずれかである場合
    if S[i][0] in dic_initial:
        # dic_initial内の人数を更新する
        dic_initial[S[i][0]] += 1
# 人の選び方の組み合わせの数を初期化する
ans = 0
# 3つの文字の組み合わせ全てについて、人の選び方の組み合わせの数を調べる
for p in range(n - 2):
    # 単語の頭からp番目の文字を頭文字とする人の数をnum_pとする
    num_p = dic_initial[word[p]]
    # num_pが0の場合、以降の処理は行わず、次の繰り返しに移る
    if num_p == 0:
        continue
    for q in range(p + 1, n - 1):
        num_q = dic_initial[word[q]]
        if num_q == 0:
            continue
        for r in range(q + 1, n):
            num_r = dic_initial[word[r]]
            ans += num_p * num_q * num_r
# 出力する
print(ans)

Submission status: Accepted

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

t_moji = ['M', 'A', 'R', 'C', 'H']
moji = {'M': 0, 'A': 1, 'R':2, 'C': 3, 'H': 4}
buff = [0 for i in range(5)]

for i in range(N):
    flag = False
    for j in range(5):
        if t_moji[j] == S[i][0]:
            flag = True
    if flag:
        buff[moji[S[i][0]]] += 1


# print(buff)
# k = [1, 1, 1, 1, 3, 6]
count = 0
for i in range(5):
    if buff[i] > 0:
        count += 1

if count < 3:
    print(0)
    exit()
else:
    # ans = cmb(count, 3)
    ans = 0
    for i in range(5):
        for j in range(5):
            if i != j:
                for k in range(5):
                    if i != k and j != k:
                        ans += buff[i] * buff[j] * buff[k]
    print(ans//6)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#ABC89 C

import math

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

m,a,r,c,h = 0,0,0,0,0
for i in s:
    if i[0] == 'M':m += 1
    elif i[0] == 'A':a+= 1
    elif i[0] == 'R':r += 1
    elif i[0] == 'C':c += 1
    elif i[0] == 'H':h += 1

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:
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
  if s[0] == "A":
    a += 1
  if s[0] == "R":
    r += 1
  if s[0] == "C":
    c += 1
  if s[0] == "H":
    h += 1
A = [m,a,r,c,h]
ans = 0
for i in range(5):
  for j in range(min(i+1,5),5):
    for k in range(min(j+1,5),5):
      ans += A[i]*A[j]*A[k]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
d = {'M':0,'A':0,'R':0,'C':0,'H':0} 
for _ in range(N):
    c = input()[0]
    if c in 'MARCH':d[c] +=  1
gl = [d['M']*d['A']*d['R'],
        d['M']*d['A']*d['C'],
        d['M']*d['A']*d['H'],
        d['M']*d['R']*d['C'],
        d['M']*d['R']*d['H'],
        d['M']*d['C']*d['H'],
        d['A']*d['R']*d['C'],
        d['A']*d['R']*d['H'],
        d['A']*d['C']*d['H'],
        d['R']*d['C']*d['H']]
print(sum(gl))

Submission status: Accepted

Solution code:
n=int(input())
da=[input() for i in range(n)]
st='MARCH'
gg=[0 for i in range(5)]
for i in da:
    for j in range(5):
        if i[0]==st[j]:
            gg[j]+=1
ans=0
for i in range(2,5):
    for j in range(1,i):
        for k in range(0,j):
            ans+=gg[i]*gg[j]*gg[k]
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations

n = int(input())
D = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for _ in range(n):
    s = input()[0]
    if s in D:
        D[s] += 1
print(sum([i * j * k for i, j, k in combinations(D.values(), 3)]))

Submission status: Accepted

Solution code:
n = int(input())
D = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for _ in range(n):
    s = input()
    k = s[0]
    if k in D:
        D[k] += 1
L = list(D.values())
ans = 0
for i in range(len(L) - 2):
    for j in range(i + 1, len(L) - 1):
        for k in range(j + 1, len(L)):
            ans += L[i] * L[j] * L[k]
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import sys
import math
from collections import Counter
input = sys.stdin.readline

def P(n, r):
    return math.factorial(n)//math.factorial(n-r)

def C(n, r):
    return P(n, r)//math.factorial(r)

N = int(input())
arr = [input() for i in range(N)]
ini_arr = [j[0] for j in arr if j[0] == "M" or j[0] == "A" or j[0] == "R" or j[0] == "C" or j[0] == "H"]
dic = Counter(ini_arr)
key_num = len(dic)
val_num = sum(k for k in dic.values())
if key_num < 3:
    print(0)
else:
    total = C(len(ini_arr), 3)
    for i in dic.values():
        if i == 2:
            total -= C(val_num - i, 1)
        elif i >= 3:
            total -= C(i, 2) * C(val_num - i, 1)  + C(i, 3)
    print(total)

Submission status: Accepted

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

count = [0]*5
countType = 0
    

for i in range(N):
    if S[i][0]  =='M':
        count[0]  = count[0] + 1
        if count[0] == 1:
            countType = countType+1
    elif S[i][0]  =='A':
        count[1]  = count[1] + 1
        if count[1] == 1:
            countType = countType+1
    elif S[i][0]  =='R':
        count[2]  = count[2] + 1
        if count[2] == 1:
            countType = countType+1
    elif S[i][0]  =='C':
        count[3]  = count[3] + 1
        if count[3] == 1:
            countType = countType+1
    elif S[i][0]  =='H':
        count[4]  = count[4] + 1
        if count[4] == 1:
            countType = countType+1
            
if countType<3:
    print(0)
else:
    ans = 1
    buf =  0
    LIST = list(itertools.combinations([0,1,2,3,4],3))
    for i in range(len(LIST)):
        for j in range(len(LIST[i])):
            ans = ans*count[LIST[i][j]]
        buf = buf + ans
        ans = 1
    print(buf)

Submission status: Accepted

Solution code:
letterlist = ['M', 'A', 'R', 'C', 'H']
countlist = [0, 0, 0, 0, 0]
N = int(input())
for i in range(0, N):
	S = input()
	for j in range(0, 5):
		if S[0] == letterlist[j]:
			countlist[j] += 1
sum = 0
for i in range(0, 5):
	for j in range(i+1, 5):
		for k in range(j+1, 5):
			sum += countlist[i]*countlist[j]*countlist[k]
print(sum)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import sys
input = sys.stdin.readline

n = int(input())
t = [0] * n
for i in range(n):
    t[i] =input()[0]
t2 = [t.count(i) for i in ["M","A","R","C","H"]]
ans = 0
for i in range(5):
    for j in range(5):
        if j == i:
            break
        for k in range(5):
            if k == j:
                break
            ans += t2[i] * t2[j] * t2[k]
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
march=['M','A','R','C','H']
s=[input() for _ in range(n)]
m=[]
a=[]
r=[]
c=[]
h=[]
for i in s:
    if i[0]=='M':
        m.append(i)
    elif i[0]=='A':
        a.append(i)
    elif i[0]=='R':
        r.append(i)
    elif i[0]=='C':
        c.append(i)
    elif i[0]=='H':
        h.append(i)
m=list(set(m))
a=list(set(a))
r=list(set(r))
c=list(set(c))
h=list(set(h))
l=[len(m),len(a),len(r),len(c),len(h)]
ans=0
rr=[]
if l.count(0)<=2:
    ll=[i for i in l if i>=1]
    ans=1
    if len(ll)==3:
        for i in ll:
            ans*=i
    elif len(ll)==4:
        for i in range(2):
            for j in range(i+1,3):
                for k in range(j+1,4):
                    rr.append(ll[i]*ll[j]*ll[k])
        ans=sum(rr)
    else:
        for i in range(3):
            for j in range(i+1,4):
                for k in range(j+1,5):
                    rr.append(ll[i]*ll[j]*ll[k])
        ans=sum(rr)
print(ans)

Submission status: Accepted

Solution code:
import sys
from itertools import combinations
#input=sys.stdin.readline

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

ans=0

cmb=list(combinations(s.values(),3))

for a,b,c in cmb:
    ans+=a*b*c

print(ans)

Submission status: Accepted

Solution code:
import sys
from itertools import combinations
input=sys.stdin.readline

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

ans=0

cmb=list(combinations(s.values(),3))

for a,b,c in cmb:
    ans+=a*b*c

print(ans)

Submission status: Accepted

Solution code:
# 2019/07/06

import sys

input=sys.stdin.readline

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

# ↑ここまでできた
# ↓ここからわからん

ans=0
for ik,iv in s.items():
    for jk,jv in s.items():
        if ik==jk:break
        for kk,kv in s.items():
            if jk==kk:break
            ans+=iv*jv*kv

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
t=[0]*n
for i in range(n):
    t[i] =input()[0]
t2=[t.count(i) for i in ["M","A","R","C","H"]]
ans=0
for i in range(5):
    for j in range(5):
        if j==i:break
        for k in range(5):
            if k==j:break
            ans += t2[i]*t2[j]*t2[k]
print(ans)

Submission status: Accepted

Solution code:
from functools import reduce
from operator import mul


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

    r = min(n-r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


def solve(n):
    # 12 17 0 2 7
    p = [set() for _ in range(27)]
    for i in range(n):
        s = input()
        p[ord(s[0])-65].add(s)

    sum_of_elems = len(p[12])+len(p[17])+len(p[0])+len(p[2])+len(p[7])
    all_cmb = cmb(sum_of_elems, 3)

    for j in [12, 17, 0, 2, 7]:
        count_of_elem = len(p[j])
        all_cmb -= cmb(count_of_elem, 2) * (sum_of_elems - count_of_elem)
        all_cmb -= cmb(count_of_elem, 3)

    return all_cmb


if __name__ == '__main__':
    n = int(input())
    print(solve(n))

Submission status: Accepted

Solution code:
N = int(input())
S = list(input() for i in range(N))
march = "MARCH"
A = [0]*5
for i in S:
    if i[0] in march:
        A[march.index(i[0])]+=1
ans = 0
for i in range(5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            ans += A[i]*A[j]*A[k]
print(ans)

Submission status: Accepted

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

ans = 0
ans += march[0]*march[1]*march[2]
ans += march[0]*march[1]*march[3]
ans += march[0]*march[1]*march[4]
ans += march[0]*march[2]*march[3]
ans += march[0]*march[2]*march[4]
ans += march[0]*march[3]*march[4]
ans += march[1]*march[2]*march[3]
ans += march[1]*march[2]*march[4]
ans += march[1]*march[3]*march[4]
ans += march[2]*march[3]*march[4]
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

dict={"M":0, "A":0, "R":0, "C":0, "H":0}
dickey=list(dict.keys())
for i in range(n):
    if s[i][0] in dict:
        dict[s[i][0]]+=1

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools

N=int(input())
march='MARCH'
S=[]
counter={'M':0,'A':0,'R':0,'C':0,'H':0}
for _ in range(N):
    s=input()
    if s[0] in march:
        counter[s[0]]+=1
        S.append(s)
ans=0
if len(S)>=3:
    select=list(itertools.combinations(march,3))
    for i in range(len(select)):
        key=[]
        key.append(select[i][0])
        key.append(select[i][1])
        key.append(select[i][2])
        ans+=counter[key[0]]*counter[key[1]]*counter[key[2]]
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
N = int(input())
L = [input()[0] for _ in range(N)]

ans = sum(x * y * z for x,y,z in combinations([L.count(s) for s in "MARCH"], 3))
print(ans)

Submission status: Accepted

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

M = 0
A = 0
R = 0
C = 0
H = 0
for i in range(N):
    tmp = S[i][0]
    if tmp == 'M':
        M += 1
    elif tmp == 'A':
        A += 1
    elif tmp == 'R':
        R += 1
    elif tmp == 'C':
        C += 1
    elif tmp == 'H':
        H += 1
P = [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 += P[i]*P[j]*P[k]
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
S=[input()[0] for _ in range(N)]
from collections import Counter
S=Counter(S)
M=S["M"]
A=S["A"]
R=S["R"]
C=S["C"]
H=S["H"]
print(M*A*(R+C+H)+(M+A)*R*(C+H)+(M+A+R)*C*H)

Submission status: Accepted

Solution code:

cha = "MARCH"
dic = {}

N = int(input())

for i in range(N):

    S = input()

    if S[0] in cha and S[0] not in dic:

        dic[S[0]] = 1

    elif S[0] in cha:

        dic[S[0]] += 1

ans = 0

for i in dic:

    for j in dic:

        if i == j:
            break

        for k in dic:

            if j == k or i == k:
                break

            ans += dic[i]*dic[j]*dic[k]

print (ans)

Submission status: Accepted

Solution code:
N = int(input())
S = []
for n in range(N):
  s = input()
  if s[0] in "MARCH":
    S.append(s[0])
S_set = list(set(S))
if len(S_set) < 3:
  ans = 0
elif len(S_set) == 3:
  ans = S.count(S_set[0]) * S.count(S_set[1]) * S.count(S_set[2])
elif len(S_set) == 4:
  ans = 0
  T = [S.count(S_set[0]), S.count(S_set[1]), S.count(S_set[2]), S.count(S_set[3])]
  for i in [0, 1]:
    for j in range(i+1, len(T)-1):
      for k in range(j+1, len(T)):
        ans += T[i] * T[j] * T[k]
elif len(S_set) == 5:
  ans = 0
  T = [S.count(S_set[0]), S.count(S_set[1]), S.count(S_set[2]), S.count(S_set[3]), S.count(S_set[4])]
  for i in [0, 1, 2]:
    for j in range(i+1, len(T)-1):
      for k in range(j+1, len(T)):
        ans += T[i] * T[j] * T[k]

print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations

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

m = []
a = []
r = []
c = []
h = []
for i in range(N):
    if S[i][0] == 'M':
        m.append(S[i])
    elif S[i][0] == 'A':
        a.append(S[i])
    elif S[i][0] == 'R':
        r.append(S[i])
    elif S[i][0] == 'C':
        c.append(S[i])
    elif S[i][0] == 'H':
        h.append(S[i])

cnt = []
cnt.append(len(m))
cnt.append(len(a))
cnt.append(len(r))
cnt.append(len(c))
cnt.append(len(h))

com = list(combinations(range(5), 3))

ans = 0
for i in com:
    ans += cnt[i[0]]*cnt[i[1]]*cnt[i[2]]
print(ans)

Submission status: Accepted

Solution code:
import itertools

n = int(input())
lst = [str(input())[0] for i in range(n)]
l_march = ["M","A","R","C","H"]
l_a = []
for i in l_march:
    l_a.append(lst.count(i))
l_b = list(itertools.combinations(range(5),3))
ans=0
for i in l_b:
    ans += l_a[i[0]]*l_a[i[1]]*l_a[i[2]]
print(ans)

Submission status: Accepted

Solution code:
# ABC089C - March
import sys

input = sys.stdin.readline

from itertools import combinations


def main():
    n = int(input())
    lst = [input().rstrip()[0] for _ in range(n)]
    print(
        sum(x * y * z for x, y, z in combinations([lst.count(s) for s in "MARCH"], 3))
    )


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ABC089C - March
import sys
input = sys.stdin.readline

from itertools import combinations


def main():
    n = int(input())
    lst = [input().rstrip()[0] for _ in range(n)]
    cand = [lst.count(s) for s in "MARCH"]
    ans = sum(x * y * z for x, y, z in combinations(cand, 3))
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ABC089C - March
from itertools import combinations


def main():
    n = int(input())
    lst = [input().rstrip()[0] for _ in range(n)]
    cand = [lst.count(s) for s in "MARCH"]
    ans = sum(x * y * z for x, y, z in combinations(cand, 3))
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ABC089C - March
import sys
input = sys.stdin.readline

from itertools import combinations


def main():
    n = int(input())
    lst = [input().rstrip() for _ in range(n)]
    cond = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
    for i in lst:
        if i[0] in "MARCH":
            cond[i[0]] += 1
    ans = 0
    for x, y, z in combinations("MARCH", 3):
        ans += cond[x] * cond[y] * cond[z]
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ABC089C - March
from itertools import combinations


def main():
    n = int(input())
    lst = [input().rstrip() for _ in range(n)]
    cond = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
    for i in lst:
        if i[0] in "MARCH":
            cond[i[0]] += 1
    ans = 0
    for x, y, z in combinations("MARCH", 3):
        ans += cond[x] * cond[y] * cond[z]
    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):
    name = input()
    if name[0] == "M":
        march[0] += 1
    elif name[0] == "A":
        march[1] += 1
    elif name[0] == "R":
        march[2] += 1
    elif name[0] == "C":
        march[3] += 1
    elif name[0] == "H":
        march[4] += 1

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

Submission status: Accepted

Solution code:
import itertools

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

M=len([s for s in S if s.startswith('M')])
A=len([s for s in S if s.startswith('A')])
R=len([s for s in S if s.startswith('R')])
C=len([s for s in S if s.startswith('C')])
H=len([s for s in S if s.startswith('H')])


ans=0
for i,j,k in itertools.combinations((M,A,R,C,H), 3):
    ans+=i*j*k

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
march = [0, 0, 0, 0, 0]

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

# 組み合わせカウント
combi = 0
for i in range(3):
    for j in range(i + 1, 4):
        for k in range(j + 1, 5):
            combi += march[i] * march[j] * march[k]
print(combi)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N = n()
names = defaultdict(int)
for i in range(N):
    name = s()
    if name[0] not in 'MARCH':
        continue
    names[name[0]] += 1

total = 0
cand = ''.join(names.keys())
import itertools
for p in itertools.combinations(cand, 3):
    total += names[p[0]] * names[p[1]] * names[p[2]]
print(total)

Submission status: Accepted

Solution code:
import itertools

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

ans =  0
if len(dict) >= 3:
  for v in itertools.combinations(dict.keys(), 3):
    ans += dict[v[0]] * dict[v[1]] * dict[v[2]]
print(ans)

Submission status: Accepted

Solution code:
n=int(input())

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

for i in range(n):
  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,c,h)
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:
import itertools

from sys import stdin
N = int(stdin.readline().rstrip())

data = []
for _ in range(N):
    data.append((input()))

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

for i in data:
    if i[0] == "M":
        M += 1
    
    if i[0] == "A":
        A += 1
    
    if i[0] == "R":
        R += 1
    
    if i[0] == "C":
        C += 1
    
    if i[0] == "H":
        H += 1

ans = 0
tmp = 1
for j in list(itertools.combinations([M,A,R,C,H],3)):
    for k in j:
        tmp = tmp * k
    ans += tmp
    tmp = 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = "MARCH"
cnt = [0, 0, 0, 0, 0]
for i in range(n):
    name = input()
    for j in range(len(s)):
        if name[0] == s[j]:
            cnt[j] += 1
cnt = [c for c in cnt if c > 0]
if len(cnt) < 3:
    print(0)
elif len(cnt) == 3:
    print(cnt[0]*cnt[1]*cnt[2])
elif len(cnt) == 4:
    ans = 0
    for i in range(4):
        ans += cnt[0]*cnt[1]*cnt[2]*cnt[3]//cnt[i]
    print(ans)
else:
    ans = 0
    for i in range(5):
        cnt_4 =[cnt[_] for _ in range(5) if _ != i]
        for j in range(4):
            ans += cnt_4[0]*cnt_4[1]*cnt_4[2]*cnt_4[3]//cnt_4[j]
    print(ans//2)

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)
score=[]
if len(M)!=0:
    score.append(len(M))
if len(A)!=0:
    score.append(len(A))
if len(R)!=0:
    score.append(len(R))
if len(C)!=0:
    score.append(len(C))
if len(H)!=0:
    score.append(len(H))

l=len(score)
if l==3:
    print(score[0]*score[1]*score[2])
elif l<=2:
    print(0)
elif l==4:
    k=score[0]*score[1]*score[2]*score[3]
    ans=0
    for i in range(4):
        ans+=k//score[i]
    print(ans)
else:
    k=score[0]*score[1]*score[2]*score[3]*score[4]
    ans=0
    for i in range(4):
        for j in range(i+1,5):
            ans+=k//(score[i]*score[j])
    print(ans)

Submission status: Accepted

Solution code:
march = ['M', 'A', 'R', 'C', 'H']
N = int(input())
S = []
people = {prefix: 0 for prefix in march}
for _ in range(N):
	s = input()
	for prefix in march:
		if s[0] == prefix:
			people[prefix] += 1
			break

ns = [n for n in people.values() if n > 0]
ans = 0
for i in range(len(ns)-2):
	for j in range(i+1,len(ns)-1):
		for k in range(j+1, len(ns)):
			ans += ns[i]*ns[j]*ns[k]
			
print(ans)

Submission status: Accepted

Solution code:
N,S=int(input()),""
for _ in range(N):S+=input()[0]
M,A,R,C,H=S.count("M"),S.count("A"),S.count("R"),S.count("C"),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:
from collections import Counter
import itertools
N = int(input())
S = [input()[0] for _ in range(N)]

counter = Counter(S)
answer = 0
for x,y,z in itertools.combinations('MARCH',3):
  answer += counter[x] * counter[y] * counter[z]

print(answer)

Submission status: Accepted

Solution code:
from collections import defaultdict
def main():
	N = int(input())
	march_list = ["M", "A", "R", "C", "H"]
	march_dict = defaultdict(int)
	for _ in range(N):
		x = input()
		if x[0] in march_list:
			march_dict[x[0]] += 1

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools as ite
N=int(input())
C=[0]*6
J="MARCH"
for i in range(N):
    C[J.find(input()[0])]+=1
ans=0
for i,j,k in list(ite.combinations(range(5),3)):
    ans+=C[i]*C[j]*C[k]
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
C=[0,0,0,0,0,0]
J="MARCH"
for i in range(N):
    C[J.find(input()[0])]+=1
ans=0
ans+=C[0]*C[1]*C[2]
ans+=C[0]*C[1]*C[3]
ans+=C[0]*C[1]*C[4]
ans+=C[0]*C[2]*C[3]
ans+=C[0]*C[2]*C[4]
ans+=C[0]*C[3]*C[4]
ans+=C[1]*C[2]*C[3]
ans+=C[1]*C[2]*C[4]
ans+=C[1]*C[3]*C[4]
ans+=C[2]*C[3]*C[4]
print(ans)

Submission status: Accepted

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

from collections import Counter

cnt = Counter(s)

from itertools import combinations

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

lss = [cnt["M"],cnt["A"],cnt["R"],cnt["C"],cnt["H"]]

ans = 0
for i in list(combinations(ls,3)):
    ans += lss[i[0]]*lss[i[1]]*lss[i[2]]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = []

for i in range(n):
    s.append(input())

l = [s[i][0] for i in range(n)]

m = l.count('M')
a = l.count('A')
r = l.count('R')
c = l.count('C')
h = l.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:
l = input().split()
N = int(l[0])
S = []
for i in range(N):
    l = input().split()
    S.append(l[0])

# print(N, S)

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

for s in S:
    h = s[0]
    if h in names:
        names[h] += 1

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

# print(names)

ans = 0

for i in range(5):
    for j in range(i + 1, 5):
        for k in range(j + 1, 5):
            # print(i, j, k)
            # print(names[table[i]])
            ni = names[table[i]]
            nj = names[table[j]]
            nk = names[table[k]]
            if ni == 0 or nj == 0 or nk == 0:
                continue
            ans += ni*nj*nk

print(ans)

Submission status: Accepted

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

import sys
import itertools

input = sys.stdin.readline

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

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

    p = [0, 0, 0, 0, 0, 0, 1, 1, 1, 2]
    q = [1, 1, 1, 2, 2, 3, 2, 2, 3, 3]
    r = [2, 3, 4, 3, 4, 4, 3, 4, 4, 4]

    n = 0
    for i in range(10):
        n += cnt[p[i]] * cnt[q[i]] * cnt[r[i]]
    print(n)

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
from itertools import combinations


n = int(input())
lst_s = [input()[0] for _ in range(n)]
lst_march = [s for s in lst_s if s in "MARCH"]
cnt_s = Counter(lst_march)
lst_num = list(cnt_s.values())
cmb_num = list(combinations(lst_num, 3))
ans = sum(c[0] * c[1] * c[2] for c in cmb_num)
print(ans)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  la=['M','A','R','C','H']
  lb=[0]*5

  for _ in range(n):
    s=S()
    if la.count(s[0])>0:
      lb[la.index(s[0])]+=1

  sm=0

  for x in list(itertools.combinations(la,3)):
    sm+=lb[la.index(x[0])]*lb[la.index(x[1])]*lb[la.index(x[2])]

  return sm

print(main())