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:
# -*- coding: utf-8 -*-
import itertools
"""
def len(a):
    return len(set(a))
"""

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

ans = 0
name_count = [0 for _ in range(5)]
M = []
A = []
R = []
C = []
H = []
for i in range(n):
    if s[i][0] == 'M':
        name_count[0] += 1
        M.append(s[i])
    if s[i][0] == 'A':
        name_count[1] += 1
        A.append(s[i])
    if s[i][0] == 'R':
        name_count[2] += 1
        R.append(s[i])
    if s[i][0] == 'C':
        name_count[3] += 1
        C.append(s[i])
    if s[i][0] == 'H':
        name_count[4] += 1
        H.append(s[i])
#print(M, A, R, C, H)
len_M = len(set(M))
len_A = len(set(A))
len_R = len(set(R))
len_C = len(set(C))
len_H = len(set(H))
#print(len_M, len_A, len_R, len_C, len_H)
#ans = len_M * (len_A * len_R + len_A * len_C + len_A * len_H + len_R * len_C + len_R * len_H + len_C * len_H) + len_A * (len_R * len_C + len_R * len_H + len_C * len_H) + len_R * len_C + len_H
tmp = [i for i in range(5)]
tmp2 = [len_M, len_A, len_R, len_C, len_H]
combination = list(itertools.combinations(tmp, 3))
ans = 0
for i in range(len(combination)):
    ans += tmp2[combination[i][0]] * tmp2[combination[i][1]] * tmp2[combination[i][2]] 
print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    ans = []
    for i in range(N):
        s = input()
        if s[0] in ["M", "A", "R", "C", "H"]:
            ans.append(s[0])
    from collections import Counter
    c = Counter(ans)
    ret = 1
    sumS = sum(int(c[s] > 0) for s in ["M", "A", "R", "C", "H"])
    accS = sum(c[s] for s in ["M", "A", "R", "C", "H"])
    if sumS >= 3:
        ret = accS*(accS-1)*(accS-2)//2//3
        for s in ["M", "A", "R", "C", "H"]:
            if c[s] == 2:
                ret -= (accS - c[s])
            elif c[s] >= 3:
                ret -= (c[s]*(c[s]-1)*(c[s]-2)//2//3) + \
                    ((c[s]-1)*(c[s])//2)*(accS - c[s])
    else:
        ret = 0
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict
from itertools import combinations
N = int(input())
cnt = defaultdict(int)

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

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

ans = 0
comb = list(combinations(["M","A","R","C","H"], 3))
for i in range(10):
    tmp = 1
    for c in comb[i]:
        tmp *= cnt[c]
    ans += tmp

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
import itertools
#ID
b = defaultdict(lambda: len(b))
n = int(input())
hed = ["M","A","R","C","H"]
for i in hed:
    b[i] 
li = [0]*5
for _ in range(n):
    a = input()
    if a[0] in hed:
        li[b[a[0]]] += 1
c = [j for j in li if j != 0]
ans = 0
for k in itertools.combinations(c,3):
    ans += k[0]*k[1]*k[2]
print(ans)

Submission status: Accepted

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

l = ['M', 'A', 'R', 'C', 'H']
d = dict()
for li in l: d[li] = 0
for si in S:
    for li in l:
        if si[0] == li: d[li] += 1

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

Submission status: Accepted

Solution code:
from collections import defaultdict
from itertools import combinations
n=int(input())
s=[input() for i in range(n)]
cnt=defaultdict(lambda :0)
cnt['M']=0
for i in range(n):
    if s[i][0] in 'MARCH':
        cnt[s[i][0]]+=1

if len(cnt)<=2:print(0)
else:
    num=len(cnt)
    ans=0
    for x,y,z in combinations(list(cnt.values()), 3):
        ans+=x*y*z
    print(ans)

Submission status: Accepted

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

v = list(d.values())
import itertools
ans = 0
for c in itertools.combinations(range(5),3):
    ans += v[c[0]]*v[c[1]]*v[c[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
    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
ar = list(itertools.combinations([0,1,2,3,4], 3))
ans = 0
for i in range(len(ar)):
    ans += a[ar[i][0]] * a[ar[i][1]] * a[ar[i][2]]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = [input() for i in range(N)]
from collections import Counter
ctr = Counter([s[0] for s in S])

ans = 0
import itertools
for ptn in itertools.combinations('MARCH', 3):
    t = 1
    for c in ptn:
        t *= ctr[c]
    ans += t
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n = INT()
num = [0 for _ in range(5)]
arr = ['M', 'A', 'R', 'C', 'H']
for _ in range(n):
    s = STR()
    if s[0] in arr:
        num[arr.index(s[0])] += 1
ans = 0
arr2 = list(combinations(range(5), 3))
for i in range(len(arr2)):
    tmp = 1
    for j in arr2[i]:
        tmp *= num[j]
    ans += tmp
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
l = [input() for i in range(N)]

name_dir = {"M":0,"A":0,"R":0,"C":0,"H":0}
for name in l:
    for alphabet in name_dir.keys():
        if name[0] == alphabet:
            name_dir[alphabet] += 1

name_counter = list(name_dir.values())
non0_name_counter = [s for s in name_counter if s != 0]

ans = 0
if name_counter.count(0) > 2:
    pass
elif name_counter.count(0) == 2:
    ans = non0_name_counter[0] * non0_name_counter[1] *non0_name_counter[2]
elif name_counter.count(0) == 1:
    for i in range(0,4):
        tmp = [s for s in list(range(0,4)) if s != i]
        ans += non0_name_counter[tmp[0]] * non0_name_counter[tmp[1]] * non0_name_counter[tmp[2]]
elif name_counter.count(0) == 0:
    for i in range(0,4):
        for j in range(i+1,5):
            tmp = [s for s in list(range(0,5)) if s != i and s != j]
            ans += non0_name_counter[tmp[0]] * non0_name_counter[tmp[1]] * non0_name_counter[tmp[2]]
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations

begin_with = list('MARCH')
num_of_begin_with = [0] * 5

n = int(input())
for _ in range(n):
    s = input()
    if s[0] in begin_with:
        num_of_begin_with[begin_with.index(s[0])] += 1

num_of_begin_with = [i for i in num_of_begin_with if i != 0]
cnt = 0
for a, b, c in combinations(num_of_begin_with, 3):
    cnt += a * b * c

print(cnt)

Submission status: Accepted

Solution code:
n=int(input())
s=['M','A','R','C','H']
for i in range(n):
    i=input()
    s.append(i[0])

import collections
c = collections.Counter(s)
d=['M','A','R','C','H']
ans=0
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            ans+=(c[d[i]]-1)*(c[d[j]]-1)*(c[d[k]]-1)
print(ans)

Submission status: Accepted

Solution code:
import sys
import numpy as np

# N 人数
n = int(input())

# 名前
num = np.zeros(5)
for ii in range(n):
    nm = input()
    if nm[0] == "M":
        num[0] += 1
    if nm[0] == "A":
        num[1] += 1
    if nm[0] == "R":
        num[2] += 1
    if nm[0] == "C":
        num[3] += 1
    if nm[0] == "H":
        num[4] += 1
comb = 0
for i in range(5):
    for j in range(i+1, 5):
        for k in range(j+1, 5):
            cb = num[i] * num[j] * num[k]
            comb += cb
print(int(comb))

Submission status: Accepted

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


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import itertools


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

for i in range(N):
    S = list(input())
    ARR.append(S)


def calculate(n,arr):
    brr = {
        "M":0,
        "A":0,
        "R":0,
        "C":0,
        "H":0,
    }

    for ar in arr:
        if ar[0] == "M":
            brr.__setitem__("M",brr.get("M") + 1)

        if ar[0] == "A":
            brr.__setitem__("A",brr.get("A") + 1)

        if ar[0] == "R":
            brr.__setitem__("R",brr.get("R") + 1)

        if ar[0] == "C":
            brr.__setitem__("C",brr.get("C") + 1)

        if ar[0] == "H":
            brr.__setitem__("H",brr.get("H") + 1)

    m = brr.values()

    ssk = []
    for k in m:
        ssk.append(k)


    result = []
    for ss in itertools.combinations(ssk,3):
        result.append(ss[0] * ss[1] * ss[2])


    print(sum(result))



calculate(N,ARR)

Submission status: Accepted

Solution code:
N = int(input())
A = [input() for _ in range(N)]
B = list()
num_M=0
num_A=0
num_R=0
num_C=0
num_H=0
for i in A:
  if i[0]=='M':
    num_M+=1
    continue
  if i[0]=='A':
    num_A+=1
    continue
  if i[0]=='R':
    num_R+=1
    continue
  if i[0]=='C':
    num_C+=1
    continue
  if i[0]=='H':
    num_H+=1
    continue
print(num_M*num_A*num_R+num_M*num_A*num_C+num_M*num_A*num_H+num_M*num_R*num_C+num_M*num_R*num_H+num_M*num_C*num_H+num_A*num_R*num_C+num_A*num_C*num_H+num_A*num_R*num_H+num_R*num_C*num_H)

Submission status: Accepted

Solution code:
from collections import Counter
from itertools import combinations

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

C = Counter(s)
ans = 0
for x, y, z in combinations("MARCH", 3):
    ans += C[x] * C[y] * C[z]

print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations

def March(n , sl):

    ans = 0
    count = {m: 0 for m in list("MARCH")}

    for i in sl:
        if i[0] in count:
            count[i[0]] += 1

    c = combinations(list("MARCH"), 3)
    for q, w, i in c:
        ans += count[q] * count[w] * count[i]

    return ans

def main():
    n = int(input())
    sl = [str(input()) for i in range(n)]
    print(March(n , sl))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

N = int(input().strip())
S_list = [input().strip() for _ in range(N)]
#-----

class Combination():
    def __init__(self):
        self._selected=[]
        self._all_pattern=[]
        
    def getPattern(self, arr :list, r :int) -> list:
        self._make(arr,r)
        return self._all_pattern
        
    def _make(self, arr :list, r :int):
        if r == 0:
            self._all_pattern.append(self._selected[:])
            return 
        
        for i in range(len(arr)):
            self._selected.append( arr[i] )
            r -= 1
            
            next_arr = arr[(i+1):]
            
            ans = self._make(next_arr,r)
            if ans == None:
                del self._selected[-1]
                r += 1
#-----

cnt_word = { w:0 for w in "MARCH"}

for words in S_list:
    key = words[0]
    if key in cnt_word:
        cnt_word[ words[0] ] += 1

comb = Combination()
pattern = comb.getPattern( list("MARCH"),3)

sum=0
for p1,p2,p3 in pattern:
    sum += cnt_word[p1] * cnt_word[p2] * cnt_word[p3]

print(sum)

Submission status: Accepted

Solution code:
import itertools
N=int(input())
nameM=0
nameA=0
nameR=0
nameC=0
nameH=0
for a in range(N):
    S=input()
    ss=[]
    for b in S:
        ss.append(b)
        if ss[0]=='M':
            nameM+=1
            break
        elif ss[0]=='A':
            nameA+=1
            break
        elif ss[0]=='R':
            nameR+=1
            break
        elif ss[0]=='C':
            nameC+=1
            break
        elif ss[0]=='H':
            nameH+=1
            break
        else:
            break
list=[nameM,nameA,nameR,nameC,nameH]
answers=[a for a in list if a!=0]
b=1
if len(answers)<=2:
    print(0)
elif len(answers)==3:
    for a in answers:
        b*=a
    print(b)
elif len(answers)>=4:
    answer=0
    for x in itertools.combinations(answers,3):
        c=1
        for y in x:
            c*=y
        answer+=c
    print(answer)

Submission status: Accepted

Solution code:
import itertools

n = int(input())
a = [0] * 5
ans = 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

a_c = list(itertools.combinations([0,1,2,3,4], 3))
for i in range(len(a_c)):
    ans += a[a_c[i][0]]*a[a_c[i][1]]*a[a_c[i][2]]
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations

N = int(input())

march = list("MARCH")
S = {m: 0 for m in march}
for _ in range(N):
    s = input()
    if s[0] in S:
        S[s[0]] += 1

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
q = []
z = ['M','A','R','C','H']
import sys
from collections import Counter
import itertools

for _ in range(n):
    s = input()
    a = s[0]
    
    if a =='M' or a =='A' or a =='R' or a =='C' or a =='H':
        q.append(a)
        
b = Counter(q)
c = list(b.keys())
m = 0

if len(b) < 3:
    print(0)
    sys.exit()
else:
    p = list(itertools.combinations(c,3))

ans = 0
for f,g,h in p:
    ans += (b[f]*b[g]*b[h])
        
print(ans)

Submission status: Accepted

Solution code:
#089_C
from collections import Counter
from itertools import combinations
n = int(input())
s = [input()[0] for _ in range(n)]
cnt = Counter(s)
ans = 0
for a, b, c in combinations('MARCH', 3):
    ans += cnt[a] * cnt[b] * cnt[c]
print(ans)

Submission status: Accepted

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

for i in S:
    if i in ['M','A','R','C','H']:
        d[i] += 1

e = list(d.values())

f = list(itertools.combinations(e,3))

s = 0
for i,j,k in f:
    s += i*j*k
print(s)

Submission status: Accepted

Solution code:
n=int(input())
s=[input() for _ in [0]*n]
march=[0]*5
for x in s:
  if x[0] in 'MARCH':
    march['MARCH'.index(x[0])]+=1
ans=0
for i in range(5):
  for j in range(i+1,5):
    for k in range(j+1,5):
      ans+=march[i]*march[j]*march[k]
print(ans)

Submission status: Accepted

Solution code:
n=int(input())

l=[]
for i in range(n):
    l+=[input()[0]]

march=[0]*5
for j in range(n):
    if l[j]=='M':
        march[0]+=1
    elif l[j]=='A':
        march[1]+=1
    elif l[j]=='R':
        march[2]+=1
    elif l[j]=='C':
        march[3]+=1
    elif l[j]=='H':
        march[4]+=1

from itertools import combinations
ans=0
for x,y,z in combinations(march, 3):
    ans+=x*y*z

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#pypyは内包表記使わない
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    N = int(input())
    M = 0
    A = 0
    R = 0
    C = 0
    H = 0
    for _ in range(N):
        s = input().rstrip()
        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
    res = 0
    l = [M, A, R, C, H]
    for a, b, c in combinations(l, 3):
        res += a*b*c
    print(res)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
name = {"M":0,"A":0,"R":0,"C":0,"H":0}
for i in range(N):
    tmp = input()
    f = tmp[0]
    if f in name:
        name[f] += 1

num = list(name.values())
ans = 0
for i in range(3):
    for j in range(i+1,4):
        for h in range(j+1,5):
            ans += num[i]*num[j]*num[h]

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=[input() for _ in range(n)]
from collections import Counter
cnt=0
d=Counter()
import itertools
ans=0
for i  in s:
    d[i[0]]+=1
for i , j,k in itertools.combinations("MARCH",3):
    ans+=d[i]*d[j]*d[k]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = ["M", "A", "R", "C", "H"]
b = [0] * 5
for _ in range(n):
    s = list(input())
    for i in a:
        if i == s[0]:
            b[a.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 += b[i] * b[j] * b[k]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
headList = [0] * 5

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

print(result)

Submission status: Accepted

Solution code:
import itertools 
N = int(input())
march = list(itertools.combinations("MARCH", 3))
dict = {i:0 for i in "MARCH"}
for _ in range(N):
    S = input()
    if(S[0] in "MARCH"):
        dict[S[0]] += 1
ans = 0
for i in range(10):
    ans +=  dict[march[i][0]]*dict[march[i][1]]*dict[march[i][2]]

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = []
for _ in range(n):
    s.append(input()[0])
import collections
c = collections.Counter(s)
lis = [c["M"],c["A"],c["R"],c["C"],c["H"]]
from itertools import *
ans=0
for tmp in combinations(lis,3):
    ans+=tmp[0]*tmp[1]*tmp[2]
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
n, *S = open(0).read().split()
# 頭文字だけ抜き出す.
cap = [s[0] for s in S]
# M,A,R,C,H,それぞれ頭文字の中にある数をカウント.
cnt = [cap.count(i) for i in "MARCH"]
# 組み合わせの合計を取る.
ans = sum(x*y*z for x, y, z in combinations(cnt, 3))
print(ans)

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    n = int(input())
    s = list()
    d = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
    for i in range(n):
        s.append(input())

    for ss in s:
        if ss[0] in d.keys():
            d[ss[0]] += 1

    ans = 0
    for i in d:
        for j in d:
            for k in d:
                if i != j and i != k and j != k:
                    ans += d[i] * d[j] * d[k]

    print(ans//6)

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:
import itertools

N = int(input())
words_count = {
  'M': 0,
  'A': 0,
  'R': 0,
  'C': 0,
  'H': 0
}
  
for _ in range(N):
  name = input()
  if name[0] in words_count.keys():
    words_count[name[0]] += 1

ans = 0
patterns = itertools.combinations(words_count.keys(), 3)
for a, b, c in patterns:
  ans += words_count[a] * words_count[b] * words_count[c]

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
from itertools import combinations
N = int(input())
Slist = [input() for _ in range(N)]
Sc = Counter([S[0] for S in Slist])
ans = 0
for x, y, z in combinations(list("MARCH"), 3):
    ans += Sc[x] * Sc[y] * Sc[z]
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
from collections import Counter

n = int(input())
c = Counter()

for _ in range(n):
  c[input()[0]]+= 1
  
ans = sum([c[pattern_i[0]]*c[pattern_i[1]]*c[pattern_i[2]] for pattern_i in combinations(['M','A','R','C','H'], 3)])
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
L=[0,0,0,0,0]
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
ans=0
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(ans)

Submission status: Accepted

Solution code:
from operator import mul
from functools import reduce

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

n = int(input())
ss = [input() for _ in range(n)]
march = ['M','A','R','C','H']
d = dict(zip(march, [0]*5))

nn = 0

for s in ss:
    if s[0] in march:
        d[s[0]] += 1
        nn += 1
if nn < 3:
    print(0)
    exit()

ans = cmb(nn, 3)
for i in d.values():
    if i >= 2:
        if i > 3:
            ans -= cmb(i, 3)
        ans -= cmb(i,2)*(nn-i)

print(int(ans))

Submission status: Accepted

Solution code:
import itertools
s = set()
N = int(input())
dict = {i:0 for i in "MARCH"}

sum_v = 0
ans = 0
for i in range(N):
    S = input()
    if(S[0] in "MARCH"):
        dict[S[0]] += 1
        s.add(S[0])
        sum_v += 1
        
c = itertools.combinations(s, 3)

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

Submission status: Accepted

Solution code:
# import bisect
from collections import Counter, defaultdict, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    n = int(input())
    initial_num = defaultdict(int)

    for i in range(n):
        s = sys.stdin.readline().rstrip("\n")
        initial = s[0]
        initial_num[initial] += 1

    ans = 0
    march = "MARCH"
    for i in range(3):
        num1 = initial_num[march[i]]
        for j in range(i+1, 4):
            num2 = initial_num[march[j]]
            for k in range(j+1, 5):
                num3 = initial_num[march[k]]
                ans += num1 * num2 * num3

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

from collections import Counter
cos = Counter(S)

num = [cos[i] for i in "MARCH"]

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

print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations

n = int(input())
s = [input() for _ in range(n)]
s.sort()
march = [0, 0, 0, 0, 0]
st = ['M', 'A', 'R', 'C', 'H']
for i in range(n):
    for j in range(5):
        if s[i][0] == st[j]:
            march[j] += 1
#print(march)
if sum(march) == 0:
    print(0)
    exit()

ans = 0

a = list(combinations(range(5), 3))
for i in range(len(a)):
    tmp = 1
    for j in a[i]:
        tmp *= march[j]
    ans += tmp

print(ans)

Submission status: Accepted

Solution code:
import itertools
m = 0
a = 0
r = 0
c = 0
h = 0

n=int(input())

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 = 0
memo = [m,a,r,c,h]

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

Submission status: Accepted

Solution code:
from itertools import combinations
n=int(input())
num=[0 for _ in range(5)]
sum=0
for i in range(n):
    s=input()
    if s[0]=="M":
        num[0]+=1
    elif s[0]=="A":
        num[1]+=1
    elif s[0]=="R":
        num[2]+=1
    elif s[0]=="C":
        num[3]+=1
    elif s[0]=="H":
        num[4]+=1
num=[i for i in num if i>=1]
if len(num)<=2:
    print(sum)
else:
    c=list(combinations(num,3))
    for i in range(len(c)):
        sum+=c[i][0]*c[i][1]*c[i][2]
    print(sum)

Submission status: Accepted

Solution code:
import collections
import itertools
n = int(input())
M = "MARCH"
S = []
for i in range(n):
  S.append(input()[0])
T = []
for i in S:
  if i in M:
    T.append(i)
U = collections.Counter(T)
TT = set(T)
P = list(itertools.combinations(TT, 3))
ans = 0
for i in P:
  ans += U[i[0]] * U[i[1]] * U[i[2]]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
march = ['M','A','R','C','H']
counter = [0]*5
for i in range(n):
	s = input()
	if s[0] in march:
		counter[march.index(s[0])] += 1

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
m = ["M", "A", "R", "C", "H"]
s = {}
for _ in range(n):
    s_ = input()[0]
    if s_ not in m: continue
    else:
        if s_ not in s.keys():
            s[s_] = 0
        s[s_] += 1
if len(list(s.keys())) <= 2:
    print(0)
    exit()
l = list(s.values())
n = len(l)
a = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            a += l[i] * l[j] * l[k]
print(a)

Submission status: Accepted

Solution code:
import itertools

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

MARCH=[0]*5
for name in s:
    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
c=list(itertools.product([0,1], repeat=5))

for i in c:
    a=1
    if sum(i)==3:
        for g in range(5):
            if i[g]==1:
                a*=MARCH[g]
        ans+=a
print(ans)

Submission status: Accepted

Solution code:
from functools import reduce
import itertools
n = int(input())
s = [input() for i in range(n)]
head = ['M','A','R','C','H']
number = [0]*26
new_s = [i for i in s if i[0] in head]
ans = [0,0,0,1,4,10]
for i in new_s:
    number[ord(i[0])-65] += 1
ans2 = [i for i in number if i!=0]
if len(ans2) <= 2:
    print(0)
else:
    mul = 0
    ans2 = list(itertools.combinations(ans2,3))
    for i in ans2:
        mul += reduce(lambda x,y:x*y,i)
    print(mul)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
s = [input() for _ in range(n)]
name_count = [0 for _ in range(5)]
for i in s:
    if i[0] == "M":
        name_count[0] += 1
    elif i[0] == "A":
        name_count[1] += 1
    elif i[0] == "R":
        name_count[2] += 1
    elif i[0] == "C":
        name_count[3] += 1
    elif i[0] == "H":
        name_count[4] += 1

result = 0
for s in range(3):
    for t in range(s+1, 4):
        for u in range(t+1, 5):
            result += name_count[s]*name_count[t]*name_count[u]
print(result)

Submission status: Accepted

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

S_first = [S[i][0] for i in range(N)]
march = ['M','A','R','C','H']
march_number = [0]*5

for i in range(5):
    march_number[i] = S_first.count(march[i])

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