Problem:


Score : 300 points

Problem Statement

There are N people. The name of the i-th person is S_i.

We would like to choose three people so that the following conditions are met:

The name of every chosen person begins with M, A, R, C or H.

There are no multiple people whose names begin with the same letter.

How many such ways are there to choose three people, disregarding order?

Note that the answer may not fit into a 32-bit integer type.

Constraints

1 \leq N \leq 10^5

S_i consists of uppercase English letters.

1 \leq |S_i| \leq 10

S_i \neq S_j (i \neq j)

Input

Input is given from Standard Input in the following format:

N
S_1
:
S_N

Output

If there are x ways to choose three people so that the given conditions are met, print x.

Sample Input 1

5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI

Sample Output 1

2

We can choose three people with the following names:

MASHIKE, RUMOI, HABORO

MASHIKE, RUMOI, HOROKANAI

Thus, we have two ways.

Sample Input 2

4
ZZ
ZZZ
Z
ZZZZZZZZZZ

Sample Output 2

0

Note that there may be no ways to choose three people so that the given conditions are met.

Sample Input 3

5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO

Sample Output 3

7



Sample input:
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI


Sample output:
2

Submission status: Accepted

Solution code:
N = int(input())
m = [0] * 5
s = "MARCH"
for i in range(N):
    a = input()
    for j in range(5):
        if s[j] == a[0]:
            m[j] += 1

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = [input()[0] for _ in range(n)]
c = [s.count("M"), s.count("A"), s.count("R"), s.count("C"), s.count("H")]
ans =  c[0] * c[1] *c [2]
ans += c[0] * c[1] *c [3]
ans += c[0] * c[1] *c [4]
ans += c[0] * c[2] *c [3]
ans += c[0] * c[2] *c [4]
ans += c[0] * c[3] *c [4]
ans += c[1] * c[2] *c [3]
ans += c[1] * c[2] *c [4]
ans += c[1] * c[3] *c [4]
ans += c[2] * c[3] *c [4]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
lst = [0, 0, 0, 0, 0]
for i in range(n):
  s = input()
  if s[0] == "M":
    lst[0] += 1
  if s[0] == "A":
    lst[1] += 1
  if s[0] == "R":
    lst[2] += 1
  if s[0] == "C":
    lst[3] += 1
  if s[0] == "H":
    lst[4] += 1

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

Submission status: Accepted

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

def MI():
    return map(int,input().split())

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

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())

n = I()
s = CS(n)

for i in s:
    if i[0]=='M':
        ddict['M'] += 1
    elif i[0]=='A':
        ddict['A'] += 1
    elif i[0]=='R':
        ddict['R'] += 1
    elif i[0]=='C':
        ddict['C'] += 1
    elif i[0]=='H':
        ddict['H'] += 1
    else:
        pass

l = list(combinations(['M','A','R','C','H'],3))
# print(l)

x = 0
for t in l:
    x += ddict[t[0]]*ddict[t[1]]*ddict[t[2]]
print(x)

Submission status: Accepted

Solution code:
from itertools import combinations
from collections import Counter

N = int(input())
S = Counter()

for i in range(N):
    S[input()[0]] += 1

tmp = []
for a,b,c in combinations('MARCH',3):
    tmp.append(int((S[a] * S[b] * S[c])))

print(sum(tmp))

Submission status: Accepted

Solution code:
import itertools
from collections import defaultdict

def main():
    name_freq = defaultdict(int)
    N = int(input())
    for _ in range(N):
        name_freq[input()[0]] += 1

    ans = 0
    for comb in itertools.combinations(['M', 'A', 'R', 'C', 'H'], 3):
        ans += name_freq[comb[0]] * name_freq[comb[1]] * name_freq[comb[2]]
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools
n=int(input())
m=list("MARCH")
d=[0]*5
for i in range(n):
  s=input()
  for j in range(len(m)):
    if s[0]==m[j]:
      d[j]+=1
ans=0
for i in list(itertools.combinations(list(range(5)), 3)):
  k=list(i)
  ans+=d[k[0]]*d[k[1]]*d[k[2]]
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
N = int(input())
defdict = defaultdict(int)
for _ in range(N):
  st = input()
  fst = st[0]
  if fst in "MARCH":
  	defdict[fst]+=1
V = list(defdict.values())
NV =  len(V)
ans = 0
for i in range(NV):
  for j in range(i+1,NV):
    for k in range(j+1,NV):
      ans+=V[i]*V[j]*V[k]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import combinations
n=int(input())
dp=[0]*5
for i in range(n):
  s=input()
  if s[0]=="M":
      dp[0]+=1
  if s[0]=="A":
      dp[1]+=1
  if s[0]=="R":
      dp[2]+=1
  if s[0]=="C":
      dp[3]+=1
  if s[0]=="H":
      dp[4]+=1
ans=0
for a,b,c in combinations(dp,3):
  ans+=a*b*c
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter


if __name__ == "__main__":
    N = int(input())
    C = Counter()
    march = ["M", "A", "R", "C", "H"]
    for _ in range(N):
        s = input()
        if s[0] in march:
            C[s[0]] += 1
    ans = 0
    for i in range(3):
        for j in range(i+1, 4):
            for k in range(j+1, 5):
                ans += C[march[i]] * C[march[j]] * C[march[k]]
    print(ans)

Submission status: Accepted

Solution code:
import itertools

N = int(input())
t = tuple('MARCH')
dic = {}

for _ in range(N):
    s = input()
    x = s[0]

    if x not in t:
        continue

    if x in dic:
        dic[x] += 1
    else:
        dic[x] = 1

count = [v for v in dic.values()]
if len(count) < 3:
    print(0)
    exit()

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

print(ans)

Submission status: Accepted

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


n = int(input().strip())


d = {
    "M": 0,
    "A": 0,
    "R": 0,
    "C": 0,
    "H": 0
}
top = list("MARCH")


for _ in range(n):
    name = input().strip()
    if name[0] in top:
        d[name[0]] += 1

ans = 0

for a in range(3):
    for b in range(a + 1, 4):
        for c in range(b + 1, 5):
            ans += d[top[a]] * d[top[b]] * d[top[c]]

print(ans)

Submission status: Accepted

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

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

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

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
T = [0]*5
for i in range(N):
    S = input()
    if S[0]=="M":
        T[0]+=1
    elif S[0]=="A":
        T[1]+=1
    elif S[0]=="R":
        T[2]+=1
    elif S[0]=="C":
        T[3]+=1
    elif S[0]=="H":
        T[4]+=1
from itertools import combinations
Ls = list(combinations([0,1,2,3,4],3))
out = 0
for L in Ls:
    out += T[L[0]]*T[L[1]]*T[L[2]]
print(out)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import combinations

N = int(input())
name_count = {'M': 0,
              'A': 0,
              'R': 0,
              'C': 0,
              'H': 0, }
for i in range(N):
    name = input()

    if name[0] in name_count:
        name_count[name[0]] += 1


def comb(n, r):
    up = 1
    down = 1
    for i in range(r):
        up *= n - i
        down *= i + 1
    return up // down


all_sum = sum(name_count.values())
total = comb(all_sum, 3)

for i in name_count.values():
    if i >= 2:
        total -= comb(i, 2) * (all_sum - i)

    if i >= 3:
        total -= comb(i, 3)

print(total)

Submission status: Accepted

Solution code:
import sys
import itertools
from collections import Counter
N = int(input())
name = []
for _ in range(N):
    a = input()
    name.append(a[0])
name = Counter(name)
kouho = []
kouho.append(name["M"])
kouho.append(name["A"])
kouho.append(name["R"])
kouho.append(name["C"])
kouho.append(name["H"])
name = []
for i in kouho:
    if i == 0:
        continue
    name.append(i)
total = sum(name)
seki = 1
for i in name:
    seki = seki*i
hikuseki = 1
for i in name:
    if i > 1:
        hikuseki = hikuseki*i

if len(name) < 3:
    print(0)
    sys.exit()

seki = list(itertools.combinations(name, 3))
ans = 0
for i in seki:
    a, b, c = i
    ans += a*b*c
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
from collections import Counter
c = Counter()
for _ in range(n):
    s = input()[0]
    c[s] += 1

ans = 0
ans += c["M"]*c["A"]*c["R"]
ans += c["M"]*c["A"]*c["C"]
ans += c["M"]*c["A"]*c["H"]
ans += c["M"]*c["R"]*c["C"]
ans += c["M"]*c["R"]*c["H"]
ans += c["M"]*c["C"]*c["H"]
ans += c["A"]*c["R"]*c["C"]
ans += c["A"]*c["R"]*c["H"]
ans += c["A"]*c["C"]*c["H"]
ans += c["R"]*c["C"]*c["H"]

print(ans)

Submission status: Accepted

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
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

lst = [m_cnt, a_cnt, r_cnt, c_cnt, h_cnt]
ans = 0
for i in range(5):
    for j in range(i+1, 5):
        for k in range(j+1, 5):
            ans += lst[i] * lst[j] * lst[k]
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import itertools

n = int(input())

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

for i in range(n):
    s = list(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

memo = [M,A,R,C,H]

ans = 0

for v in itertools.combinations(memo, 3):
    tmp = 1
    for vv in v:
        tmp *= vv
    ans += tmp
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
n = int(input())
arr = [input() for _ in range(n)]

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

result = []
for s in li:
    result.append(len(set([x for x in arr if x[0] == s])))

ans = 0

for x, y, z in combinations(result, 3):
    ans += x * y * z

print(ans)

Submission status: Accepted

Solution code:
import sys
from itertools import combinations

index = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}

N = int(sys.stdin.readline())
for _ in range(N):
    s = sys.stdin.readline().strip()
    if s[0] in index:
        index[s[0]] += 1

ans = 0
for (a, b, c) in combinations(index.items(), 3):
    ans += a[1] * b[1] * c[1]

print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
N = int(input())
A = [0 for _ in range(5)]
for _ in range(N):
    a = input().strip()
    if a[0]=="M":
        A[0] += 1
    elif a[0]=="A":
        A[1] += 1
    elif a[0]=="R":
        A[2] += 1
    elif a[0]=="C":
        A[3] += 1
    elif a[0]=="H":
        A[4] += 1
cnt = 0
for x in combinations(range(5),3):
    cnt += A[x[0]]*A[x[1]]*A[x[2]]
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
S = [input() for _ in range(N)]
res = [0] * 5
ini = 'MARCH'
for i in range(N):
    for j in range(5):
        if S[i][0] == ini[j]:
            res[j] += 1

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

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
d = defaultdict(int)
for _ in range(n):
    s = input() 
    d[s[0]] += 1
res = 0
li = ['M','A','R','C','H']
for i in range(3):
    a = li[i]
    for j in range(i+1,4):
        b = li[j]
        for k in range(j+1,5):
            c = li[k]
            res += d[a] * d[b] * d[c]
print(res)

Submission status: Accepted

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

vs = []
for v in md.values():
    vs.append(v)

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

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):
    a,b,c = ptn
    ans += ctr[a] * ctr[b] * ctr[c]
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
T=set(['M','A','R','C','H'])
d={}

for _ in range(N):
    s=input()[0]
    if s in T:
        d[s]=d.get(s, 0)+1

k=len(d.keys())
ans=0
if 3<=k:
    import itertools
    for x,y,z in itertools.combinations(d.keys(), 3):
        #print(x,y,z,d[x]*d[y]*d[z])
        ans+=d[x]*d[y]*d[z]
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations as C

d = {}
for _ in range(int(input())):
    s = input()[0]
    if s in "MARCH":
        d[s] = d.get(s, 0) + 1
else:
    print(sum([p * q * r for p, q, r in C(d.values(), 3)]))

Submission status: Accepted

Solution code:
from itertools import combinations as C

d = {}
for _ in range(int(input())):
    s = input()[0]
    d[s] = d.get(s, 0) + 1

dk = set(d.keys()) & set("MARCH")
ans = 0
for p, q, r in C(dk, 3):
    ans += d[p] * d[q] * d[r]
else:
    print(ans)

Submission status: Accepted

Solution code:
import collections
N = int(input())
S = []
for i in range(N):
    st = str(input())
    S.append(st[0])
    
#print(S)

c = collections.Counter(S)
#print(c)
count = []
for i in c.items():
    if i[0] in 'MARCH':
        count.append(i[1])
#print(count)
ans = 0
for i in range(len(count)):
    for j in range(i+1,len(count)):
        for k in range(j+1,len(count)):
            #print(i,j,k)
            ans += count[i]*count[j]*count[k]
            
if len(count) != 0:
    print(ans)
else:
    print(0)

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, gcd
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 functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N = INT()
    S = [INPUT() for _ in range(N)]

    inis = [s[0] for s in S if s[0] == 'M' or s[0] == 'A' or s[0] == 'R' or s[0] == 'C' or s[0] == 'H']
    c = Counter(inis)
    ans = 0
    for tpl in list(combinations(c.values(), 3)):
        ans += list(accumulate(tpl, mul))[-1]

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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

S_head = []
for s in S:
    if s[0] in ['M', 'A', 'R', 'C', 'H']:
        S_head.append(s[0])

S_head_c = Counter(S_head)
ans = 0
for i in list(combinations(['M', 'A', 'R', 'C', 'H'], 3)):
    tmp = 1
    for j in i:
        tmp *= S_head_c[j]
    ans += tmp

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
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
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
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 = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = [input() for i in range(N)]
dic = defaultdict(list)

for s in S:
    dic[s[0]].append(s)

L = list(combinations(list("MARCH"), 3))
# print(L)

cnt = 0
for l in L:
    # print(l)
    cnt += len(dic[l[0]]) * len(dic[l[1]]) * len(dic[l[2]])
print(cnt)

Submission status: Accepted

Solution code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()

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

for i in range(n):
  k=input()[0]
  if k=='M':
    m+=1
  if k=='A':
    a+=1
  if k=='R':
    r+=1
  if k=='C':
    c+=1
  if k=='H':
    h+=1

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

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

Submission status: Accepted

Solution code:
n = int(input())
m, a, r, c, h = 0, 0, 0, 0, 0
for _ in range(n):
    i = input()
    i = i[0]
    if i == 'M':
        m += 1
    elif i == 'A':
        a += 1
    elif i == 'R':
        r += 1
    elif i == 'C':
        c += 1
    elif i == 'H':
        h += 1
 
ans = 0
from itertools import combinations
for i in combinations([m, a, r, c, h], 3):
    i, j, k = i
    ans += i * j * k
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
def input():
    return stdin.readline().strip()
 
n = int(input())
m, a, r, c, h = 0, 0, 0, 0, 0
for _ in range(n):
    i = input()
    i = i[0]
    if i == 'M':
        m += 1
    elif i == 'A':
        a += 1
    elif i == 'R':
        r += 1
    elif i == 'C':
        c += 1
    elif i == 'H':
        h += 1
 
ans = 0
from itertools import combinations
for i in combinations([m, a, r, c, h], 3):
    i, j, k = i
    ans += i * j * k
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
lst=[]
s1=0
s2=0
s3=0
s4=0
s5=0
for i in range(N):
    s=input()
    if s[0]=="M":
        s1+=1
    elif s[0]=='A':
        s2+=1
    elif s[0]=="R":
        s3+=1
    elif s[0]=="C":
        s4+=1
    elif s[0]=="H":
        s5+=1
ans=0
ans+=s1*s2*s3
ans+=s1*s2*s4
ans+=s1*s2*s5
ans+=s1*s4*s5
ans+=s1*s3*s5
ans+=s1*s3*s4
ans+=s2*s3*s4
ans+=s2*s3*s5
ans+=s3*s4*s5
ans+=s2*s4*s5
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:
    d[s[0]] += 1
ans = 0
for v in itertools.combinations(d, 3):
    ans += d[v[0]] * d[v[1]] * d[v[2]]
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
#s=[]
l=[0]*5
#print(l)
for _ in range(n):
    s=input()
    if s[0]=="M": l[0]+=1
    if s[0]=="A": l[1]+=1
    if s[0]=="R": l[2]+=1
    if s[0]=="C": l[3]+=1
    if s[0]=="H": l[4]+=1
#print(l)
ans=0
for i in range(5):
    for j in range(5):
        for k in range(5):
            if i!=j and j!=k and k!=i:
                ans+=l[i]*l[j]*l[k]
ans//=6
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations

n = int(input())
c = {
    "M": 0,
    "A": 0,
    "R": 0,
    "C": 0,
    "H": 0
}
ck = list(c.keys())
cnt = 0

for i in range(n):
    s = input()
    if s[0] in c.keys():
        c[s[0]] += 1
        cnt += 1

if cnt >= 3:
    ans = 0
    for p in list(combinations("MARCH", 3)):
        ans += c[p[0]] * c[p[1]] * c[p[2]]
    print(ans)
else:
    print(0)

Submission status: Accepted

Solution code:
N = int(input())
march_dict = {
    'M': 0,
    'A': 0,
    'R': 0,
    'C': 0,
    'H': 0
}
for i in range(N):
    S = input()
    s_head = S[0]
    if march_dict.get(s_head) is not None:
        march_dict[s_head] += 1

# march_candidate = [key for key, val in march_dict.items() if val != 0]
import itertools

ans = 0
for C in itertools.combinations(['M', 'A', 'R', 'C', 'H'], 3):
    a = march_dict[C[0]]
    b = march_dict[C[1]]
    c = march_dict[C[2]]
    ans += a * b * c
    # print(ans)
    # print(march_candidate)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
march_dict = {
    'M': 0,
    'A': 0,
    'R': 0,
    'C': 0,
    'H': 0
}
for i in range(N):
    S = input()
    s_head = S[0]
    if march_dict.get(s_head) is not None:
        march_dict[s_head] += 1

march_candidate = [key for key, val in march_dict.items() if val != 0]

import itertools

ans = 0
for C in itertools.combinations(march_candidate, 3):
    a = march_dict[C[0]]
    b = march_dict[C[1]]
    c = march_dict[C[2]]
    ans += a * b * c
    #print(ans)
    #print(march_candidate)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

l = [0] * 5
for i in range(n):
    s = list(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(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:
from sys import stdin
def input():
    return stdin.readline().strip()

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

ans = 0
from itertools import combinations
for i in combinations([m, a, r, c, h], 3):
    i, j, k = i
    ans += i * j * k
print(ans)

Submission status: Accepted

Solution code:
import itertools
N = int(input())
M_Dict = {"M":0,"A":0,"R":0,"C":0,"H":0}
for i in range(N):
    moji = str(input())
    if moji[0] in M_Dict.keys():
        M_Dict[moji[0]] += 1
M_Dict = {k: v for k, v in M_Dict.items() if v != 0}    
if len(M_Dict) < 3:
    ans = 0
else:
    ans = 0
    for k in itertools.combinations(list(M_Dict.keys()),3):
        ans += int(M_Dict[k[0]]) * int(M_Dict[k[1]]) * int(M_Dict[k[2]])
    
print(ans)

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    S = [SS() for _ in range(N)]

    cnt = collections.Counter([i[0] for i in S])
    # print(cnt)
    ans = 0
    for i, j, k in itertools.combinations(('M', 'A', 'R', 'C', 'H'), 3):
        ans += cnt[i] * cnt[j] * cnt[k]

    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
n = int(input())

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

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

Submission status: Accepted

Solution code:
N = int(input())
num = {s: 0 for s in list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")}
for i in range(N):
    s = input()
    num[s[0]] += 1

patterns = [
    "MAR",
    "MAC",
    "MAH",
    "MRC",
    "MRH",
    "MCH",

    "ARC",
    "ARH",
    "ACH",

    "RCH"
]
ans = 0
for pat in patterns:
    ans += num[pat[0]]*num[pat[1]]*num[pat[2]]
print(ans)

Submission status: Accepted

Solution code:
import sys
from itertools import combinations

input = sys.stdin.readline
d = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for i in range(int(input())):
    a = input()
    if a[0] in "MARCH":
        d[a[0]] += 1

l = [i for i in d.values() if i != 0]
print(sum(i * j * k for i, j, k in combinations(l, 3)))

Submission status: Accepted

Solution code:
import itertools
n=int(input())
name=dict()
for c in "MARCH":
    name[c]=0
for i in range(n):
    t=input()
    if t[0] in "MARCH":
        name[t[0]]+=1

ans=0
for hey in itertools.combinations("MARCH",3):
    ans+=name[hey[0]]*name[hey[1]]*name[hey[2]]
print(ans)

Submission status: Accepted

Solution code:
M,A,R,C,H=list(),list(),list(),list(),list()
N=int(input())
for i in range(N):
  S=input()
  if S[0]=="M":
    M.append(S)
  elif S[0]=="A":
    A.append(S)
  elif S[0]=="R":
    R.append(S)
  elif S[0]=="C":
    C.append(S)
  elif S[0]=="H":
    H.append(S)
a=len(M)
b=len(A)
c=len(R)
d=len(C)
e=len(H)
print(a*b*c+a*b*d+a*b*e+a*c*d+a*c*e+a*d*e+b*c*d+b*c*e+b*d*e+c*d*e)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict

_,*s=sys.stdin.read().split()
intl=defaultdict(int)
for p in s:
  intl[p[0]]+=1

march=list(intl[w] for w in 'MARCH')
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=[input() for _ in range(int(input()))];m,a,r,c,h=0,0,0,0,0
for i in n:
  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
r=[m,a,r,c,h]
print(sum([sum([sum([r[i]*r[j]*r[k] for k in range(j+1,5)]) for j in range(i+1,5)]) for i in range(5)]))

Submission status: Accepted

Solution code:
n=[input() for _ in range(int(input()))];m,a,r,c,h,count=0,0,0,0,0,0
for i in n:
  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
r=[m,a,r,c,h]
print(sum([sum([sum([r[i]*r[j]*r[k] for k in range(j+1,5)]) for j in range(i+1,5)]) for i in range(5)]))

Submission status: Accepted

Solution code:
n=[input() for _ in range(int(input()))];m,a,r,c,h,count=0,0,0,0,0,0
for i in n:
  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
r=[m,a,r,c,h]
for i in range(5):
  for j in range(i+1,5):
    for k in range(j+1,5):
      count+=r[i]*r[j]*r[k]
print(count)

Submission status: Accepted

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

cnt = [0] * 5

for x in s:
    if x[0] == 'M':
        cnt[0] += 1
    if x[0] == 'A':
        cnt[1] += 1
    if x[0] == 'R':
        cnt[2] += 1
    if x[0] == 'C':
        cnt[3] += 1
    if x[0] == 'H':
        cnt[4] += 1

if cnt.count(0) > 2:
    print(0)
    exit()

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

print(ans)