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:
import itertools 
n=int(input())
a=[]
for i in range(n):
    a.append(str(input()))
march=[0]*5

for i in range(n):
    if a[i][0:1]=='M':
        march[0]+=1
    if a[i][0:1]=='A':
        march[1]+=1
    if a[i][0:1]=='R':
        march[2]+=1
    if a[i][0:1]=='C':
        march[3]+=1
    if a[i][0:1]=='H':
        march[4]+=1
#三人を選ぶほうほうのそれぞれのかずを懸けあわっせる
#print(march)

kumi_list=list(itertools.combinations([0,1,2,3,4],3))
#print(kumi_list)
ans=0
for i in kumi_list:
    b,c,d= i
    #print(b,c,d) 
    ans+=march[b]*march[c]*march[d]
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
l ='MARCH'
cnt=[0,0,0,0,0]
 
for i in range(n):
    s = input()
    for j in range(len(l)):
        if s[0]==l[j]: 
            cnt[j]+=1
 
ans = 0
for i in range(len(cnt)):
    for j in range(i+1, len(cnt)):
        for k in range(j+1, len(cnt)):
            ans += cnt[i]*cnt[j]*cnt[k]
        
print(ans)

Submission status: Accepted

Solution code:
import itertools

n=int(input())
name=("M","A","R","C","H")
name_cnt={}
for i in range(n):
    s=input()
    s0 = s[0]
    if s0 in name:
        if s0 in name_cnt.keys():
            name_cnt[s0] += 1
        else:
            name_cnt[s0] = 1
l=list(name_cnt.keys())

if len(l) < 3:
    print(0)
elif len(l) == 3:
    ans=1
    for v in name_cnt.values():
        ans *= v
    print(ans)
else:
    ans=0
    for c in itertools.combinations(l,3):
        ans1=1
        for i in c:
            ans1 *= name_cnt[i]
        ans += ans1
    print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
# coding: utf-8
from fractions import gcd 
from functools import reduce
import sys
sys.setrecursionlimit(200000000)
from inspect import currentframe


# my functions here!
#標準エラー出力
def printargs2err(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' : '+repr(arg) for arg in args),file=sys.stderr)
def debug(x):
    print(x,file=sys.stderr)
def printglobals():
    for (symbol, value) in globals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
def printlocals():
    for (symbol, value) in locals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
#入力（後でいじる）
def pin(type=int):
    return map(type,input().split())


"""
"""

#solution:
#繰り返し自乗法だよ
#これはnのp乗をmで割ったあまりをだすよ
def modular_w_binary_method (n,m,p):
    ans=1 if n>0 else 0
    while(p>0):
        if p%2==1:
            ans=(ans*n)%m
        n=(n**2)%m
        p//=2
    return ans

#mod上でのaの逆元を出すよ
"""
    フェルマーの小定理より a**(p)%p==a isTrue
    これを利用すれば a**(p-2)%p==a**(-1) isTrue
    元と逆元とをかけてpで割れば1が余るよ！
"""
def modular_inverse(a,prime):
    return(modular_w_binary_method(a,prime,prime-2))


#逆元を使うと容易に頑張れるｃ
def conbination(n,a,mod=10**9+7):
    #cはイラない
    res=1 
    for s in range(a):
        res=(res*(n-s)*(modular_inverse(s+1,mod)))%mod

        
    return res
#操作から作れるものの組み合わせは何個かー＞同じものでも違う方法で構成できるかから考える方法もある
        
#input
def resolve():
    N=int(input())
    S=([input()[0] for i in range(N)])
    MARCH=[0]*5
    c="MARCH"
    for item in S:
        for char in range(5):
            if item==c[char]:
                MARCH[char]+=1
    j=0
    for t in range(5):
        if MARCH[t]!=0:
            j+=1
    ans=0
    for x in range(5):
        for y in range(x+1,5):
            for z in range(y+1,5):
                if MARCH[x]*MARCH[y]*MARCH[z]!=0:
                    ans+=MARCH[x]*MARCH[y]*MARCH[z]
    print(ans)
    #print(["No","Yes"][cond])
    #print([["NA","YYMM"],["MMYY","AMBIGUOUS"]][cMMYY][cYYMM])
#if __name__=="__main__":resolve()
"""
#printデバッグ消した？
#前の問題の結果見てないのに次の問題に行くの？
"""
"""
お前カッコ閉じるの忘れてるだろ
"""
import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI"""
        output = """2"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """4
ZZ
ZZZ
Z
ZZZZZZZZZZ"""
        output = """0"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO"""
        output = """7"""
        self.assertIO(input, output)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

for _ in range(n):
  s=input()
  ss=s[0]
  if ss in ["M","A","R","C","H"]:
    dic[ss]=dic[ss]+1

keys=["M","A","R","C","H"]

i=0
result=0
while i<3:
  j=i+1
  while j<4:
    k=j+1
    while k<5:
      result+=dic[keys[i]]*dic[keys[j]]*dic[keys[k]]
      
      k+=1    
    j+=1  
  i+=1
print(result)

Submission status: Accepted

Solution code:
n = int(input())
count = [0]*5
d = {'M': 0, 'A': 1, 'R': 2, 'C':3, 'H': 4}

for i in range(n):
  s = input()
  if s[0] in 'MARCH':
    count[d[s[0]]] += 1

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

Submission status: Accepted

Solution code:
n = int(input())
dat = []
for _ in range(n):
    dat.append(input())
cm, ca, cr, cc, ch = 0,0,0,0,0
for i in range(n):
    if dat[i][0] == "M":
        cm += 1
    if dat[i][0] == "A":
        ca += 1
    if dat[i][0] == "R":
        cr += 1
    if dat[i][0] == "C":
        cc += 1
    if dat[i][0] == "H":
        ch += 1
#print(cm,ca,cr,cc,ch)

res = 0
res += cm*ca*cr
res += cm*ca*cc
res += cm*ca*ch
res += cm*cr*cc
res += cm*cr*ch
res += cm*cc*ch

res += ca*cr*cc
res += ca*cr*ch
res += ca*cc*ch

res += cr*cc*ch
print(res)

Submission status: Accepted

Solution code:
import collections

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

for i in range(N):
    s = input()
    if (s[0] in 'MARCH'):
        S.append(s[0])

CNT = collections.Counter(S).most_common()
ans = 0

if (len(CNT) >= 3):

    for i in range(len(CNT)):

        for j in range(i + 1, len(CNT)):

            for k in range(j + 1, len(CNT)):

                ans += CNT[i][1] * CNT[j][1] * CNT[k][1]

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
L = ['M','A','R','C','H']

A = [0] * 5

for i in range(n):
    s = input()
    if s[0] not in L:
        continue
    A[L.index(s[0])] += 1
import itertools
total = 0
for i in list(itertools.combinations(A,3)):
    a, b, c = i
    total += a*b*c
print(total)

Submission status: Accepted

Solution code:
N = int(input())
INI = ["M","A","R","C","H"]
c = [0]*5
for i in range(N):
    S = input()
    if S[0] in INI:
        c[INI.index(S[0])] += 1

ans = 0
for i in range(0,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:
n=int(input())
a=[0]*5
for i in range(n):
    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
res=0
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            res+=a[i]*a[j]*a[k]
print(res)

Submission status: Accepted

Solution code:
comp='MARCH'
cnt=[0,0,0,0,0]

n=int(input())
for i in range(n):
    word=input()
    for j in range(len(comp)):
        if word[0]==comp[j]: cnt[j]+=1

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

Submission status: Accepted

Solution code:
import itertools


N = int(input())
D = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
for i in range(N):
    s = input()
    if s[0] in D.keys():
        D[s[0]] += 1
ans = 0
for v in itertools.combinations(D.values(), 3):
    ans += v[0] * v[1] * v[2]
print(ans)

Submission status: Accepted

Solution code:
import itertools

n = int(input())
s = [0] * n
for _ in range(n):
    s[_] = input()
cnt = [0] * 5
for i in range(n):
    if s[i][0] == 'M':
        cnt[0] += 1
    elif s[i][0] == 'A':
        cnt[1] += 1
    elif s[i][0] == 'R':
        cnt[2] += 1
    elif s[i][0] == 'C':
        cnt[3] += 1
    elif s[i][0] == 'H':
        cnt[4] += 1
    else:
        pass

num = 0
newCnt = []
for i in range(5):
    if cnt[i] > 0:
        num += 1
        newCnt.append(cnt[i])

ans = 0
val = 1
if len(newCnt) < 3:
    ans = 0
elif len(newCnt) < 4:
    for i in range(len(newCnt)):
        val *= newCnt[i]
    ans = val
else:
    com = itertools.combinations(newCnt, 3)
    for i in com:
        val = 1
        for j in i:
            val *= j
        ans += val

print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
from collections import defaultdict
d = defaultdict(int)

n = int(input())
for _ in range(n):
    d[input()[0]] += 1

ans = 0
for com in combinations('MARCH', 3):
    ans += d[com[0]] * d[com[1]] * d[com[2]]
print(ans)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
n=int(input())
names=[input() for i in range(n)]
march=[0]*5
MARCH={j:i for i,j in enumerate('MARCH')}
for i in range(n):
    if names[i][0] in 'MARCH':
        march[MARCH[names[i][0]]]+=1
ans=0
for  i in range(5):
  for j in range(i+1,5):
    for k in range(j+1,5):
      ans+=march[i]*march[j]*march[k]      
print(ans)

Submission status: Accepted

Solution code:
#%%
from operator import mul
from functools import reduce
import itertools


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


N = int(input())

m_cnt = 0
a_cnt = 0
r_cnt = 0
c_cnt = 0
h_cnt = 0

for _ in range(N):
    s = input()
    if s[0] == 'M':
        m_cnt += 1
    elif s[0] == 'A':
        a_cnt += 1
    elif s[0] == 'R':
        r_cnt += 1
    elif s[0] == 'C':
        c_cnt += 1
    elif s[0] == 'H':
        h_cnt += 1


ans = 0
march = (m_cnt, a_cnt, r_cnt, c_cnt, h_cnt)
for cb in itertools.combinations(march, 3):
    ans += cb[0] * cb[1] * cb[2]


print(ans)

Submission status: Accepted

Solution code:
n = int(input())
m = 0
a = 0
r = 0
c = 0
h = 0
for i in range(n):
    s = input()
    if s[0] == "M":
        m += 1
    elif s[0] == "A":
        a += 1
    elif s[0] == "R":
        r += 1
    elif s[0] == "C":
        c += 1
    elif s[0] == "H":
        h += 1
print(m*a*r + 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={}
for i in range(n):
    a=input()
    if a[0]=="M" or a[0]=="A" or a[0]=="R" or a[0]=="C" or a[0]=="H":
        d[a[0]]=d.get(a[0],0)+1
a=list(d.values())
if len(a)<3:
    print(0)
    exit()
import itertools
c=list(itertools.combinations(a,3))
ans=0
for i,j,k in c:
    ans+=i*j*k
print(ans)

Submission status: Accepted

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

for i in range(N):
    S = input()
    for a in count:
        if S.startswith(a):
            count[a] += 1
# print(count)

val_list = {}
for key, val in count.items():
    if val > 0:
        val_list[key] = val

import itertools

ans = 0
for i in list(itertools.combinations(val_list.keys(), 3)):
    # print(i)
    ans += val_list[i[0]]*val_list[i[1]]*val_list[i[2]]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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


for n in range(N):
  _ = input()
  if _[0] == 'M':
    M += 1
  elif _[0] == 'A':
    A += 1
  elif _[0] == 'R':
    R += 1
  elif _[0] == 'C':
    C += 1
  elif _[0] == 'H':
    H += 1
  else:
    pass

ans = M*A*R + M*A*C + M*A*H + M*R*C + M*R*H + M*C*H
ans += A*R*C + A*R*H + A*C*H
ans += R*C*H
print(ans)

Submission status: Accepted

Solution code:
import itertools

N = int(input())

cnt_dict = {'M':0, 'A':0, 'R': 0, 'C':0, 'H':0}
first_letters = cnt_dict.keys()

for i in range(N):
    first_letter = input()[0]
    if first_letter in first_letters:
        cnt_dict[first_letter] += 1
        
sum_cnt = 0
for comb in itertools.combinations(cnt_dict, 3):
    comb_num = 1
    for c in comb:
        comb_num *= cnt_dict[c]
    sum_cnt += comb_num

print(sum_cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
N=int(input())
key='MARCH'
cnt=[0]*5
for i in range(N):
    S=input()
    for j in range(5):
        if(S[0]==key[j]):
            cnt[j]+=1
ans=0
for v in itertools.combinations(cnt,3):
    ans+=v[0]*v[1]*v[2]
print(ans)

Submission status: Accepted

Solution code:
import itertools
N=int(input())
A=[0]*5
for i in range(N):
    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
sum=0
for v in itertools.combinations(A,3):
    sum+=v[0]*v[1]*v[2]
print(sum)

Submission status: Accepted

Solution code:
comp='MARCH'
cnt=[0,0,0,0,0]

n=int(input())
for i in range(n):
  word=input()
  for j in range(len(comp)):
    if word[0]==comp[j]: cnt[j]+=1

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

Submission status: Accepted

Solution code:
from itertools import combinations

N = int(input())

candidates = {c:0 for c in "MARCH"}
combination = combinations("MARCH", 3)

for c in tuple(input()[0] for _ in range(N)):
    if c in "MARCH":
        candidates[c] += 1

print(0 if sum(candidates.values()) < 3 else sum(candidates[a] * candidates[b] * candidates[c] for a, b, c in combination))

Submission status: Accepted

Solution code:
from collections import defaultdict
def Combi2(n):
  return n*(n-1)//2
def Combi3(n):
  return n*(n-1)*(n-2)//6
def main():
  n=int(input())
  d=defaultdict(int)
  l="MARCH"
  for _ in range(n):
    s=input()[0]
    if s in l:
      d[s]+=1
  if len(d)<3:
    print(0)
    return
  s=sum(d.values())
  ans=Combi3(s)
  for i in d.values():
    if i>=2:
      ans-=Combi2(i)*(s-i)
      if i>=3:
        ans-=Combi3(i)
  print(ans)
main()

Submission status: Accepted

Solution code:
n = int(input())

ans = 0
m, a, r, c, h = 0, 0, 0, 0, 0
for _ in range(n):
  s = input()
  if s[0] == "M": m += 1
  if s[0] == "A": a += 1
  if s[0] == "R": r += 1
  if s[0] == "C": c += 1
  if s[0] == "H": h += 1

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:
from collections import Counter
from itertools import combinations

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

con = []
for c in 'MARCH':
    if c in lc:
        con.append(lc[c])

ans = 0
for a, b, c in combinations(con, 3):
    ans += a * b * c

print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
n = int(input())
names = [input() for _ in range(n)]
march = "MARCH"
cnt = {k: 0 for k in march}
for name in names:
    if any(name.startswith(s) for s in march):
        cnt[name[0]] += 1
cnt = [v for _, v in cnt.items()]
if len([v for v in cnt if v > 0]) < 3:
    print(0)
else:
    result = sum(a * b * c for a, b, c in combinations(cnt, 3))
    print(result)

Submission status: Accepted

Solution code:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

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

cnt = [0]*5
M = 'MARCH'
for s in S:
    for i in range(5):
        if s[0] == M[i]:
            cnt[i] += 1

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

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
s = [input() for _ in range(n)]
# m,a,r,c,h で始まる人の名前をcnt[]に保存して、10pattern a[i]*a[j]*a[k]を足せばOK
cnt = [0]*5
for i in range(n):
    if s[i][0] == "M": cnt[0]+=1
    if s[i][0] == "C": cnt[1]+=1
    if s[i][0] == "R": cnt[2]+=1
    if s[i][0] == "A": cnt[3]+=1
    if s[i][0] == "H": cnt[4]+=1
ans = 0
#print(cnt)
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)

Submission status: Accepted

Solution code:
n=int(input())
march=["M","A","R","C","H"]
count=[0]*5
for i in range(n):
    s=input()
    for j in range(5):
        if s[0]==march[j]:
            count[j]+=1
c0=count[0]
c1=count[1]
c2=count[2]
c3=count[3]
c4=count[4]
ans=c0*c1*c2+c0*c1*c3+c0*c1*c4+c0*c2*c3+c0*c2*c4+c0*c3*c4+c1*c2*c3+c1*c2*c4+c1*c3*c4+c2*c3*c4
print(ans)

Submission status: Accepted

Solution code:
import itertools
from collections import defaultdict
n = int(input())
d = defaultdict(lambda: 0)
for i in range(n):
    s = input()
    d[s[0]] += 1
ans = 0

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

Submission status: Accepted

Solution code:
import itertools

N=int(input())
L=[0,0,0,0,0]
T="MARCH"

for i in range(N):
    S=input()
    for i in range(5):
        if S[0]==T[i]:
            L[i]+=1
            
ans=0
for itr in itertools.combinations(range(5), 3):
    ans+=L[itr[0]]*L[itr[1]]*L[itr[2]]
    
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
N = int(input())
# スペース区切りの整数の入力
# b, c = map(int, input().split())
# 文字列の入力
#s = input()
sList=[input() for i in range(N)]

m = 0;
a = 0;
r = 0;
c = 0;
h = 0;
for i in range(len(sList)):
  s = sList[i];
  if s[0] == 'M':
    m = m + 1;
  elif s[0] == 'A':
    a = a + 1;
  elif s[0] == 'R':
    r = r + 1;
  elif s[0] == 'C':
    c = c + 1;
  elif s[0] == 'H':
    h = h + 1;
  
# 出力
# MARCHの10通りの組み合わせを足す
result = m * a * r + m * a * c + m * a * h + m * r * c + m * r * h + m * c * h + a * r * c + a * r * h + r * c * h + a * c * h;
print(result);

Submission status: Accepted

Solution code:
import itertools
import math
import sys
from collections import Counter
from fractions import gcd
from functools import reduce

n = int(input())
cnt = 0
ans = [0] * 5
for i in range(n):
    s = input()
    letters = ["M", "A", "R", "C", "H"]
    if s[0] in letters:
        ans[letters.index(s[0])] += 1
# print(ans)
cnt = 0
for i in ans:
    if i >= 1:
        cnt += 1
if cnt < 3:
    print(0)
else:
    ans2 = 1
    without0 = []
    for i in ans:
        if i > 0:
            without0.append(i)
            ans2 *= i
    # print(ans2)
    if cnt == 3:
        print(ans2)
    elif cnt == 4:
        ans3 = 0
        for i in without0:
            ans3 += ans2 // i
        print(ans3)
    else:
        ans4 = 0
        for i in range(len(without0) - 1):
            for j in range(i + 1, len(without0)):
                division = without0[i] * without0[j]
                ans4 += ans2 // division
        print(ans4)

Submission status: Accepted

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

Submission status: Accepted

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

# それぞれの頭文字から名前が始まる人をカウント
for i in range(n):
    s = input()
    if s[0] == "M":
        m += 1
    if s[0] == "A":
        a += 1
    if s[0] == "R":
        r += 1
    if s[0] == "C":
        c += 1
    if s[0] == "H":
        h += 1

D = []
D.append(m)
D.append(a)
D.append(r)
D.append(c)
D.append(h)
# 3人の名前の頭文字を選ぶ組み合わせ
P = [0, 0, 0, 0, 0, 0, 1, 1, 1, 2]
Q = [1, 1, 1, 2, 2, 3, 2, 2, 3, 3]
R = [2, 3, 4, 3, 4, 4, 3, 4, 4, 4]

ans = 0
for i in range(10):
    ans += D[P[i]] * D[Q[i]] * D[R[i]]
print(ans)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N=int(input())
    Ms=set()
    As=set()
    Rs=set()
    Cs=set()
    Hs=set()
    for i in range(N):
        name=input()
        if name[0]=="A":
            As.add(name)
        elif name[0]=="M":
            Ms.add(name)
        elif name[0]=="R":
            Rs.add(name)
        elif name[0]=="C":
            Cs.add(name)
        elif name[0]=="H":
            Hs.add(name)
    NAMES=[Ms.__len__(),As.__len__(),Rs.__len__(),Cs.__len__(),Hs.__len__()]
    zeros=NAMES.count(0)
    if zeros>=3:
        print(0)
    else:
        from itertools import combinations
        ans=0
        for comb in combinations(NAMES,3):
            if 0 in comb:
                continue
            else:
                temp=1
                for c in comb:
                    temp*=c
                ans+=temp
        print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
march = "MARCH"
n = int(input())
initial = Counter([input()[0] for _ in range(n)])
ans = []
for i, num in initial.items():
    if i in march:
        ans.append(num)

x = len(ans)
if x < 3:
    print(0)
elif x >= 3:
    y = 0
    for i in range(0, x-2):
        for j in range(i+1, x-1):
            for k in range(j+1, x):
                y += ans[i] * ans[j] * ans[k]
    print(y)

Submission status: Accepted

Solution code:
# coding:utf-8

import sys
import math
import time
import numpy as np
import collections
from collections import deque
import queue
import copy

# 最大公約数
def gcd(m,n):
  x = max(m,n)
  y = min(m,n)
  if x%y == 0:
    return y
  else:
    while x%y != 0:
      z = x%y
      x = y
      y = z
    else:
      return z

# 幅優先探索(BFS)でスタート座標(x, y)からの最大距離返す
def bfs(SS, x, y, H, W):#入力(座標系(迷路), x, y, xの端, yの端)
  x_next = [0, 0, -1, 1]
  y_next = [1, -1, 0, 0]
  tempx = x
  tempy = y
  mlength = 0
  q = deque()
  xytuple = (x, y, 0)
  q.append(xytuple)


  while q:
    xytuple = q.popleft()
    SS[xytuple[0]][xytuple[1]] = "x" #探索した場所は探索できないようにする
    for i in range(4): #このforで上下左右を調べてる
      tempx = xytuple[0] + x_next[i]
      tempy = xytuple[1] + y_next[i]
      #print(tempx, tempy, xytuple[2])
      #print(S)
      if(0 <= tempx and tempx < H and 0 <= tempy and tempy < W and SS[tempx][tempy] == "."):
        temptuple = (tempx, tempy, xytuple[2]+1)
        SS[temptuple[0]][temptuple[1]] = "x" #探索した場所は探索できないようにする
        mlength = max(mlength, xytuple[2] +1)
        q.append(temptuple)
      #print(q)
  return mlength

def brick(a,n,m,N):#ABC 148
  #n番目以降にmがあるか調べる
  if not m in a[n:]:
    print(N-(m-1))
  else:
    #b = copy.deepcopy(a)
    brick(a,a[n:].index(m),m+1,N)

#X = str(input()).split()
#a = [int(x) for x in input().split()]

N = int(input())
S = []
Mc = 0
Ac = 0
Rc = 0
Cc = 0
Hc = 0
ans = 0

for i in range(N):
    S.append(str(input())[0])
    if(S[i]=="M"):
        Mc +=1
    elif(S[i]=="R"):
        Rc += 1
    elif(S[i]=="A"):
        Ac += 1
    elif(S[i]=="C"):
        Cc += 1
    elif(S[i]=="H"):
        Hc += 1

ans += Mc*Ac*Rc
ans += Mc*Ac*Cc
ans += Mc*Ac*Hc
ans += Mc*Rc*Cc
ans += Mc*Rc*Hc
ans += Mc*Cc*Hc
ans += Ac*Rc*Cc
ans += Ac*Hc*Cc
ans += Ac*Rc*Hc
ans += Cc*Rc*Hc

print(ans)

Submission status: Accepted

Solution code:
import itertools
N = int(input())
S_num = [0] * 5
answer = 0
for _ in range(N):
    S = input()
    if S[0] == 'M':
        S_num[0] += 1
    elif S[0] == 'A':
        S_num[1] += 1
    elif S[0] == 'R':
        S_num[2] += 1
    elif S[0] == 'C':
        S_num[3] += 1
    elif S[0] == 'H':
        S_num[4] += 1

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    initials = ["M", "A", "R", "C", "H"]
    person_name = {}
    for initial in initials:
        person_name[initial] = 0
    for _ in range(n):
        name = input()
        if name[0] in person_name:
            person_name[name[0]] += 1
    answer = 0
    for i in range(5):
        for j in range(i + 1, 5):
            for k in range(j + 1, 5):
                answer += person_name[initials[i]] * person_name[initials[j]] * person_name[initials[k]]
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
lis = [0] * 5
name = ['M','A','R','C','H']

for i in range(n):
    s = list(input())
    for j in range(5):
        if s[0] == name[j]:
            lis[j] += 1

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

Submission status: Accepted

Solution code:
from collections import Counter
from itertools import combinations
 
n = int(input())
l = [input()[0] for _ in range(n)]
lc = Counter(l)
 
con = []
for c in 'MARCH':
  if c in lc:
    con.append(lc[c])
 
ans = 0
for a, b, c in combinations(con, 3):
  ans += a * b * c
 
print(ans)

Submission status: Accepted

Solution code:
import itertools
n = int(input())
m,a,r,c,h = [0]*5
for i in range(n):
    s = input()
    if s[0] == "M":m += 1
    if s[0] == "A": a += 1
    if s[0] == "R": r += 1
    if s[0] == "C": c += 1
    if s[0] == "H": h += 1
x = [m,a,r,c,h]
y = ["M","A","R","C","H"]
ans = 0
for i in itertools.combinations(x,3):
    ans += i[0]*i[1]*i[2]
print(ans)

Submission status: Accepted

Solution code:
import math
n = int(input())
a = ["M","A","R","C","H"]
dic = {}
def combination(n,r):
	return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))
for i in range(n):
	x = input()
	if x[0] in a:
		if x[0] in dic:
			dic[x[0]] += 1
		else:
			dic[x[0]] = 1
b = []
for i in dic.values():
	b.append(i)

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

Submission status: Accepted

Solution code:
n=int(input())
slist=[input() for i in range(n)]
m,a,r,c,h = 0,0,0,0,0
for s in slist:
  if s[0]=="M":
    m += 1
  if s[0]=="A":
    a+=1
  if s[0]=="R":
    r+=1
  if s[0]=="C":
    c+=1
  if s[0]=="H":
    h+=1
li=[m,a,r,c,h]
li=[i for i in li if i>0]
import itertools
if len(li)<3:
  print(0)
  exit()

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

Submission status: Accepted

Solution code:
n=int(input())
info=[["M",0],["A",0],["R",0],["C",0],["H",0]]
kind=0
for i in range(n):
    s=input()
    for i in range(5):
        if s[0]==info[i][0]:
            if info[i][1]==0:
                kind+=1
            info[i][1]+=1
            break
if kind<=2:
    print(0)
else:
    kind_num=[] #1人以上いるグループの人数を記録
    for i in range(5):
        if info[i][1]!=0:
            kind_num.append(info[i][1])
    all_=[]
    for i in range(kind):
        for j in range(kind):
            if j<=i:
                continue
            for k in range(kind):
                if k<=j:
                    continue
                all_.append([i,j,k])
    ans=0
    for i in range(len(all_)):
        ans+=kind_num[all_[i][0]]*kind_num[all_[i][1]]*kind_num[all_[i][2]]
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import combinations

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

ret = 0
for a, b, c in combinations(lst, 3):
    ret += a * b * c

print(ret)

Submission status: Accepted

Solution code:
import itertools
N = int(input())
S = []
count = [0, 0, 0, 0, 0]
l = list('MARCH')
for _ in range(N):
    name = input()
    # print('name', name[0])
    if name[0] in list('MARCH'):
        S.append(name)
        count[l.index(name[0])] += 1
# print('S', S)
# print('count', count)

count = list(itertools.filterfalse(lambda x: x == 0, count))
# print('count', count)

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

Submission status: Accepted

Solution code:
from itertools import combinations 
n = int(input())
march_num = {"M":0,"A":0,"R":0,"C":0,"H":0}

for _ in range(n):
    s = input()
    if s[0] in set(march_num):
        march_num[s[0]] += 1;
        
ans = 0
for x,y,z in combinations(set(march_num),3):
    ans += march_num[x] * march_num[y] * march_num[z]
        
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
li = ['0'] * N
for i in range(N) :
    li[i] = input()
import collections
from collections import deque
M = deque()
A = deque()
R = deque()
C = deque()
H = deque()
for i in range(N) :
    if li[i][0] == 'M' :
        M.append(li[i])
    if li[i][0] == 'A' :
        A.append(li[i])
    if li[i][0] == 'R' :
        R.append(li[i])
    if li[i][0] == 'C' :
        C.append(li[i])
    if li[i][0] == 'H' :
        H.append(li[i])
m = len(M)
a = len(A)
r = len(R)
c = len(C)
h = len(H)
s = m * a * (r + c + h) + m * r * (c + h) + m * c * h + a * r * (c + h) + r * c * h + a * c * h
print(s)