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 math import factorial as fac
from itertools import combinations as comb

n = int(input())
x = ["M", "A", "R", "C", "H"]
x_l = [[], [], [], [], []]
l = [ input() for i in range(n)]

for s in l:
  if s[0] in x:
    x_l[x.index(s[0])].append(s)
    
    
x_l = [len(x_l[i]) for i in range(5) if len(x_l[i]) != 0]
leng = len(x_l)


if leng < 3:
  print(0)
else:
  ans = 0
  for number in comb([ i for i in range(leng)], 3):
    ans += x_l[number[0]]*x_l[number[1]]*x_l[number[2]]
  print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

values = [v for k, v in initial.items()]
ans = 0
for i in range(3):
    for j in range(i+1, 4):
        for k in range(j+1, 5):
            ans += values[i] * values[j] * values[k]

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
Sset = set()
str_dict = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for _ in range(N):
    S = input()
    if S in Sset:
        continue
    if S[0] in {"M", "A", "R", "C", "H"}:
        Sset.add(S)
        str_dict[S[0]] += 1

non0 = []
for item in str_dict.items():
    if item[1] > 0:
        non0.append(item[0])

num = 0
from itertools import combinations
for comb in combinations(non0, 3):
    num += str_dict[comb[0]] * str_dict[comb[1]] * str_dict[comb[2]]

print(num)

Submission status: Accepted

Solution code:
from sys import stdin
from itertools import combinations
from math import factorial

n = int(stdin.readline().rstrip())
li = [stdin.readline().rstrip() for _ in range(n)]

lin = [0]*5

for i in range(len(li)):
    if li[i][0] == "M":
        lin[0] += 1
    elif li[i][0] == "A":
        lin[1] += 1
    elif li[i][0] == "R":
        lin[2] += 1
    elif li[i][0] == "C":
        lin[3] += 1
    elif li[i][0] == "H":
        lin[4] += 1
        
lis = list(combinations(lin, 3))

point = 0
for i in lis:
    point += i[0]*i[1]*i[2]

print(point)

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def main():
    N = int(readline())
    S = list(map(lambda x: x.decode("UTF-8"), readlines()))
    S = list(map(lambda x: x.rstrip('\n'), S))
    march = list("MARCH")

    cnt = [0] * 5
    for i in range(N):
        for j in range(5):
            if S[i][0] == march[j]:
                cnt[j] += 1

    ans = 0

    if N < 3:
        print(0)
    else:
        for i in range(3):
            for j in range(i+1, 4):
                for k in range(j+1, 5):
                    ans += cnt[i] * cnt[j] * cnt[k]

        print(ans)


main()

Submission status: Accepted

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

s = [m, a, r, c, h]
x = [0, 0, 0, 0, 0, 0, 1, 1, 1, 2]
y = [1, 1, 1, 2, 2, 3, 2, 2, 3, 3]
z = [2, 3, 4, 3, 4, 4, 3, 4, 4, 4]

cnt = 0
for i in range(10):
    cnt += (s[x[i]] * s[y[i]] * s[z[i]])
print(cnt)

Submission status: Accepted

Solution code:
from collections import defaultdict
import itertools
N = int(input())
D = defaultdict(int)
for _ in range(N):
    D[input()[0]] += 1
A = ['M','A','R','C','H']
A = list(itertools.combinations(A,3))
ans = 0
for x in A:
    s = 1
    for e in x:
        s *= D[e]
    ans += s
print(ans)

Submission status: Accepted

Solution code:
N=int(input())

D={}
D["M"]=0
D["A"]=0
D["R"]=0
D["C"]=0
D["H"]=0

for i in range(N):
    S=input()
    if S[0]=="M":
        D["M"]+=1
    elif S[0]=="A":
        D["A"]+=1
    elif S[0]=="R":
        D["R"]+=1
    elif S[0]=="C":
        D["C"]+=1
    elif S[0]=="H":
        D["H"]+=1

import itertools
l=["M","A","R","C","H"]
a=list(itertools.combinations(l,3)) #Lの中から2個

ANS=0
for i in range(len(a)):
    ANS+=(D[a[i][0]]*D[a[i][1]]*D[a[i][2]])
print(ANS)

Submission status: Accepted

Solution code:
import itertools


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

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

for i in range(len(s)):
    if s[i][0] == "M":
        m += 1
    if s[i][0] == "A":
        a += 1
    if s[i][0] == "R":
        r += 1
    if s[i][0] == "C":
        c += 1
    if s[i][0] == "H":
        h += 1

head_l = [m, a, r, c, h]
comb_l = list(itertools.combinations(head_l, 3))
ans = 0
for comb in comb_l:
    pat = comb[0]
    for i in range(1, len(comb)):
        pat *= comb[i]
    ans += pat
        
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
import itertools

d = defaultdict(int)

N = int(input())
for _ in range(N):
    s = input()
    if s.startswith('M'):
        d['M'] += 1
    elif s.startswith('A'):
        d['A'] += 1
    elif s.startswith('R'):
        d['R'] += 1
    elif s.startswith('C'):
        d['C'] += 1
    elif s.startswith('H'):
        d['H'] += 1

answer = 0
for x, y, z in list(itertools.combinations(['M', 'A', 'R', 'C', 'H'], 3)):
    answer += d[x] * d[y] * d[z]
print(answer)

Submission status: Accepted

Solution code:
N = int(input())
li = [input() for i in range(N)]
liM = []
liA = []
liR = []
liC = []
liH = []
for i in range(N):
  if li[i][0] == 'M':
    liM.append(li[i])
  elif li[i][0] == 'A':
    liA.append(li[i])
  elif li[i][0] == 'R':
    liR.append(li[i])
  elif li[i][0] == 'C':
    liC.append(li[i])
  elif li[i][0] == 'H':
    liH.append(li[i])
M = len(liM)
A = len(liA)
R = len(liR)
C = len(liC)
H = len(liH)
ans = M*(A*(R+C+H)+R*(C+H)+C*H) + A*(R*(C+H)+C*H) + R*C*H
print(ans)

Submission status: Accepted

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

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

c = combinations(march,3)    
ans = 0
for v1,v2,v3 in c:
  ans += dic[v1]*dic[v2]*dic[v3]  

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
ss = "MARCH"
c = [0 for i in range(5)]
for i in range(n):
	s = input()
	for j in range(5):
		if s[0] == ss[j]:
			c[j] += 1
ans = 0
for i in range(5):
	for j in range(i+1,5):
		for k in range(j+1,5):
			ans += c[i]*c[j]*c[k]
print (ans)

Submission status: Accepted

Solution code:
lists=[0 for i in range(5)]
mar=["M","A","R","C","H"]
n=int(input())
for i in range(n):
    s=input()
    a=s[0]
    for i in range(5):
        if a==mar[i]:
            lists[i]+=1
answer=0
for i in range(5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            answer+=lists[i]*lists[j]*lists[k]
print(answer)

Submission status: Accepted

Solution code:
from itertools import*
N,*S=open(0)
print(sum(a*b*c for a,b,c in combinations([sum(1 for s in S if s[0]==c) for c in "MARCH"],3)))

Submission status: Accepted

Solution code:
import itertools
n = int(input())
list_march = ["M", "A", "R", "C", "H"]
num_march = [0 for i in range(5)]
for i in range(n):
  s = input()
  if s[0] in list_march:
    num_march[list_march.index(s[0])] += 1

if num_march.count(0) >= 3:
  print(0)
else:
  cand = list(itertools.combinations([0, 1, 2, 3, 4], 3))
  result = 0
  for a, b, c in cand:
    result += num_march[a] * num_march[b] * num_march[c]
  print(result)

Submission status: Accepted

Solution code:
import collections
N = int(input())
S = [input() for i in range(N)]
SI = [S[i][0] for i in range(N)]
cnt = collections.Counter(SI)
n = [cnt["M"],cnt["A"],cnt["R"],cnt["C"],cnt["H"]]
ans = 0
for i in range(3):
    for j in range(i+1,5):
        for k in range(j+1,5):
            ans += n[i]*n[j]*n[k]
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
import itertools
N = int(input())
d = defaultdict(int)
for _ in range(N):
  s = input()
  if s[0] in 'MARCH':
    d[s[0]] += 1

ans = 0
if len(d.keys()) >= 3:
  for c in itertools.combinations(d.values(), 3):
    ans += c[0] * c[1] * c[2]

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = [input() for _ in range(n)]
M = A = R = C = H = 0
for i in range(len(s)):
    if s[i][0] == 'M':
        M += 1
    if s[i][0] == 'A':
        A += 1
    if s[i][0] == 'R':
        R += 1
    if s[i][0] == 'C':
        C += 1
    if s[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 = 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

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

Submission status: Accepted

Solution code:
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1

def main():
    n=int(input())
    cc=[0]*5
    for _ in range(n):
        c=input()[0]
        if c=="M":cc[0]+=1
        if c == "A": cc[1] += 1
        if c == "R": cc[2] += 1
        if c == "C": cc[3] += 1
        if c == "H": cc[4] += 1
    ans=0
    for k in range(5):
        for j in range(k):
            for i in range(j):
                ans+=cc[i]*cc[j]*cc[k]
    print(ans)

main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
S = [input() for _ in range(N)]

import collections
name_frq_dict = collections.defaultdict(int)
for s in S:
    if s[0] in ['M', 'A', 'R', 'C', 'H']:
        name_frq_dict[s[0]] += 1


len_name_frq_dict = len(name_frq_dict)

if len_name_frq_dict < 3:
    print(0)
else:
    import itertools

    ans = 0
    names = list(name_frq_dict.keys())
    for part_names in itertools.permutations(names, 3):
        a = 1
        for n in part_names:
            a *= name_frq_dict[n]
        ans += a

    print(ans//6)

Submission status: Accepted

Solution code:
# C
from itertools import combinations
n = int(input())
names = [0 for _ in range(5)]
for _ in range(n):
    start = input()[0]
    if start == 'M':
        names[0] += 1
    if start == 'A':
        names[1] += 1
    if start == 'R':
        names[2] += 1
    if start == 'C':
        names[3] += 1
    if start == 'H':
        names[4] += 1
comb = combinations(names, 3)
total = 0
for c in comb:
    total += c[0]*c[1]*c[2]
print(total)

Submission status: Accepted

Solution code:
N = int(input())
Dict={}
for i in range(N):
    T=input()
    if Dict.get(T[0],None)==None:
        Dict[T[0]]=1
    else:
        Dict[T[0]]+=1

L=[]
if Dict.get("M",None)!=None:
    L.append(Dict["M"])
if Dict.get("R",None)!=None:
    L.append(Dict["R"])
if Dict.get("A",None)!=None:
    L.append(Dict["A"])
if Dict.get("C",None)!=None:
    L.append(Dict["C"])
if Dict.get("H",None)!=None:
    L.append(Dict["H"])
if(len(L)<3):
    print(0)
    exit()


S=0
for i in range(len(L)):
    for j in range(len(L)):
        if(i==j):break
        for k in range(len(L)):
            if(i==k):break
            if(j==k):break
            S+=L[i]*L[j]*L[k]
print(S)

Submission status: Accepted

Solution code:
X = [0] * 5
D = {"M": 0, "A": 1, "R": 2, "C": 3, "H": 4}
N = int(input())
for _ in range(N):
    s = input()[0]
    if s in D:
        X[D[s]] += 1

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

Submission status: Accepted

Solution code:
#                         author:  kagemeka 
#                         created: 2019-11-06 16:52:04(JST)
import sys
# import collections
# import math
# import string
# import bisect
# import re
import itertools
# import statistics
# import functools
# import operator

# def nCr(n, r):
#     r = min(r, n - r)
#     return functools.reduce(operator.mul, range(n, n-r, -1), 1) // math.factorial(r)

def main():
    n = int(sys.stdin.readline().rstrip())
    march = {l: 0 for l in 'MARCH'}

    for i in range(n):
        initial = sys.stdin.readline()[0]
        if initial in march:
            march[initial] += 1


    march = {k: v for k, v in march.items() if v != 0}
    
    if len(march) < 2:
        print(0)
        exit()
    
    total_cmb = 0
    for cmb in itertools.combinations(march.values(), 3):
        total_cmb += cmb[0] * cmb[1] * cmb[2]
    
    print(total_cmb)
        
if __name__ == "__main__":
    # execute only if run as a script
    main()

Submission status: Accepted

Solution code:
N=int(input())
S= list(str(input()) for i in range(N))
count_M = 0
count_R = 0
count_A = 0
count_C = 0
count_H = 0
for i in range(N):
  if S[i][0] =='M':
    count_M +=1
  if S[i][0] =='R':
    count_R +=1
  if S[i][0] =='C':
    count_C +=1
  if S[i][0] =='H':
    count_H +=1
  if S[i][0] =='A':
    count_A +=1
print(count_M*count_A*count_R+count_M*count_A*count_C+count_M*count_A*count_H+count_M*count_R*count_C+count_M*count_R*count_H+count_M*count_C*count_H+count_A*count_R*count_C+count_A*count_R*count_H+count_R*count_C*count_H+count_A*count_C*count_H)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
dic = dict()

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

ans = 0

A = list(dic.values())
for i in range(len(A) - 2):
	for j in range(i + 1, len(A) - 1):
		for k in range(j + 1, len(A)):
			ans += A[i] * A[j] * A[k]
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
D="MARCH"
cnt=[0]*5
for i in range(N):
  s=input()[0]
  if s in D:
    cnt[D.index(s)]+=1

pat=[None]*10
pati=0
for a in range(5):
  for b in range(a+1,5):
    for c in range(b+1,5):
      pat[pati]=[a,b,c]
      pati+=1

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

Submission status: Accepted

Solution code:
N=int(input())
S=[""]*N
for i in range(N):
  S[i]=input()
D="MARCH"
cnt=[0]*5
for s in S:
  if s[0] in D:
    cnt[D.index(s[0])]+=1
    
pat=[None]*10
pati=0
for a in range(5):
  for b in range(a+1,5):
    for c in range(b+1,5):
      pat[pati]=[a,b,c]
      pati+=1

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

Submission status: Accepted

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

    dict = {'M': [],
    'A': [],
    'R': [],
    'C': [],
    'H': []}

    for i in range(N):
        name = input()
        if name[0] in list(dict.keys()):
            dict[name[0]].append(name)
    
    comb = itertools.combinations(dict.keys(), 3)
    count = 0
    for c in comb:
        count += len(dict[c[0]])*len(dict[c[1]])*len(dict[c[2]])
    
    print(count)

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys
import collections
import itertools
sys.setrecursionlimit(10 ** 7)


def main():
    N = int(input())
    S = []
    for _ in range(N):
        x = input()
        if x.startswith(("M", "A", "R", "C", "H")):
            S.append(x[0])

    c = collections.Counter(S)
    ans = 0
    for x, y, z in itertools.combinations(["M", "A", "R", "C", "H"], 3):
        ans += c[x] * c[y] * c[z]
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict
from itertools import combinations

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

dic = defaultdict(int)
for s in S:
    dic[s[0]] += 1

comb = combinations("MARCH", 3)

ans = 0
for x1,x2,x3 in comb:
    ans += dic[x1]*dic[x2]*dic[x3]

print(ans)

Submission status: Accepted

Solution code:
import itertools
n = int(input())
s = [input()[0] for _ in range(n)]
c = list(itertools.combinations(set(filter(lambda x: x in "MARCH", s)), 3))

ans = 0
for _c in c:
    ans += s.count(_c[0])*s.count(_c[1])*s.count(_c[2])
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()[0]
    if s=='M':
        M+=1
    elif s=='A':
        A+=1
    elif s=='R':
        R+=1
    elif s=='C':
        C+=1
    elif s=='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())
m=0
a=0
r=0
c=0
h=0
for i in range(n):
	s=input()[0]
	if s=='M':
		m+=1
	elif s=='A':
		a+=1
	elif s=='R':
		r+=1
	elif s=='C':
		c+=1
	elif s=='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:
import collections
import itertools

n = int(input())
s = [input()[0] for _ in range(n)]
counter = collections.Counter(s)
ans = 0
for a, b, c in itertools.combinations('MARCH', 3):
    ans += counter[a] * counter[b] * counter[c]
print(ans)

Submission status: Accepted

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

mrch = ["M","A","R","C","H"]
memo = [0 for i in range(5)]

for i in range(n):
    a = list(input())
    for j in range(5):
        if a[0] == mrch[j]:
            memo[j] += 1

ans = 0
for i in range(2**5):
    cnt = 0
    memo2 = 1
    for j in range(5):
        #print(bin(i)," ",i," ",j," ",i>>j)
        if (i >> j) & 1:
            #print(bin(i)," ",i," ",j," ",i>>j)
            cnt += 1
            memo2 *= memo[j]
    if cnt == 3:
        ans += memo2
        #print(bin(i))

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import combinations as comb
n = int(input())
d = {'M':0,'A':0,'R':0,'C':0,'H':0}
for i in range(n):
  try:
    d[input()[0]] += 1
  except:
    continue
c = 0
l = d.values()
for i,j,k in comb(l,3):
  c += i*j*k
print(c)

Submission status: Accepted

Solution code:
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac
import fractions
from functools import reduce
from operator import mul
import bisect
import sys
import logging
import heapq
import itertools

#logging.basicConfig(level=logging.DEBUG)

input = sys.stdin.readline

setrecursionlimit(1000000)


def main():
	n = int(input())
	s = defaultdict(set)
	for _ in range(n):
		t = input()
		if(t[0] in ['M','A','R','C','H']):
			s[t[0]].add(t)
	s = list(s.values())
	ans = 0
	for i in itertools.permutations(s,3):
		ans += len(i[0]) * len(i[1]) * len(i[2])
	print(ans//6)

def factorization(n):
	arr = []
	temp = n
	for i in range(2, int(-(-n**0.5//1))+1):
		if temp%i==0:
			cnt=0
			while temp%i==0:
				cnt+=1
				temp //= i
			arr.append([i, cnt])

	if temp!=1:
		arr.append([temp, 1])

	if arr==[]:
		arr.append([n, 1])

	return arr

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

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def lcm(numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

class PriorityQueue():
	def __init__(self):
		self.queue = []
	def push(self,i):
		heapq.heappush(self.queue,-i)
	def pop(self):
		return -1 * heapq.heappop(self.queue)
	def sum(self):
		return -sum(self.queue)

main()

Submission status: Accepted

Solution code:
# coding: utf-8
N = int(input())
ans = 0
a_l = {"M":0, "A":0, "R":0, "C":0, "H":0}
a_l = [0] * 5
a_l_char = ["M", "A", "R", "C", "H"]
for _ in range(N):
    tmp = input()
    # a_l[str(tmp[0])] += 1
    for i in range(len(a_l_char)):
        if tmp[0] == a_l_char[i]:
            a_l[i] += 1
ans += a_l[0] * a_l[1] * a_l[2]
ans += a_l[0] * a_l[1] * a_l[3]
ans += a_l[0] * a_l[1] * a_l[4]
ans += a_l[0] * a_l[2] * a_l[3]
ans += a_l[0] * a_l[2] * a_l[4]
ans += a_l[0] * a_l[3] * a_l[4]

ans += a_l[1] * a_l[2] * a_l[3]
ans += a_l[1] * a_l[2] * a_l[4]
ans += a_l[1] * a_l[3] * a_l[4]

ans += a_l[2] * a_l[3] * a_l[4]

print(ans)

Submission status: Accepted

Solution code:
import sys
import collections
import itertools


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    d = collections.defaultdict(lambda: collections.defaultdict(list))
    for i in range(n):
        s = str(input().rstrip('\n'))
        if s[0] == "M":
            d["M"][s]
        elif s[0] == "A":
            d["A"][s]
        elif s[0] == "R":
            d["R"][s]
        elif s[0] == "C":
            d["C"][s]
        elif s[0] == "H":
            d["H"][s]
    ls = [0] * len(d)
    cur = 0
    for v in d.values():
        ls[cur] += len(v)
        cur += 1
    t = 0
    for v in itertools.combinations(ls, 3):
        t += (v[0] * v[1] * v[2])
    print(t)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
from collections import Counter
import itertools

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

c = Counter(S)
print(sum(c[x]*c[y]*c[z]  for x, y, z in itertools.combinations('MARCH', 3)))

Submission status: Accepted

Solution code:
from itertools import combinations

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

lst = [M,A,R,C,H]
# lst = [2,3,4]
# print(lst)
x = list(combinations(lst, 3))
# print(x)

ans = 0
for a,b,c in x:
    ans += a * b * c
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
KEY = 'MARCH'

d={}
for i in KEY:
	d[i]=0

for i in range(N):
	t = input()[0]
	if t in KEY:
		d[t]+=1

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

print(ans)

Submission status: Accepted

Solution code:
N=int(input())

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N=int(input())
name_dict={'M':0,'A':0,'R':0,'C':0,'H':0}
for n in range(N):
    S=list(input())
    if S[0] in name_dict:
        name_dict[S[0]]+=1

ans=name_dict['M']*name_dict['A']*name_dict['R']\
    +name_dict['M']*name_dict['A']*name_dict['C']\
    +name_dict['M']*name_dict['A']*name_dict['H']\
    +name_dict['M']*name_dict['R']*name_dict['C']\
    +name_dict['M']*name_dict['R']*name_dict['H']\
    +name_dict['M']*name_dict['C']*name_dict['H']\
    +name_dict['A']*name_dict['R']*name_dict['C']\
    +name_dict['A']*name_dict['R']*name_dict['H']\
    +name_dict['A']*name_dict['C']*name_dict['H']\
    +name_dict['R']*name_dict['C']*name_dict['H']
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=[]
c=[]
ans=0
for i in range(n):
  s.append(input()[0])
for x in 'MARCH':
  c.append(s.count(x))
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 main():
    cnt_march = [0] * 5
    N = int(input())
    for _ in range(N):
        S = input()
        if S[0] == 'M':
            cnt_march[0] += 1
        elif S[0] == 'A':
            cnt_march[1] += 1
        elif S[0] == 'R':
            cnt_march[2] += 1
        elif S[0] == 'C':
            cnt_march[3] += 1
        elif S[0] == 'H':
            cnt_march[4] += 1

    ans = 0
    from itertools import combinations
    for i, j, k in combinations(range(5), 3):
        ans += cnt_march[i] * cnt_march[j] * cnt_march[k]

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())

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

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

    print(ans)


main()

Submission status: Accepted

Solution code:
n, *s = open(0).read().split()
n = int(n)
slist = []
for i  in range(5):
  slist.append([])
for ss in s:
  if ss[0] == "M":
    slist[0].append(ss)
  elif ss[0] == "A": 
    slist[1].append(ss)
  elif ss[0] == "R": 
    slist[2].append(ss)
  elif ss[0] == "C": 
    slist[3].append(ss)
  elif ss[0] == "H": 
    slist[4].append(ss)
  else:
    continue

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

Submission status: Accepted

Solution code:
def input():
    import sys
    return sys.stdin.readline().rstrip()


def main():
    import math
    import collections
    import itertools
    import functools
    
    n = int(input())
    ss = [input() for _ in range(n)]
    target_chars = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
    # n_names = [0] * 5
    for name in ss:
        if name[0] in target_chars.keys():
            target_chars[name[0]] += 1
    
    ans = 0
    for comb in itertools.combinations(target_chars, 3):
        ans += functools.reduce(lambda x, y: x * target_chars[y], comb, 1)

    print(ans)
            

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools

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

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


if __name__ == "__main__":
    test()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = [ input() for _ in range(n)]
march = [ 0 for _ in range(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] + ans
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools

N = int(input())
count = [0,0,0,0,0]
total = 0

for _ in range(N):
    S = input()
    if S[0] == 'M':
        count[0] += 1
    elif S[0] == 'A':
        count[1] += 1
    elif S[0] == 'R':
        count[2] += 1
    elif S[0] == 'C':
        count[3] += 1
    elif S[0] == 'H':
        count[4] += 1
count = [i for i in count if i != 0]

for v in itertools.combinations(count, 3):
    total += v[0]*v[1]*v[2]
print(total)