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:
def main():
    N = int(input())
    names = []
    for _ in range(N):
        names.append(input())
    d = dict()
    for s in names:
        if s[0] in "MARCH":
            d[s[0]] = d.get(s[0], 0) + 1
    ans = 0
    for c0 in d:
        for c1 in d:
            for c2 in d:
                if c0 < c1 < c2:
                    ans += d[c0]*d[c1]*d[c2]
    return ans

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

Submission status: Accepted

Solution code:
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
from itertools import combinations
t=list(combinations(range(5),3))
a=0
for i in range(10):
    a+=l[t[i][0]]*l[t[i][1]]*l[t[i][2]]
print(a)

Submission status: Accepted

Solution code:
import itertools

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

#MARCH
L = [0]*5
for i in range(N):
    if S[i][0]=="M":
        L[0] += 1
    elif S[i][0]=="A":
        L[1] += 1
    elif S[i][0]=="R":
        L[2] += 1
    elif S[i][0]=="C":
        L[3] += 1
    elif S[i][0]=="H":
        L[4] += 1

res = 0
for l in itertools.permutations(L,3):
    c = 1
    for x in l:
        c *= x
    res += c
print(res//6)

Submission status: Accepted

Solution code:
import collections, itertools
n = int(input())
s = collections.Counter([input()[0] for _ in range(n)])
ls = list("MARCH")
t = 0
for i in itertools.combinations(ls, 3):
    t += s[i[0]] * s[i[1]] * s[i[2]]
print(t)

Submission status: Accepted

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

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(5):
    for j in range(5):
        for k in range(5):
            if i >= j or i >= k or j >= k:
                continue
            ans += march[i] * march[j] * march[k]
            
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from itertools import combinations
from collections import defaultdict
n=int(input())
S=tuple(input().strip() for _ in range(n))
d=defaultdict(int)
A=('M','A','R','C','H')
for i in range(n):
    tmp=S[i][0]
    if tmp in A:
        d[tmp]+=1
B=[]
for a in A:
    if d[a]:
        B.append(a)
if len(B)<3:
    print(0)
else:
    ans=0
    for i in combinations(B,3):
        tmp=1
        for j in range(3):
            tmp*=d[i[j]]
        ans+=tmp
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
li = [["M",0],["A",0],["R",0],["C",0],["H",0]]
ans = 0
for i in range(N):
    tmp = str(input())
    if tmp[0]=="M" or tmp[0]=="A" or tmp[0]=="R" or tmp[0]=="C" or tmp[0]=="H":
        for j in range(5):
            if tmp[0]==li[j][0]:
                li[j][1] += 1
                break

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

Submission status: Accepted

Solution code:
n = int(input())
s = [input() for _ in range(n)]
STR = "MARCH"
cnt = {c:0 for c in STR}
for ss in s:
  if ss[0] in STR:
    cnt[ss[0]] += 1
    
ans = 0
for i1 in range(5):
  for i2 in range(i1+1, 5):
    for i3 in range(i2+1, 5):
      ans += cnt[STR[i1]]*cnt[STR[i2]]*cnt[STR[i3]]

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
C = [0] * 5
prefix = 'MARCH'

for i in range(N):
    s = input().rstrip()[0]
    if s in prefix:
        C[prefix.find(s)] += 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:
from collections import Counter
n=int(input())
name=[]
initial={"M":0,
         "A":0,
         "R":0,
         "C":0,
         "H":0}
for _ in range(n):
    s=input()
    if s[0] in ["M","A","R","C","H"]:
        initial[s[0]]+=1
num=[v for k,v in initial.items()]

if len(num)<3:
    print(0)
else:
    ans=0
    for i in range(len(num)-2):
        for j in range(i+1,len(num)-1):
            for k in range(j+1,len(num)):
                #print(i,j,k)
                ans+=num[i]*num[j]*num[k]
    print(ans)

Submission status: Accepted

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

# print(names)

count = 0
candidate = ["M", "A", "R", "C", "H"]

M = len(sorted([name for name in names if name[0] == candidate[0]]))
A = len(sorted([name for name in names if name[0] == candidate[1]]))
R = len(sorted([name for name in names if name[0] == candidate[2]]))
C = len(sorted([name for name in names if name[0] == candidate[3]]))
H = len(sorted([name for name in names if name[0] == candidate[4]]))

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())
A=[0]*5
count=0
for i in range(N):
    S=input()
    if S[0]=='M':
        A[0]+=1
    if S[0]=='A':
        A[1]+=1
    if S[0]=='R':
        A[2]+=1
    if S[0]=='C':
        A[3]+=1
    if S[0]=='H':
        A[4]+=1

for i in range(5):
    for j in range(i):
        for k in range(j):
            if i!=j and j!=k and k!=i:
                count+=A[i]*A[j]*A[k]
print(count)

Submission status: Accepted

Solution code:
import itertools
N = int(input())
s = "MARCH"
dct = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for i in range(N):
  begin = input()[0] 
  if begin in dct.keys():
    dct[begin] += 1
cmb = itertools.combinations(list(dct.keys()), 3)
ans = 0
for i in list(cmb):
  n = 1
  for j in i:
    n *= dct[j]
  ans += n
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
march = {'m': 0, 'a': 0, 'r': 0, 'c': 0, 'h': 0}
for i in range(n):
  s = input()[0].lower()
  try:
    march[s] += 1
  except:
    pass
ans = 0

for key1 in march.keys():
  for key2 in march.keys():
    if key1 != key2:
      for key3 in march.keys():
        if key3 != key1 and key3 != key2:
          ans += march[key1] * march[key2] * march[key3]
print(ans//6)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline

h = {}
for c in "MARCH":
    h[c] = 0

for i in range(int(input())):
    c = input().strip()[0]
    if c in h:
        h[c] += 1

import itertools
ans = 0
for i,j,k in itertools.combinations("MARCH", 3):
    ans += h[i]*h[j]*h[k]
print(ans)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline

n = int(input())
a = [0]*5
for i in range(n):
    s = input().strip()
    c = s[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
#print(a)

ans = 0
for i in range(0, len(a)-2):
    for j in range(i+1, len(a)):
        for k in range(j+1, len(a)):
#            print(i,j,k, a[i]*a[j]*a[k])
            ans += a[i]*a[j]*a[k]
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
from itertools import combinations as comb



initial_dict = defaultdict(int)
n = int(input())
for i in range(n):
    initial = input()[0]
    if initial in 'MARCH':
        initial_dict[initial] += 1



ret = 0
for i, j, k in comb('MARCH', 3):
    ret += initial_dict[i] * initial_dict[j] * initial_dict[k]


print(ret)

Submission status: Accepted

Solution code:
from collections import defaultdict
from itertools import combinations


N = int(input())
d = defaultdict(int)
for _ in range(N):
    S = input()
    if S[0] in 'MARCH':
        d[S[0]] += 1

ans = 0
for a, b, c in combinations('MARCH', 3):
    ans += d[a] * d[b] * d[c]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

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

ans = 0
count = list(count.items())
for i in range(len(count)):
    for j in range(i + 1, len(count)):
        for k in range(j + 1, len(count)):
            ans += count[i][1] * count[j][1] * count[k][1]

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
dic = {"M":0,"A":0,"R":0,"C":0,"H":0}
for i in range(n):
    s = input()
    if s[0] in ["M","A","R","C","H"]:
        dic[s[0]]+=1
l = [dic["M"],dic["A"],dic["R"],dic["C"],dic["H"]]
count = 0
for i in range(5):
    for j in range(5):
        for k in range(5):
            if i<j and j<k:
                count += l[i]*l[j]*l[k]
print(count)

Submission status: Accepted

Solution code:
from collections import defaultdict
from itertools import combinations

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

    S = defaultdict(int)

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

    ans = 0

    # 文字を3種類ピックアップする組み合わせごとに数を求めて
    # 足し合わせる
    for a, b, c in combinations(S.values(), 3):
        ans += a * b * c

    print(ans)
main()

Submission status: Accepted

Solution code:
from itertools import combinations
box=list(list(input())[0] for i in range(int(input())))
count=[0,0,0,0,0]
for i in box:
    if i=="M":count[0] +=1
    elif i=="A":count[1] +=1
    elif i=="R":count[2] +=1
    elif i=="C":count[3] +=1
    elif i=="H":count[4] +=1
point=0
for i,j,k in combinations(count,3):
    point +=i*j*k
print(point)

Submission status: Accepted

Solution code:

import collections
import itertools

def getint(): return int(input())
def getints(): return list(map(int, input().split()))

n = getint()
s = [input() for _ in range(n)]
c = collections.Counter()

for h in s:
    c[h[0]] += 1

res = 0
for perm in itertools.combinations("MARCH", 3):
    res += c[perm[0]] * c[perm[1]] * c[perm[2]]

print(res)

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

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

Submission status: Accepted

Solution code:
time = [0,0,0,0,0]
def suc(time):
  point = 5-1
  while point >= 0:
    if time[point] == 0:
      time[point] = 1
      return time
      break
    else:
      time[point] = 0
      point -= 1
  else:
    return 'over'
n = int(input())
s = [0 for _ in range(5)]
for i in range(n):
  now = input()[0]
  if now == 'M':
    s[0] += 1
  elif now == 'A':
    s[1] += 1
  elif now == 'R':
    s[2] += 1
  elif now == 'C':
    s[3] += 1
  elif now == 'H':
    s[4] += 1
ans = 0
while time != 'over':
  if sum(time) != 3:
    pass
  else:
    tmp = 1
    for j in range(5):
      if time[j] == 1:
        tmp *= s[j]
    ans += tmp
    #print(tmp,time)
  time = suc(time)
#print(s)
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):
    b = input()
    if b.startswith("M"):m+=1
    if b.startswith("A"):a+=1
    if b.startswith("R"):r+=1
    if b.startswith("C") : c += 1
    if b.startswith("H") : h += 1
l = [m,a,r,c,h]
#print(l)
ans = 0
for i in range(5):
    for j in range(i+1,5):
        for m in range(j+1,5):
            ans += l[i]*l[j]*l[m]
print(ans)

Submission status: Accepted

Solution code:
import collections
import itertools

N = int(input())
ss = [input() for _ in range(N)]
s = [i[0] for i in ss if i[0] in ["M", "A", "R", "C", "H"]]
c = collections.Counter(s)

# print(c)

l = list(itertools.combinations(c,3))

# print(l)

ans = sum([c[i[0]] * c[i[1]] * c[i[2]] for i in l])

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
from itertools import combinations
from functools import reduce

N = int(input())

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

# solve

nd = defaultdict(int)

for name in S:
    if name[0] in "MARCH":
        nd[name[0]] += 1

if len(nd.keys()) < 3:
    print(0)
    exit()

ans = 0
for trio in combinations(nd.keys(), 3):
    # ans += [nd[x] for x in trio]
    # ans += reduce((lambda x, y: nd[x] * nd[y]), trio)
    ans += nd[trio[0]] * nd[trio[1]] * nd[trio[2]]

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = [input() for i in range(N)]
c = "MARCH"
num = []
for i in range(5):
    count = 0
    for j in range(N):
        if S[j][0] == c[i]:
            count += 1
    num.append(count)
ans = 0
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            ans += num[i]*num[j]*num[k]
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
P = Counter((x for _ in range(N) for x in input()[0] if x in "MARCH"))
Pidx = list(P.keys())
def mycount(i, ptn, c):
    #print((i,ptn,c))
    if c <= 0:
        return ptn
    elif len(P) - i < c:
        return 0
    return mycount(i+1, ptn, c) + mycount(i+1, ptn * P[Pidx[i]], c - 1)
#print(Pidx)
print(mycount(0, 1, 3))

Submission status: Accepted

Solution code:
n = int(input())
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

lst = []
for i in range(2**5):
    s = format(i,'b').rjust(5,'0')
    if s.count('1') == 3:
        lst.append(s)

ans = 0
for l in lst:
    c = 1
    for i in range(5):
        if l[i] == '1':
            c *= name[i]
    ans += c
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

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

Submission status: Accepted

Solution code:
n = int(input())
m = 0
a = 0
r = 0
c = 0
h = 0

for i in range(n):
  s = str(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
  else:
    continue
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 itertools import combinations
n = int(input())
names = [input()[0] for _ in range(n)]
li = [0]*5
for i,c in enumerate("MARCH"):
	cnt = 0
	for name in names:
		if c == name:
			cnt += 1
	li[i] = cnt
ans = 0
for i,j,k in combinations(li,3):
	ans += i*j*k
print(ans)

Submission status: Accepted

Solution code:
a = int(input())
b = [input() for i in range(a)]
c = ['a']*a
for i in range(a):
    c[i] = b[i][0]
h = c.count('H')
m = c.count('M')
a = c.count('A')
r = c.count('R')
c1 = c.count('C')
ansm = m*a*h + m*a*c1 + m*a*r + m*r*h + m*r*c1 + m*c1*h
ansa = a*r*h + a*r*c1 + a*c1*h
ansr = r*c1*h
print(ansm+ansa+ansr)

Submission status: Accepted

Solution code:
N = int(input())
S = [0] * N
m = 0
a = 0
r = 0
c = 0
h = 0

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

l = [m, a, r, c, h]
for i in range(0,3):
    for j in range(i+1,4):
        for k in range(j+1, 5):
            ans += l[i] * l[j] * l[k]

print(ans)

Submission status: Accepted

Solution code:
S = int(input())

name = [input() for _ in range(S)]

l = [0]*5
M=A=R=C=H=0
for i in range(S):
	if name[i][0] == "M":
		l[0] += 1
	if name[i][0] == "A":
		l[1] += 1
	if name[i][0] == "R":
		l[2] += 1
	if name[i][0] == "C":
		l[3] += 1
	if name[i][0] == "H":
		l[4] += 1

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

print(ans)

Submission status: Accepted

Solution code:

n = int(input())
li = [input()[0] for _ in range(n)]
count = [0, 0, 0, 0, 0]
name_index = ["M", "A", "R", "C", "H"]
li = [i for i in li if i in name_index ] 
for i in li:
    count[name_index.index(i)]+= 1
ans = 0

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

Submission status: Accepted

Solution code:
n=int(input())
s={"M":0,"A":0,"R":0,"C":0,"H":0}
for i in range(n):
    v=input()
    if v[0] in s:
        s[v[0]]+=1
l=list(s.values())
ans=0
for a in range(5):
    for b in range(a+1,5):
        for c in range(b+1,5):
            ans+=l[a]*l[b]*l[c]         
print(ans)

Submission status: Accepted

Solution code:
import itertools
n=int(input())
s=[input() for i in range(n)]
m=['M','A','R','C','H']
c=[0 for i in range(5)]
ans=0

for i in range(5):
    for j in range(n):
        if s[j][0].count(m[i])==1:
            c[i]+=1



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

Submission status: Accepted

Solution code:
n=int(input())
s=[input()[0] for _ in [0]*n]
l=['M','A','R','C','H']
L=[s.count(x) for x in l]
a=0
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            a+=L[i]*L[j]*L[k]
print(a)

Submission status: Accepted

Solution code:
import itertools

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

m = S.count('M')
a = S.count('A')
r = S.count('R')
c = S.count('C')
h = S.count('H')

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

j = 0
p = list(itertools.combinations(ans,3))
for i in p:
    j += i[0]*i[1]*i[2]

print(j)

Submission status: Accepted

Solution code:
from itertools import combinations
N = int(input())
m = [0] * 5
for _ in range(N):
    S = input()
    cand = ("M", "A", "R", "C", "H")
    if S[0] in cand:
        m[cand.index(S[0])] += 1
ans = 0
for i, j, k in combinations(range(5), 3):
    ans += m[i] * m[j] * m[k]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = list(input() for _ in range(n))
m,a,r,c,h = 0,0,0,0,0

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

ans = 0
cnt = 0
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:
  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
N = int(input())
S = [input() for _ in range(N)]
lis = []
for i in range(N):
    for j in ['M','A','R','C','H']:
        if S[i][0] == j:
            lis.append(j)

cnt = [lis.count('M'),lis.count('A'),lis.count('R'),lis.count('C'),lis.count('H')]
ans = 0
for a, b, c in itertools.combinations(cnt, 3):
    ans += a*b*c
print(ans)

Submission status: Accepted

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


def solve(N: int, S: "List[str]"):
    m = len([i for i in S if i[0] == 'M'])
    a = len([i for i in S if i[0] == 'A'])
    r = len([i for i in S if i[0] == 'R'])
    c = len([i for i in S if i[0] == 'C'])
    h = len([i for i in S if i[0] == '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
        )

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = [ next(tokens) for _ in range(N) ]  # type: "List[str]"
    solve(N, S)

if __name__ == '__main__':
    main()

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 i in range(n):
  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
li=[m,a,r,c,h]
li.sort(reverse=True)
if li[2]==0:
  print(0)
else:
  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:
N = int(input())
char_lst = ['M', 'A', 'R', 'C', 'H']
counts = {'M' : 0, 'A': 0, 'R':0, 'C': 0, 'H': 0}
for i in range(N):
    S = input()
    if S[0] in char_lst:
        counts[S[0]] += 1
            
ans = 0
for i in range(len(char_lst) - 2):
    for j in range(i + 1, len(char_lst) - 1):
        for k in range(j + 1, len(char_lst)):
            ans += counts[char_lst[i]] * counts[char_lst[j]] * counts[char_lst[k]]
            
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = []
for i in range(N):
    t = input()
    if t[0] == "M" or t[0] == "A" or t[0] == "R" or t[0] == "C" or t[0] == "H":
        S.append(t[0])
l = len(S)
S_set = set(S)
count_list = []
for i in S_set:
    count_list.append(S.count(i))
if len(S_set) == 3:
    ans = count_list[0] * count_list[1] * count_list[2]
elif len(S_set) == 4:
    ans = count_list[0] * count_list[1] * count_list[2] + count_list[0] * count_list[1] * count_list[3] + count_list[0] * count_list[2] * count_list[3] + count_list[1] * count_list[2] * count_list[3]
elif len(S_set) == 5:
    tmp0 = count_list[0] * count_list[1] * count_list[2] + count_list[0] * count_list[1] * count_list[3] + count_list[0] * count_list[1] * count_list[4]
    tmp1 = count_list[0] * count_list[2] * count_list[3] + count_list[0] * count_list[2] * count_list[4] + count_list[0] * count_list[3] * count_list[4]
    tmp2 = count_list[1] * count_list[2] * count_list[3] + count_list[1] * count_list[2] * count_list[4] + count_list[1] * count_list[3] * count_list[4]
    tmp3 = count_list[2] * count_list[3] * count_list[4]
    ans = tmp0 + tmp1 + tmp2 + tmp3
else:
    ans = 0
print(ans)

Submission status: Accepted

Solution code:
import itertools
N = int(input())
nm = []
for i in range(N):
    S = input()
    nm.append(S[0])
tm = [nm.count(i) for i in str('MARCH')]
f = [(n == 0) for n in tm]
ans = 0
for i,j,k in itertools.combinations(range(5), 3):
    ans += tm[i]*tm[j]*tm[k] 
print(ans)

Submission status: Accepted

Solution code:
#ABC 80, C - March
from itertools import combinations
from collections import Counter

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


C = Counter(S)
total = 0
for comb in combinations('MARCH', 3):
    total += C[comb[0]] * C[comb[1]] * C[comb[2]]
print(total)

Submission status: Accepted

Solution code:
N = int(input())
names = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
FIRST = ('M', 'A', 'R', 'C', 'H')
for _ in range(N):
  name = input()
  if name[0] in FIRST:
    names[name[0]] += 1
ans = 0
for i in range(5):
  for j in range(i+1, 5):
    for k in range(j+1, 5):
      ans += names[FIRST[i]]*names[FIRST[j]]*names[FIRST[k]]
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
#ABC088C
import sys

n = int(input())
num_m = 0
num_a = 0
num_r = 0
num_c = 0
num_h = 0
for i in range(0,n):
	tmp = input()
	if(tmp[0]=='M'):
		num_m += 1
	if(tmp[0]=='A'):
		num_a += 1
	if(tmp[0]=='R'):
		num_r += 1
	if(tmp[0]=='C'):
		num_c += 1
	if(tmp[0]=='H'):
		num_h += 1

sum=0
sum+=num_m*num_a*num_r
sum+=num_m*num_a*num_c
sum+=num_m*num_a*num_h
sum+=num_m*num_r*num_c
sum+=num_m*num_r*num_h
sum+=num_m*num_c*num_h
sum+=num_a*num_r*num_c
sum+=num_a*num_r*num_h
sum+=num_a*num_c*num_h
sum+=num_r*num_c*num_h

print(sum)
#print(num_m)
#print(num_a)
#print(num_r)
#print(num_c)
#print(num_h)

Submission status: Accepted

Solution code:
N = int(input())
Al = ['M', 'A', 'R', 'C', 'H']
S = {}
for _ in range(N):
    s = input()[0]
    if s in Al:
        if not s in S.keys():
            S[s] = 1
        else:
            S[s] += 1
L = S.values()
if len(L) == 3:
    a, b, c = L
    ans = a*b*c
elif len(L) == 4:
    a, b, c ,d = L
    ans = a*b*c + a*b*d + a*c*d + b*c*d
elif len(L) == 5:
    a, b, c, d, e = L
    ans = a*b*c + a*b*d + a*c*d + b*c*d + a*b*e + a*c*e + a*d*e + b*c*e + b*d*e + c*d*e
else:
    ans = 0

print(ans)

Submission status: Accepted

Solution code:
import itertools

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

comb = list(itertools.combinations([M, A, R, C, H], 3))
answer = 0 

for i in comb:
  answer += (i[0]*i[1]*i[2])

print(answer)

Submission status: Accepted

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

ans = M * A * R + M * R * C + M * C * H + M * A * C + M * A * H + M * R * H + A * R * C + A * C * H + A * R * H + R * C * H

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
def main():
    N = int(input())
    s = []
    
    for i in range(N):
        tmp = input()
        s.append(tmp)
        
    m = 0
    a = 0
    r = 0
    c = 0
    h = 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
            
    #print("{} {} {} {} {}".format(m, a,r,c,h))
    total = (a*m*c) + (a*m*r) + (a*m*h) + (a*c*r) + (a*c*h) + (a*r*h) + (m*c*r) + (m*c*h) + (m*r*h) + (c*r*h)
            
    print(total)
	
if __name__ == "__main__":
	main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from itertools import combinations

M = 'MARCH'
d = {i: set() for i in M}
for _ in range(int(input())):
    s = input()
    if s[0] in M:
        d[s[0]].add(s)

cmb = list(combinations(M, 3))
ans = 0
for c in cmb:
    t = 1
    for k in c:
        t *= len(d[k])
    ans += t

print(ans)

Submission status: Accepted

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

names = {}
for s in S:
    initial = s[0]
    if initial not in names:
        names[initial] = 0
    names[initial] += 1

initial_keys = set(names.keys()).intersection({"M", "A", "R", "C", "H"})
if len(initial_keys) < 3:
    print(0)
else:
    initials = ["M", "A", "R", "C", "H"]
    count = 0
    for i in range(len(initials)-2):
        for j in range(i+1, len(initials)-1):
            for k in range(j+1, len(initials)):
                count += (names.get(initials[i], 0) * names.get(initials[j], 0) * names.get(initials[k], 0))
    print(count)

Submission status: Accepted

Solution code:
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
import heapq
INF = float("inf")
sys.setrecursionlimit(10**7)
# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def mi(): return map(int, input().split())
def ii(): return int(input())
###template###

N = ii()
nums = [0 for _ in range(5)]
ans = 0

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

for i, j, k in combinations(range(5), 3):
  ans += nums[i] * nums[j] * nums[k]

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
dict = {
    "M":0,
    "A":0,
    "R":0,
    "C":0,
    "H":0
}
S = []
for _ in range(N):
    S = input()
    if S[0] == "M":
        dict[S[0]] += 1
    elif S[0] == "A":
        dict[S[0]] += 1
    elif S[0] == "R":
        dict[S[0]] += 1
    elif S[0] == "C":
        dict[S[0]] += 1
    elif S[0] == "H":
        dict[S[0]] += 1

ans = 0
ans += dict["M"] * dict["A"] * dict["R"]
ans += dict["M"] * dict["A"] * dict["C"]
ans += dict["M"] * dict["A"] * dict["H"]
ans += dict["M"] * dict["R"] * dict["C"]
ans += dict["M"] * dict["R"] * dict["H"]
ans += dict["M"] * dict["C"] * dict["H"]
ans += dict["A"] * dict["R"] * dict["C"]
ans += dict["A"] * dict["R"] * dict["H"]
ans += dict["A"] * dict["C"] * dict["H"]
ans += dict["R"] * dict["C"] * dict["H"]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
d = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0, }
t = "MARCH"
for i in range(n):
    s = input()
    if s[0] in d:
        d[s[0]] += 1

ans = 0
for bits in range(1<<5):
    bits_list = [i for i in range(5) if (bits >> i) & 1 == 1]
    if len(bits_list) == 3:
        ans += d[t[bits_list[0]]] * d[t[bits_list[1]]] * d[t[bits_list[2]]]

print(ans)