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())
ans = 0
MARCH = [0] * 5  # 順にM、A、R、C、H
for i in range(N):
    S = input()
    if S[0] == "M":
        MARCH[0] += 1
    elif S[0] == "A":
        MARCH[1] += 1
    elif S[0] == "R":
        MARCH[2] += 1
    elif S[0] == "C":
        MARCH[3] += 1
    elif S[0] == "H":
        MARCH[4] += 1

for j in range(3):
    for k in range(j+1, 4):
        for m in range(k+1, 5):
            ans += MARCH[j] * MARCH[k] * MARCH[m]
print(ans)
#print(MARCH)

Submission status: Accepted

Solution code:
n=int(input())
al=list('MARCH')
d=[0]*5
for i in range(n):
    s=list(input())
    if s[0] in al:
        d[al.index(s[0])]+=1
op=['0','1']
for i in range(4):
    tmp=[]
    for j in op:
        tmp.append(j+'0')
        tmp.append(j+'1')
    op=tmp
k=[]
for i in op:
    g=list(i)
    c=0
    for j in g:
        if j=='1':
            c+=1
    if c==3:
        k.append(i)
ans=0
for i in k:
    t=1
    for j in range(5):
        if i[j]=='1':
            t*=d[j]
    ans+=t
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
m,a,r,c,h=0,0,0,0,0
for i in range(n):
  s=input()
  if s[0]=='M':
    m+=1
  elif s[0]=='A':
    a+=1
  elif s[0]=='R':
    r+=1
  elif s[0]=='C':
    c+=1
  elif s[0]=='H':
    h+=1
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())
sl=[input() for _ in range(n)]
t=[0]*5
a=[0,0,0,0,0,0,1,1,1,2]
b=[1,1,1,2,2,3,2,2,3,3]
c=[2,3,4,3,4,4,3,4,4,4]
for s in sl:
    if s[0]=='M':
        t[0]+=1
    elif s[0]=='A':
        t[1]+=1
    elif s[0]=='R':
        t[2]+=1
    elif s[0]=='C':
        t[3]+=1
    elif s[0]=='H':
        t[4]+=1
ans=0
for i in range(10):
    ans+=t[a[i]]*t[b[i]]*t[c[i]]
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
l=[0]*5

for _ 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
    else:
        pass
count=0
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            count+=l[i]*l[j]*l[k]

print(count)

Submission status: Accepted

Solution code:
import itertools

N = int(input())

# 頭文字Mグループ、頭文字Aグループ、のように分割する
# どの3つのグループから1人選ぶかを考える

n_initial_MARCH = [0]*5
match_initial = ["M", "A", "R", "C", "H"]
for _ in range(N):
    s = input()
    for idx in range(5):
        if s[0] == match_initial[idx]:
            n_initial_MARCH[idx] += 1

taken_indices = list(itertools.combinations([idx for idx in range(5) if n_initial_MARCH[idx] > 0], 3))

ans = 0

for groups in taken_indices:
    ans += n_initial_MARCH[groups[0]] * n_initial_MARCH[groups[1]] * n_initial_MARCH[groups[2]]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
l=[0]*5
m='MARCH'
for i in range(n):
  s=input()
  f=s[0]
  for i in range(5):
    if f==m[i]:
      l[i]+=1
      break
x=0
for i in range(3):
  for j in range(i+1,4):
    for k in range(j+1,5):
      x+=l[i]*l[j]*l[k]
print(x)

Submission status: Accepted

Solution code:
n=int(input())
l=[0]*5
m='MARCH'
for i in range(n):
  s=input()
  f=s[0]
  for i in range(5):
    if f==m[i]:
      l[i]+=1
      break
a=[]
for i in l:
  if i!=0:
    a.append(i)
if len(a)<3:
  print(0)
elif len(a)==3:
  print(a[0]*a[1]*a[2])
elif len(a)==4:
  print(a[0]*a[1]*(a[2]+a[3])+a[2]*a[3]*(a[0]+a[1]))
else:
  x=0
  for i in range(3):
    for j in range(i+1,4):
      for k in range(j+1,5):
        x+=a[i]*a[j]*a[k]
  print(x)

Submission status: Accepted

Solution code:
from itertools import combinations


march = {'M':0,'A':0,'R':0,'C':0,'H':0}
n = int(input())
for _ in range(n):
    s = input()
    for cap in march:
        if s.startswith(cap):
            march[cap] +=1

trios = combinations(['M','A','R','C','H'],3)
ans = 0
for trio in trios:
    ans += march[trio[0]]*march[trio[1]]*march[trio[2]]

print(ans)

Submission status: Accepted

Solution code:
M = []
A = []
R = []
C = []
H = []
ans = 0
n = int(input())
for _ in range(n):
    tmp = input()
    if tmp[0] == "M":
        M.append(tmp)
    elif tmp[0] == "A":
        A.append(tmp)
    elif tmp[0] == "R":
        R.append(tmp)
    elif tmp[0] == "C":
        C.append(tmp)
    elif tmp[0] == "H":
        H.append(tmp)
if len(M) == 0 and len(A) == 0 and len(R) == 0 and len(C) == 0 and len(H) == 0:
    print(ans)
else:
    lenM = len(M)
    lenA = len(A)
    lenR = len(R)
    lenC = len(C)
    lenH = len(H)

    ans += lenM * lenA * lenR
    ans += lenM * lenA * lenC
    ans += lenM * lenA * lenH
    ans += lenM * lenR * lenC
    ans += lenM * lenR * lenH
    ans += lenM * lenC * lenH
    ans += lenA * lenR * lenC
    ans += lenA * lenR * lenH
    ans += lenA * lenC * lenH    
    ans += lenR * lenC * lenH

    print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
import itertools
n = int(input())
ary = []
for i in range(n):
    x = input()[0]
    if x == "M" or x =="A" or x =="R" or x =="C" or x == "H":
        ary.append(x)
c = Counter(ary)
cmb = itertools.combinations(c.keys(),3)
ans = 0
for s in cmb:
    ans += c[s[0]]*c[s[1]]*c[s[2]]
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
n=[input()[0] for _ in range(N)]
m,a,r,c,h=n.count("M"),n.count("A"),n.count("R"),n.count("C"),n.count("H")
print(m*a*(r+c+h)+m*r*(c+h)+m*c*h+a*r*(c+h)+a*c*h+r*c*h)

Submission status: Accepted

Solution code:
N=int(input())
name=[input()[0] for _ in range(N)]
m,a,r,c,h=name.count("M"),name.count("A"),name.count("R"),name.count("C"),name.count("H")
print(m*a*(r+c+h)+m*r*(c+h)+m*c*h+a*r*(c+h)+a*c*h+r*c*h)

Submission status: Accepted

Solution code:
import itertools
N = int(input())
Data = [0]*5
for _ in range(N):
    s = input()
    c = s[0]
    if c == 'M':
        Data[0] += 1
    elif c == 'A':
        Data[1] += 1
    elif c == 'R':
        Data[2] += 1
    elif c == 'C':
        Data[3] += 1
    elif c == 'H':
        Data[4] += 1
ans = 0
for data in itertools.combinations(Data,3):
    ans += data[0]*data[1]*data[2]
print(ans)

Submission status: Accepted

Solution code:
import itertools

N = int(input())
S = []
cnt_dict = {'M': 0, 'A': 0, 'R': 0, 'C': 0,'H': 0}

for _ in range(N):
    s = input()
    if s[0] in cnt_dict.keys():
        cnt_dict[s[0]] += 1

cnt_list = list(cnt_dict.values())
cnt = 0
for c in itertools.combinations(range(5), 3):
    cnt += cnt_list[c[0]]*cnt_list[c[1]]*cnt_list[c[2]]
print(cnt)

Submission status: Accepted

Solution code:
import itertools
N = int(input())
C = {"M":0,"A":0,"R":0,"C":0,"H":0}
for _ in range(N):
    s = input().strip()
    x = s[0]
    if x in C:
        C[x] += 1
D = list(C.values())
cnt = 0
for y in itertools.combinations(range(5),3):
    cnt += D[y[0]]*D[y[1]]*D[y[2]]
print(cnt)

Submission status: Accepted

Solution code:
N=int(input())
ls=[0,0,0,0,0]#MARCH
for i in range(N):
  x=input()
  if x[0]=='M':
    ls[0]+=1
  elif x[0]=='A':
    ls[1]+=1
  elif x[0]=='R':
    ls[2]+=1
  elif x[0]=='C':
    ls[3]+=1
  elif x[0]=='H':
    ls[4]+=1
ans=0
for i in range(3):
  for j in range(i+1,4):
    for k in range(j+1,5):
      ans+=ls[i]*ls[j]*ls[k]
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
n,*s=map(str,open(0).read().split())
a=[0]*5
for i in s:
    if i[0] in "MARCH":
        a["MARCH".index(i[0])]+=1
print(sum([a[x]*a[y]*a[z] for x,y,z in combinations(range(5),3)]))

Submission status: Accepted

Solution code:
n,*s=map(str,open(0).read().split())
a=[0]*5
ans=0
for i in s:
    if i[0] in "MARCH":
        a["MARCH".index(i[0])]+=1
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())
s = [input() for i in range(n)]
m,a,r,c,h = 0,0,0,0,0

for name in s:
    if name[0] == "M":
        m += 1
    if name[0] == "A":
        a += 1
    if name[0] == "R":
        r += 1
    if name[0] == "C":
        c += 1
    if name[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())
d = {"M":0, "A":0, "R":0, "C":0, "H":0}
for i in range(n):
    s = input()
    letter = s[0]
    if letter in d:
        d[letter] += 1
ans = 0
l = ["M", "A", "R", "C", "H"]
t1 = 0
t2 = 0
t3 = 0
for i in range(0, 3):
    if d[l[i]] != 0:
        t1 = d[l[i]]
        for j in range(i+1, 4):
            if d[l[j]] != 0:
                t2 = d[l[j]]
                for k in range(j+1, 5):
                    if d[l[k]] != 0:
                        t3 = d[l[k]]
                        ans += t1 * t2 * t3
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
d = {"M":0, "A":0, "R":0, "C":0, "H":0}
for i in range(n):
    s = input()
    letter = s[0]
    if letter in d:
        d[letter] += 1
ans = 0
if d["M"] != 0 and d["A"] != 0 and d["R"] != 0:
    ans += d["M"] * d["A"] * d["R"]
if d["M"] != 0 and d["A"] != 0 and d["C"] != 0:
    ans += d["M"] * d["A"] * d["C"]
if d["M"] != 0 and d["A"] != 0 and d["H"] != 0:
    ans += d["M"] * d["A"] * d["H"]
if d["M"] != 0 and d["R"] != 0 and d["C"] != 0:
    ans += d["M"] * d["R"] * d["C"]
if d["M"] != 0 and d["R"] != 0 and d["H"] != 0:
    ans += d["M"] * d["R"] * d["H"]
if d["M"] != 0 and d["C"] != 0 and d["H"] != 0:
    ans += d["M"] * d["C"] * d["H"]
if d["A"] != 0 and d["R"] != 0 and d["C"] != 0:
    ans += d["A"] * d["R"] * d["C"]
if d["A"] != 0 and d["R"] != 0 and d["H"] != 0:
    ans += d["A"] * d["R"] * d["H"]
if d["A"] != 0 and d["C"] != 0 and d["H"] != 0:
    ans += d["A"] * d["C"] * d["H"]
if d["R"] != 0 and d["C"] != 0 and d["H"] != 0:
    ans += d["R"] * d["C"] * d["H"]
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
from collections import defaultdict
n = int(input())
d = defaultdict(int)
for i in range(n):
    tmp = input()
    if tmp.startswith("M"):
        d["m"] += 1
    elif tmp.startswith("A"):
        d["a"] += 1
    elif tmp.startswith("R"):
        d["r"] += 1
    elif tmp.startswith("C"):
        d["c"] += 1
    elif tmp.startswith("H"):
        d["h"] += 1

if len(d) < 3:
    print(0)
else:
    res = 0
    for a, b, c in combinations(d.keys(), 3):
        res += d[a] * d[b] * d[c]
    print(res)

Submission status: Accepted

Solution code:
n=int(input())
name={}
name["M"]=0
name["A"]=0
name["R"]=0
name["C"]=0
name["H"]=0
for _ in range(n):
    s=list(input())
    if s[0] not in name:
        name[s[0]]=1
    else:
        name[s[0]]+=1
cnt=[name["M"],name["A"],name["R"],name["C"],name["H"]]
ans=0
n=5
for i in range(n-2):
    for j in range(n-i-2):
        j+=i+1
        for k in range(n-j-1):
            k+=j+1
            ans+=cnt[i]*cnt[j]*cnt[k]
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
import itertools
n = int(input())
ary = []
for i in range(n):
    s = input()[0]
    if s == "M" or s == "A" or s =="R" or s =="C" or s == "H":
        ary.append(s)
count = Counter(ary)
s = set(count.keys())
cnb = list(itertools.combinations(s,3))
ans = 0
for a,b,c in cnb:
    ans += count[a] * count[b] * count[c]
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
s = set([input() for _ in range(n)])
cnt = []
for i in s:
    if i[0] in "MARCH":
        cnt.append(i[0])

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

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

Submission status: Accepted

Solution code:
from collections import defaultdict as dd
import sys
N = int(input())
D = dd(int)
D["M"] = 0
D["A"] = 0
D["R"] = 0
D["C"] = 0
D["H"] = 0

for i in range(N):
  s = input()[0]
  if any((s == "M", s == "A", s == "R", s == "C", s == "H")):
    D[s] += 1
ans = 0
tpls = (("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"))

for t in tpls:
    ans += D[t[0]] * D[t[1]] * D[t[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()
  f = s[0]
  if f == 'M':
    m += 1
  elif f == 'A':
    a += 1
  elif f == 'R':
    r += 1
  elif f == 'C':
    c += 1
  elif f == 'H':
    h += 1

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

Submission status: Accepted

Solution code:
from itertools import combinations

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

chenge = list("MARCH")
d = dict()
for i, c in enumerate(chenge):
    d[c] = i

cnt = [0] * 5

for s in S:
    if s[0] in chenge:
        cnt[d[s[0]]] += 1

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
from itertools import combinations
N =int(input())
B = []
for i in range(N):
  S = list(input())
  if S[0]=="M" or S[0]=="A" or S[0]=="R" or S[0]=="C" or S[0]=="H":
    B.append(S[0])
B = Counter(B)
l = ["M","A","R","C","H"]
ans = 0
for a,b,c in combinations(l, 3):
  if a in B.keys() and b in B.keys() and c in B.keys():
    ans += B[a]*B[b]*B[c]
print(ans)

Submission status: Accepted

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

check=['M','A','R','C','H']
cnt=[0]*5
for i in range(n):
  for j in range(5):
    if S[i][0]==check[j]:
      cnt[j]+=1
      break
ans=0
for i in range(2**5):
  tmp=1
  flag=0
  for j in range(5):
    if i>>j&1:
      tmp*=cnt[j]
      flag+=1
  if flag==3:
    ans+=tmp
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
cnt_M=0
cnt_A=0
cnt_R=0
cnt_C=0
cnt_H=0
for _ in range(N):
    s=input()[0]
    if s=='M':
        cnt_M+=1
    elif s=='A':
        cnt_A+=1
    elif s=='R':
        cnt_R+=1
    elif s=='C':
        cnt_C+=1
    elif s=='H':
        cnt_H+=1
arr=[cnt_M, cnt_A, cnt_R, cnt_C, cnt_H]
ans=0
for i in range(5):
    for j in range(5):
        for k in range(5):
            if i!=j and j!=k and k!=i:
                ans+=arr[i]*arr[j]*arr[k]

print(ans//6)

Submission status: Accepted

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

ans = 0
for items in combinations(march, 3):
  ans += dic[items[0]] * dic[items[1]] * dic[items[2]]
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=[]
a,b,c,d,e=0,0,0,0,0
for i in range(n):
  S=input()
  if S[0]=='M':
    a+=1
  if S[0]=='A':
    b+=1
  if S[0]=='R':
    c+=1
  if S[0]=='C':
    d+=1
  if S[0]=='H':
    e+=1
print(a*b*c+a*b*d+a*b*e+a*c*d+a*c*e+a*d*e+b*c*d+b*c*e+b*d*e+c*d*e)

Submission status: Accepted

Solution code:
import itertools

N = int(input())

M = [0, 0, 0, 0, 0]

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

ans = 0
for a, b, c in list(itertools.combinations(M, 3)):
    ans += a * b * c

print(ans)

Submission status: Accepted

Solution code:
import sys
from functools import reduce
import copy
import math
from pprint import pprint


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    persons = inputs
    N = 5
    kinds = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0, }
    for n in persons:
        if n[0] in kinds:
            kinds[n[0]] += 1
    kinds_list = list(kinds.keys())

    if len(persons) < 3:
        return 0

    pattern = 0
    for i in range(N-2):
        for j in range(i+1, N-1):
            for k in range(j+1, N):
                p1 = kinds_list[i]
                p2 = kinds_list[j]
                p3 = kinds_list[k]
                pattern += kinds[p1] * kinds[p2] * kinds[p3]
    return pattern


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    N = int(input())
    ret = solve(inputs(N))
    print(ret)

Submission status: Accepted

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

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

for x in s:
    if x[0] in 'MARCH':
        d[x[0]] += 1

res = 0
march = 'MARCH'
for i in range(3):
    for j in range(i+1, 4):
        for k in range(j+1, 5):
            res += d[march[i]] * d[march[j]] * d[march[k]]

print(res)

Submission status: Accepted

Solution code:
n = int(input())
li = set(list("MARCH"))

name_li = set()
name = dict()

for i in range(n):
    s = input()
    if s[0] in li:
        name.setdefault(s[0], 0)
        name[s[0]] += 1
        name_li.add(s[0])

import itertools
c_list = list(itertools.combinations(name_li, 3))

ans = 0

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

Submission status: Accepted

Solution code:
# ABC089 C - March
N = int(input())
S = [input() for i in range(N)]

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]

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

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

ans = 0
D = []
D.append(m)
D.append(a)
D.append(r)
D.append(c)
D.append(h)

for d in range(10):
    ans += D[x[d]]*D[y[d]]*D[z[d]]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = [input() for _ in range(N)]
L = ['M', 'A', 'R', 'C', 'H']
dict_S = {}

for i in range(N):
    moji = S[i][0]
    if moji in L:
        if moji not in dict_S:
            dict_S[moji] = 1
        else:
            dict_S[moji] += 1

keys = len(dict_S.keys())
values = list(dict_S.values())

if keys < 3 or keys == None:
    print(0)
else:
    x = 0
    for i in range(keys):
        for j in range(i+1, keys):
            for k in range(j+1, keys):
                x += values[i] * values[j] * values[k]
    print(x)

Submission status: Accepted

Solution code:
N = int(input())

cnt = [0 for _ in range(5)]
ch = "MARCH"

for _ in range(N):
    S = input()
    for i in range(5):
        if S[0] == ch[i]:
            cnt[i] += 1

ans = 0
ans += cnt[0]*cnt[1]*cnt[2]
ans += cnt[0]*cnt[1]*cnt[3]
ans += cnt[0]*cnt[1]*cnt[4]
ans += cnt[0]*cnt[2]*cnt[3]
ans += cnt[0]*cnt[2]*cnt[4]
ans += cnt[0]*cnt[3]*cnt[4]

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

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

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
count=0
import itertools
N=int(input())
S=[input() for i in range(N)]
a = ['M', 'A','R', 'C', 'H']
b=[0]*5
for s in S:
    try:    
        b[a.index(s[0])]+=1
    except ValueError:pass
l=list(itertools.combinations(b,3))
for c in l:
    tmp=1
    for i in range(3):
        tmp*=c[i]
    count+=tmp
print(count)

Submission status: Accepted

Solution code:
N=int(input())
name=[input()[0] for _ in range(N)]
m=name.count("M")
a=name.count("A")
r=name.count("R")
c=name.count("C")
h=name.count("H")
print(m*a*(r+c+h)+m*r*(c+h)+m*c*h+a*r*(c+h)+a*c*h+r*c*h)

Submission status: Accepted

Solution code:
from itertools import combinations

n=int(input())
march=[0]*5

for _ in range(n):
    initial=input()[0]
    if initial in "MARCH":
        march["MARCH".index(initial)]+=1

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

Submission status: Accepted

Solution code:
import sys
from collections import Counter
from itertools import combinations


def input(): return sys.stdin.readline().strip()


def solve(S):
    c = Counter(S)

    # 文字が3種類未満
    if len(c.keys()) < 3:
        return 0

    # 人数が3人未満
    if sum(c.values()) < 3:
        return 0

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

    return ans


def main():
    N = int(input())
    S = [input()[0] for _ in range(N)]
    print(solve(S))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    s="MARCH"
    n=int(input())
    k=[0]*5
    for _ in range(n):
        t=input()[0]
        if t in s: k[s.index(t)]+=1
    from itertools import combinations
    A=combinations(range(5),3)
    ans=0
    for a,b,c in A:
        ans+=k[a]*k[b]*k[c]
    print(ans)
resolve()

Submission status: Accepted

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

march = [0] * 5
for c in s:
    if c in 'MARCH':
        march['MARCH'.index(c)] += 1

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

Submission status: Accepted

Solution code:
def factorial(n):
    res = 1
    for i in range(1, n + 1):
        res *= i
    return res


def combination(n, r):
    return factorial(n) // (factorial(r) * factorial(n - r))


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

march = [0] * 5
for c in s:
    if c in 'MARCH':
        march['MARCH'.index(c)] += 1

k = sum(x > 0 for x in march)
if k < 3:
    print(0)
    exit()


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

Submission status: Accepted

Solution code:
N = int(input())
MARCH = [0]*5
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
    else:
        continue

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:
n = int(input())
m=a=r=c=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
  else:
    continue
march = [m,a,r,c,h]
march.sort()
if march[0] == march[1] == march[2] == 0:
  print(0)
elif march[0] == march[1] == 0:
  print(march[2]*march[3]*march[4])
elif march[0] == 0:
  print(march[1]*march[2]*march[3]
  +march[2]*march[3]*march[4]
  +march[3]*march[4]*march[1]
  +march[4]*march[1]*march[2])
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=[]
for i in range(n):
    t=str(input())
    if t[0] in 'MARCH':
        s.append(t[0])
#s.sort()
if s==[]:
    print(0)
else:
    l=[]
    l.append(s.count('M'))
    l.append(s.count('A'))
    l.append(s.count('R'))
    l.append(s.count('C'))
    l.append(s.count('H'))
    ans=0
    #print(l)
    for i in range(5):
        for j in range(i+1,5):
            for k in range(j+1,5):
                ans+=l[i]*l[j]*l[k]
                #print(l[i],l[j],l[k])
    print(ans)

Submission status: Accepted

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


def main():
    N = int(input())
    D = defaultdict(int)
    for _ in range(N):
        S = input()
        D[S[:1]] += 1
    
    ans = 0
    for initials in itertools.combinations(['M','A','R','C','H'], 3):
        a = 1
        for i in initials:
            a *= D[i]
        ans += a
    
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter
import itertools

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

ans = 0

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

Submission status: Accepted

Solution code:
n = int(input())
marchSentence = ["M", "A", "R", "C", "H"]
marchCount = [0, 0, 0, 0, 0]
marchSum = 0
for i in range(n):
    s = input()
    if marchSentence.count(s[0]) > 0:
        num = marchSentence.index(s[0])
        if num > -1:
            marchCount[num] += 1

for a in range(0, 3):
    for b in range(a + 1, 4):
        for c in range(b + 1, 5):
            marchSum += marchCount[a] * marchCount[b] * marchCount[c]
print(marchSum)

Submission status: Accepted

Solution code:
n = int(input())
marchSentence = ["M", "A", "R", "C", "H"]
marchCount = [0, 0, 0, 0, 0]
marchSum = 0
for i in range(n):
    s = input()
    sa = s[0]
    if marchSentence.count(sa) > 0:
        num = marchSentence.index(s[0])
        if num > -1:
            marchCount[num] += 1

for a in range(0, 3):
    for b in range(a + 1, 4):
        for c in range(b + 1, 5):
            marchSum += marchCount[a] * marchCount[b] * marchCount[c]
print(marchSum)

Submission status: Accepted

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

comb = itertools.combinations(list(range(5)), 3)
ans = 0
for i in comb:
    ans += march[i[0]] * march[i[1]] * march[i[2]]
print(ans)

Submission status: Accepted

Solution code:
# ABC089C - March
from itertools import combinations as comb


def main():
    N, *S = open(0).read().split()
    capitals = [s[0] for s in S]
    cnt = [capitals.count(i) for i in "MARCH"]
    ans = sum(x * y * z for x, y, z in comb(cnt, 3))
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ABC089C - March
from itertools import combinations as comb


def main():
    N, *S = open(0).read().split()
    cnt = [sum(s.startswith(i) for s in S) for i in "MARCH"]
    ans = sum(x * y * z for x, y, z in comb(cnt, 3))
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

sss = list(ss.values())
res = 0
if len(ss.keys()) <= 2:
    res = 0
elif len(ss.keys()) == 3:
    res = sss[0] * sss[1] * sss[2]
elif len(ss.keys()) == 4:
    res = sss[0] * sss[1] * sss[2] + sss[0] * sss[1] * sss[3] + sss[0] * sss[2] * sss[3] + sss[1] * sss[2] * sss[3]
elif len(ss.keys()) == 5:
    res = sss[0] * sss[1] * sss[2] + sss[0] * sss[1] * sss[3] + sss[0] * sss[1] * sss[4] + sss[0] * sss[2] * sss[3] \
          + sss[0] * sss[2] * sss[4] + sss[0] * sss[3] * sss[4] + sss[1] * sss[2] * sss[3] + sss[1] * sss[2] * sss[4] \
          + sss[1] * sss[3] * sss[4] + sss[2] * sss[3] * sss[4]
print(res)

Submission status: Accepted

Solution code:
from itertools import combinations
from collections import Counter

N = int(input())
S = Counter()
for _ in range(N):
    S[input()[0]] += 1
print(sum([S[a]*S[b]*S[c] for a, b, c in combinations('MARCH', 3)]))

Submission status: Accepted

Solution code:
N=int(input())
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 i in range(5):
  for j in range(i+1,5):
    for k in range(j+1,5):
      ans+=M[i]*M[j]*M[k]
print(ans)

Submission status: Accepted

Solution code:
import itertools

n = int(input())


def add(dict, str):
    if not str[0] in dict:
        dict[str[0]] = []
    dict[str[0]].append(str)


march = {}
for _ in range(n):
    s_i = input()
    if 'M' == s_i[0] or 'A' == s_i[0] or 'R' == s_i[0] or 'C' == s_i[0] or 'H' == s_i[0]:
        add(march, s_i)

key_combination = list(itertools.combinations(list(march), 3))
count = 0
for case in key_combination:
    indiv_count = 1
    for key in case:
        if not key in march:
            indiv_count = 0
            break
        indiv_count *= len(march[key])
    count += indiv_count
print(count)

Submission status: Accepted

Solution code:
import itertools

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


def add(dict, str):
    if not str[0] in dict:
        dict[str[0]] = []
    dict[str[0]].append(str)


march = {}
for s_i in s:
    if 'M' == s_i[0] or 'A' == s_i[0] or 'R' == s_i[0] or 'C' == s_i[0] or 'H' == s_i[0]:
        add(march, s_i)

key_combination = list(itertools.combinations(list(march), 3))
count = 0
for case in key_combination:
    indiv_count = 1
    for key in case:
        if not key in march:
            indiv_count = 0
            break
        indiv_count *= len(march[key])
    count += indiv_count
print(count)

Submission status: Accepted

Solution code:
N = int(input())
M = 0
A = 0
R = 0
C = 0
H = 0

for _ in range(N):
  tmp = input()[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

ans = 0
ans += M * A * C
ans += M * A * R
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)