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 sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())

m = {}

for i in range(N):
    s = input()
    if s[0] not in "MARCH":
        continue

    m[s[0]] = m.get(s[0], 0) + 1

ans = 0
for i in range(5):
    for j in range(i + 1, 5):
        for k in range(j + 1, 5):
            ans += m.get("MARCH"[i], 0) * m.get("MARCH"[j], 0) * m.get("MARCH"[k], 0)

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:
n = int(input())
dic = {}
march = set(['M', 'A', 'R', 'C', 'H'])
for i in range(n):
  s = input()[0]
  if s in march:
    dic.setdefault(s, 0)
    dic[s] += 1
if len(dic) <= 2:
  print(0)
  exit()
march = ['M', 'A', 'R', 'C', 'H']
for t in march:
  dic.setdefault(t, 0)
march = ['MAR', 'MAC', 'MAH', 'MRC', 'MRH', 'MCH', 'ARC', 'ARH', 'ACH', 'RCH']
res = 0
for t in march:
  res += (dic[t[0]] * dic[t[1]] * dic[t[2]])
print(res)

Submission status: Accepted

Solution code:
import itertools
import collections
N = int(input())
S = [input() for i in range(N)]
candi = []
for s in S:
    if s[0] == 'M' or s[0] == 'A' or s[0] == 'R' or s[0] == 'C' or s[0] == 'H':
        candi.append(s[0])
col_s = collections.Counter(candi)
combi_s = itertools.combinations(list(col_s),3)
counter = 0 
for i in combi_s:
    counter += col_s[i[0]]*col_s[i[1]]*col_s[i[2]]
print(counter)

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
import heapq
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
# list(map(int, input().split()))

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

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

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

ans = 0
for c in comb:  # 計10通り
    ans += cnt[c[0]] * cnt[c[1]] * cnt[c[2]]

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())
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:
D={'M':0,'A':0,'R':0,'C':0,'H':0}
for k in range(int(input())):
  s=input()
  if s[0] in D.keys():
    D[s[0]]+=1

t,v=0,list(D.values())
for i in range(5):
  for j in range(i+1,5):
    for k in range(j+1,5):
      t+=v[i]*v[j]*v[k]

print(t)

Submission status: Accepted

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


inf = 10 ** 18
mod = 10 ** 9 + 7

n = ir()
s = [input()[0] for i in range(n)]
dic = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
for c in s:
    if c in dic:
        dic[c]+=1
ans = 0
judge = [dic[c] for c in dic.keys()]
for tmp in itertools.combinations(judge, 3):
    ans += tmp[0]*tmp[1]*tmp[2]
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
from itertools import combinations
N = int(input())
dic = defaultdict(list)
for _ in range(N):
    s = input()
    if s[0] in "MARCH":
        dic[s[0]].append(s)

cmb = combinations(dic.keys(),3)
ans = 0
for a,b,c in cmb:
    ans += len(dic[a])*len(dic[b])*len(dic[c])
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
march =[]

for i in range(n):
    a = input()
    ai = a[0]
    march.append(ai)

import collections
c = collections.Counter(march)

mm = c["M"]
aa = c["A"]
rr = c["R"]
cc = c["C"]
hh = c["H"]

import itertools
seq = [mm,aa,rr,cc,hh]
mmm = list(itertools.combinations(seq,3))

res= 0
for i in range(10):
    aaa = mmm[i]
    res += aaa[0]*aaa[1]*aaa[2]

print(res)

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7
import numpy as np

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result
N = i()
S = [s() for _ in range(N)]
m = 0
a = 0
r = 0
c = 0
h = 0
for i in range(N):
    if S[i][0] == 'M':
        m += 1
    elif S[i][0] == 'A':
        a += 1
    elif S[i][0] == 'R':
        r += 1
    elif S[i][0] == 'C':
        c += 1
    elif S[i][0] == 'H':
        h += 1
cmbs = [m,a,r,c,h]
cmbs = itertools.combinations(cmbs,3)
ans = 0
for c in cmbs:
    ans += np.prod(list(c))
print(ans)

Submission status: Accepted

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

from itertools import combinations
comb=combinations(["M", "A", "R", "C", "H"], 3)

ans=0
for c in comb:
    ans+=cnt[c[0]]*cnt[c[1]]*cnt[c[2]]

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
import collections
import itertools
l=['M','A','R','C','H']
x=[]
for i in range(n):
  s=input()
  if s[0] in l:
    x.append(s[0])
c=collections.Counter(x)
ans=0
for p in itertools.combinations('MARCH',3):
  cnt=1
  for j in range(3):
    cnt*=c[p[j]]
  ans+=cnt
print(ans)

Submission status: Accepted

Solution code:
import itertools

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

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
cnt.sort()
# print(cnt)
p = 0
if cnt[2] == 0:
    p = 0
elif cnt[1] == 0:
    p = cnt[2]*cnt[3]*cnt[4]
elif cnt[0] == 0:
    p += cnt[1]*cnt[2]*cnt[3]
    p += cnt[1]*cnt[2]*cnt[4]
    p += cnt[1]*cnt[3]*cnt[4]
    p += cnt[2]*cnt[3]*cnt[4]
else:
    num = [0,1,2,3,4]
    combi = list(itertools.combinations(num,3))
    # print(combi)
    for i in range(len(combi)):
        a,b,c = combi[i][0], combi[i][1], combi[i][2]
        p += cnt[a]*cnt[b]*cnt[c]
print(p)

Submission status: Accepted

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

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

for c in s:
    if c[0] not in d:
        d[c[0]] = 1 
    else:
        d[c[0]] += 1

tmp = d.copy()
t = ['M', 'A', 'R', 'C', 'H']
for c in tmp:
    if c not in t:
        d.pop(c)

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

Submission status: Accepted

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

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

c = [0 for _ in range(5)]
t = 'MARCH'

for i in range(n):
    for j in range(5):
        if s[i][0] == t[j]:
            c[j] += 1
ans = 0 
for i in range(5):
    for j in range(i+1, 5): 
        for k in range(j+1, 5): 
            ans += c[i]*c[k]*c[j]
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations


n = int(input())

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

c = list(combinations(s.keys(), 3))
ans = 0
for i in c:
    ans += s[i[0]] * s[i[1]] * s[i[2]]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = [input()[0] for i in range(N)]
from collections import Counter
ctr = Counter(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:
from collections import Counter
from itertools import combinations as comb

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

ans = 0
for i, j, k in comb(["M","A","R","C","H"], 3):
    ans += d[i]*d[j]*d[k]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys
n=int(input())

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

march=[d["M"],d["A"],d["R"],d["C"],d["H"]]
zero=march.count(0)
if zero>=3:
    ans=0
    print(ans)
    sys.exit()

m=[]
for i in march:
    if i>0:
        m.append(i)

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

print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
n=int(input())
name=[0]*5
march=['M','A','R','C','H']
for i in range(n):
  s=input()
  if s[0] in march:
    name[march.index(s[0])]+=1
sm=0
for i,j,k in list(combinations(name,3)):
  sm+=i*j*k
print(sm)

Submission status: Accepted

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

for i in range(n):
  s = input()
  d[s[0]] = d.get(s[0], 0) + 1

x = 0
x += d["M"] * d["A"] * d["R"]
x += d["M"] * d["A"] * d["C"]
x += d["M"] * d["A"] * d["H"]
x += d["M"] * d["R"] * d["C"]
x += d["M"] * d["R"] * d["H"]
x += d["M"] * d["C"] * d["H"]
x += d["A"] * d["R"] * d["C"]
x += d["A"] * d["R"] * d["H"]
x += d["A"] * d["C"] * d["H"]
x += d["R"] * d["C"] * d["H"]
print(x)

Submission status: Accepted

Solution code:
import numpy,itertools
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
c = [0] * 5
for _ in range(n):
    s = readline().decode().rstrip()
    if s[0] == 'M':
        c[0] += 1
    elif s[0] == 'A':
        c[1] += 1
    elif s[0] == 'R':
        c[2] += 1
    elif s[0] == 'C':
        c[3] += 1
    elif s[0] == 'H':
        c[4] += 1

cm = list(itertools.combinations(c, 3))
arr = numpy.array(cm)

print(sum(list(numpy.prod(arr, axis=1))))

Submission status: Accepted

Solution code:
#M=0 A=1 R=2 C=3 H=4
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]

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

ans = 0
for i in range(10):
    ans += name[p[i]] * name[q[i]] * name[r[i]]

print(ans)

Submission status: Accepted

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


def log(*args):
    print(*args, file=sys.stderr)


def main():
    n = int(input().rstrip())
    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)


if __name__ == '__main__':
    main()

Submission status: Accepted

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


def log(*args):
    print(*args, file=sys.stderr)


def main():
    n = int(input().rstrip())
    s = [input()[0] for _ in range(n)]
    s = [v for v in s if v in 'MARCH']
    c = Counter(s)
    ans = 0
    for x, y, z in combinations(c, 3):
        ans += c[x] * c[y] * c[z]
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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


def log(*args):
    print(*args, file=sys.stderr)


def main():
    n = int(input().rstrip())
    m = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
    for _ in range(n):
        s = input().rstrip()
        if s[0] in m:
            m[s[0]] += 1
    ans = 0
    for c in combinations(m, 3):
        ans += m[c[0]] * m[c[1]] * m[c[2]]
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict
import itertools
d = defaultdict(int)
x='MARCH'
for i in range(5):
  d[x[i]]=i+1
x=[0]*5
N=int(input())
for i in range(N):
  S=input()
  a=d[S[0]]
  if a>0:
    x[a-1]+=1
ans=0
for i,j,k in itertools.combinations([i for i in range(5)], 3):
  ans+=x[i]*x[j]*x[k]
print(ans)

Submission status: Accepted

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

for s in S:
    for c in ['M', 'A', 'R', 'C', 'H']:
        if s.startswith(c):
            d[c] += [s]

num = {k: len(d[k]) for k in ['M', 'A', 'R', 'C', 'H']}

ans = 0
for v in itertools.combinations(['M', 'A', 'R', 'C', 'H'], 3):
    tmp = 1
    for c in v:
        tmp *= num[c]
    ans += tmp
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
m = []
apple = []
r = []
cat = []
h = []

for _ in range(n):
    s = str(input())
    if s[0]=="M":
        m.append(s)
    elif s[0]=="A":
        apple.append(s)
    elif s[0]=="R":
        r.append(s)
    elif s[0]=="C":
        cat.append(s)
    elif s[0]=="H":
        h.append(s)
    else:
        pass
a = len(m)
b = len(apple)
c = len(r)
d = len(cat)
e = len(h)
print(a*b*c + a*b*d + a*b*e + b*c*d + b*c*e + c*d*e + a*c*d + a*c*e + a*d*e + b*d*e)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import combinations
from collections import Counter
n = int(input())
C = Counter()
for i in range(n):
    C[input()[0]] +=1


print(sum(C[a]*C[b]*C[c] for a,b,c in combinations('MARCH',3)
))

Submission status: Accepted

Solution code:
from itertools import combinations
from collections import Counter
n = int(input())
C = Counter()
for i in range(n):
    C[input()[0]] +=1

print(sum(C[a]*C[b]*C[c] for a,b,c in combinations('MARCH',3)
))

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc089/tasks/abc089_c
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def read_a_int(): return int(read())


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from itertools import product, permutations, combinations

N = read_a_int()
cnt = defaultdict(lambda: 0)
march = {'M', 'A', 'R', 'C', 'H'}
for _ in range(N):
    s = read()[0]
    if s in march:
        cnt[s] += 1
ans = 0
for a, b, c in combinations(cnt.values(), r=3):
    ans += a * b * c
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations

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

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

Submission status: Accepted

Solution code:
import itertools
n = int(input())
sl = []

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

lst = []
for com in itertools.combinations(dic.keys(),3):
    lst.append(com)

ans = 0
for v in lst:
    ans += dic[v[0]] * dic[v[1]] * dic[v[2]]
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from collections import Counter
import itertools

n = int(input())

s = [str(input()) for _ in range(n)]
initial = []
d = ['M', 'A', 'R', 'C', 'H']

for i in range(n):
    if s[i][0] in d:
        initial.append(s[i][0])

reg = Counter(initial)
ele = []

for i, j in reg.items():
    ele.append(i)
ans = 0
for A in itertools.combinations(ele, 3):
    #print(A)
    cnt = 1
    for s in A:
        cnt *= reg[s]
    ans += cnt

print(ans)

Submission status: Accepted

Solution code:
import itertools

N = int(input())
MARCH=[0]*5
ans = 0
for _ in range(N):
    S = (input())[0]
    if S == 'M':
        MARCH[0]+=1
    if S == 'A':
        MARCH[1]+=1
    if S == 'R':
        MARCH[2]+=1
    if S == 'C':
        MARCH[3]+=1
    if S == 'H':
        MARCH[4]+=1

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

print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
from collections import defaultdict
def main():
    n = int(input())
    march = defaultdict(int)

    for _ in range(n):
        s = input()
        march[s[0]] += 1

    p = tuple(combinations(['M', 'A', 'R', 'C', 'H'], 3))
    r = 0
    for pe in p:
        t = march[pe[0]] * march[pe[1]] * march[pe[2]]
        r += t
    print(r)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
M=A=R=C=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
a=[M,A,R,C,H]
from itertools import combinations
ans=0
for L in list(combinations(a,3)):
    ans+=L[0]*L[1]*L[2]
print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
import itertools
n = int(input())
dic = defaultdict(lambda : 0)
for _ in range(n):
    s = input()
    if s[0] in 'MARCH':
        dic[s[0]] += 1
if len(dic) <= 2:
    print(0)
    sys.exit()
if len(dic) == 3:
    ans = 1
    for val in dic.values():
        ans *= val
    print(ans)
    sys.exit()

ans = 0
for i, j, k in itertools.combinations(dic.keys(), 3):
    ans += dic[i] * dic[j] * dic[k]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict

def main():
    N = int(input())
    MARCH = ['M','A','R','C','H']
    S = [0] * len(MARCH)
    for _ in range(N):
        s = input()
        if not s[0] in MARCH:
            continue
        if s[0] == MARCH[0]: S[0] += 1
        elif s[0] == MARCH[1]: S[1] += 1
        elif s[0] == MARCH[2]: S[2] += 1
        elif s[0] == MARCH[3]: S[3] += 1
        elif s[0] == MARCH[4]: S[4] += 1
    cnt = 0
    for i in range(len(S)-2):
        for j in range(i+1,len(S)-1):
            for k in range(j+1,len(S)):
                cnt += S[i]*S[j]*S[k]
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools
n = int(input())
Dict = {'M':0,'A':1,'R':2,'C':3,'H':4}

List = [[]for i in range(5)]
for i in range(n):
    tmp = input()
    if tmp[0] in Dict:
        index = Dict[tmp[0]]
        List[index].append(tmp)
List_num = [len(List[i]) for i in range(5)]
ans = 0
for v in itertools.combinations(List_num,3):
    cnt = 1
    for youso in v:
        cnt*=youso
    ans += cnt
print(ans)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
N = int(input())
initials = [0]*5
lis = ['M', 'A', 'R', 'C', 'H']
SET = set(lis)
for _ in range(N):
    s = input()[0]
    if not s in SET:
        continue
    idx = lis.index(s)
    initials[idx] += 1

ans = 0
from itertools import permutations
for a, b, c in permutations(initials, 3):
    ans += a*b*c

print(ans//6)

Submission status: Accepted

Solution code:
import itertools
N = int(input())

dic = {"M":0, "A":0, "R":0, "C":0, "H":0}
S = set([])
for i in range(N):
  temp = str(input())
  if temp[0] == "M":
    dic["M"] += 1
    S.add("M")
  elif temp[0] == "A":
    dic["A"] += 1
    S.add("A")    
  elif temp[0] == "R":
    dic["R"] += 1  
    S.add("R")
  elif temp[0] == "C":
    dic["C"] += 1  
    S.add("C")
  elif temp[0] == "H":
    dic["H"] += 1
    S.add("H")
#print(dic)
#print(len(S))
L = list(dic.values())
if len(S) <=2:
  print("0")
  exit()
ans = 0
A = list(itertools.combinations(L,3))
for X in A:
  ans += X[0]*X[1]*X[2]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

check = {v:0 for v in "MARCH"}

for i in range(n):
    s = input()
    if s[0] in check:
        check[s[0]] += 1
ans = 0
kijyun = "MARCH"

for a in range(5):
    for b in range(a+1,5):
        for c in range(b+1,5):
            ans += check[kijyun[a]] * check[kijyun[b]] * check[kijyun[c]]

print(ans)

Submission status: Accepted

Solution code:
import itertools

N = int(input())

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

comb = itertools.combinations(MARCH,3)

for j in comb:
  ans += j[0]*j[1]*j[2]
print(ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    num_m = 0
    num_a = 0
    num_r = 0
    num_c = 0
    num_h = 0
    inlis = set()
    for i in range(n):
        s = input()
        if s in inlis:
            pass
        else:
            inlis.add(s)
            if s[0] == "M":
                num_m += 1        
            if s[0] == "A":
                num_a += 1
            if s[0] == "R":
                num_r += 1
            if s[0] == "C":
                num_c += 1
            if s[0] == "H":
                num_h += 1
    numlis = [num_m, num_a, num_r, num_c, num_h]
    ans = 0
    if sum(numlis) < 3:
        print(0)
    else:
        for i in range(5):
            for j in range(5):
                for k in range(5):
                    if i == j or i == k or j == k:
                        pass
                    else:
                        ans += numlis[i] * numlis[j] * numlis[k]
        print(int(ans/6))
                    


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import itertools

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

CNT = [0] * 5
iniset = ["M","A","R","C","H"]
s_to_i = {"M":0,"A":1,"R":2,"C":3,"H":4}


for s in S:
  i = s[0]
  if not i in iniset:
    continue
    
  CNT[s_to_i[i]] += 1
  
ans = 0
for x,y,z in itertools.combinations(CNT,3):
  ans += x * y * z

print(ans)

Submission status: Accepted

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


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


n = I()
s = SR(n)
d = defaultdict(int)
for c in ['M', 'A', 'R', 'C', 'H']:
    d[c] = 0
for name in s:
    if name[0] in {'M', 'A', 'R', 'C', 'H'}:
        d[name[0]] += 1
combs = list(combinations(['M', 'A', 'R', 'C', 'H'], 3))

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

Submission status: Accepted

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

import itertools

L = [0 for _ in range(5)]

March = 'MARCH'
for s in S:
    for i, m in enumerate(March):
        if s[0] == m:
            L[i] += 1

Itr = itertools.combinations(range(5), 3)

ans = 0
for itr in Itr:
    ans += L[itr[0]]*L[itr[1]]*L[itr[2]]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = [input() for i in range(N)]
num = [0] * 5
ans = 0

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

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

Submission status: Accepted

Solution code:
N = int(input())
dic = {}
for c in "MARCH":
    dic[c] = 0
myset = set(list("MARCH"))
for _ in range(N):
    c = input()[0]
    if c in myset:
        dic[c] += 1

res = 0
for i in range(5-2):
    for j in range(i+1, 5-1):
        for k in range(j+1, 5):
            res += dic["MARCH"[i]] * dic["MARCH"[j]] * dic["MARCH"[k]]
print(res)

Submission status: Accepted

Solution code:
n = int(input())
# M,A,R,C,H
num = [0] * 5
check_list = ['M','A','R','C','H']
for _ in range(n):
    s = input()
    for i, c in enumerate(check_list):
        if s[0] == c:
            num[i]+=1
            break
ans = 0
for i in range(5-2):
    for j in range(i+1, 5-1):
        for k in range(j+1, 5):
            ans += num[i]*num[j]*num[k]
print(ans)