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

n = int(input())
ls = [input().rstrip() for _ in range(n)]
counter = collections.Counter()
for x in ls:
    x = x[0]
    if x in 'MARCH':
        counter[x] += 1

res = 0
for a, b, c in itertools.combinations('MARCH', 3):
    res += counter[a] * counter[b] * counter[c]
print(res)

Submission status: Accepted

Solution code:
from functools import reduce
from itertools import combinations
import copy

N = int(input())
S = {key: 0 for key in 'MARCH'}
for _ in range(N):
  s = input()
  if s[0] in S:
    S[s[0]] += 1

newS = copy.deepcopy(S)
keys = []
for key, value in S.items():
  if value == 0: del newS[key]
  else: keys.append(key)

if len(newS) < 3:
  print(0)
  exit()
  
ans = 0
for cmb in combinations(keys,3):
  ans += reduce(lambda x,y: x*y, [newS[idx] for idx in cmb])
print(ans)

Submission status: Accepted

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

ans = 0
cntM = 0
cntA = 0
cntR = 0
cntC = 0
cntH = 0
for i in range(N):
    cntM += (1 if S[i][0] == 'M' else 0)
    cntA += (1 if S[i][0] == 'A' else 0)
    cntR += (1 if S[i][0] == 'R' else 0)
    cntC += (1 if S[i][0] == 'C' else 0)
    cntH += (1 if S[i][0] == 'H' else 0)
cntlst = [cntM, cntA, cntR, cntC, cntH]

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

Submission status: Accepted

Solution code:
import itertools
N = int(input().strip())
name = [input().strip() for _ in range(N)]

n_dict = {k:0 for k in 'MARCH'}
for n in name:
  if n[0] in 'MARCH':
    n_dict[n[0]] += 1

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

Submission status: Accepted

Solution code:
N = int(input())
ls = []
ls2 = []
for i in range(N):
    ls.append(input())
for i in range(N):
    ls2.append(ls[i][0])
M = ls2.count("M")
A = ls2.count("A")
R = ls2.count("R")
C = ls2.count("C")
H = ls2.count("H")
print(M*A*R+M*A*C+M*A*H+M*R*C+M*R*H+M*C*H+A*R*C+A*R*H+A*C*H+R*C*H)

Submission status: Accepted

Solution code:
N = int(input())
ls = []
ls2 = []
M = 0
A = 0
R = 0
C = 0
H = 0
for i in range(N):
    ls.append(input())
for i in range(N):
    ls2.append(ls[i][0])
M = ls2.count("M")
A = ls2.count("A")
R = ls2.count("R")
C = ls2.count("C")
H = ls2.count("H")
print(M*A*R+M*A*C+M*A*H+M*R*C+M*R*H+M*C*H+A*R*C+A*R*H+A*C*H+R*C*H)

Submission status: Accepted

Solution code:
from collections import defaultdict
import itertools
d = defaultdict(list)
n = int(input())
for i in range(n):
  s = input()
  d[s[0]].append(s)
cnt = 0
for v in itertools.combinations(["M","A","R","C","H"], 3):
  cnt += len(d[v[0]])*len(d[v[1]])*len(d[v[2]])
print(cnt)

Submission status: Accepted

Solution code:
from itertools import combinations
n = int(input())
m = []
a = []
r = []
c = []
h = []
for i in range(n):
  t = input()
  if t[0] == 'M':
    m.append(t)
  elif t[0] == 'A':
    a.append(t)
  elif t[0] == 'R':
    r.append(t)
  elif t[0] == 'C':
    c.append(t)
  elif t[0] == 'H':
    h.append(t)

names = [m,a,r,c,h]
com = list(combinations(names,3))
cnt = 0
for i in range(len(com)):
  cnt += len(com[i][0]) * len(com[i][1]) * len(com[i][2])
print(cnt)

Submission status: Accepted

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

a = {}
a["M"] = 0
a["A"] = 0
a["R"] = 0
a["C"] = 0
a["H"] = 0

b = defaultdict(int)
b["M"] = 1
b["A"] = 1
b["R"] = 1
b["C"] = 1
b["H"] = 1
C = ["M","A","R","C","H"]

for i in range(N):
    s = input()
    if b[s[0]] == 1:
        a[s[0]] += 1
ans = 0        
for v in itertools.combinations(C, 3):
    ans += a[v[0]]*a[v[1]]*a[v[2]]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
march = ["M", "A", "R", "C", "H"]
S = [0,0,0,0,0]

for i in range(N):
  s = str(input())
  if s[0] in march:
    index = march.index(s[0])
    S[index] += 1
    
for i in range(5):
  if 0 in S:
    S.remove(0)
   
N = len(S)
if N <= 2:
  ans = 0
elif N == 3:
  ans = S[0]*S[1]*S[2]
elif N == 4:
  mul = S[0]*S[1]*S[2]*S[3]
  ans = 0
  for i in range(4):
    ans += mul//S[i]
else:#N = 5
  mul = S[0]*S[1]*S[2]*S[3]*S[4]
  ans = 0
  for i in range(5):
    for j in range(i+1,5):
      ans += mul//(S[i]*S[j])
      
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
S = [input()[0] for i in range(N)]
S = [i for i in S if i in {'M', 'A', 'R', 'C', 'H'}]
s = list(Counter(S).values())
ans = 0

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

sum_s=dict_s["M"]*dict_s["A"]*dict_s["R"]+ \
      dict_s["M"]*dict_s["A"]*dict_s["C"]+ \
      dict_s["M"]*dict_s["A"]*dict_s["H"]+ \
      dict_s["M"]*dict_s["R"]*dict_s["C"]+ \
      dict_s["M"]*dict_s["R"]*dict_s["H"]+ \
      dict_s["M"]*dict_s["C"]*dict_s["H"]+ \
      dict_s["A"]*dict_s["R"]*dict_s["C"]+ \
      dict_s["A"]*dict_s["R"]*dict_s["H"]+ \
      dict_s["A"]*dict_s["C"]*dict_s["H"]+ \
      dict_s["R"]*dict_s["C"]*dict_s["H"]
print(sum_s)

Submission status: Accepted

Solution code:
import math


def combi(a, b):
    ans = math.factorial(a) / (math.factorial(a - b) * math.factorial(b))
    return ans


N = int(input())
S = [0] * 5

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

c = 0
N = 0
for i in range(5):
    N += S[i]
    if S[i] != 0:
        c += 1

if c <= 2:
    print(0)

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

Submission status: Accepted

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

Submission status: Accepted

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

dict = {"M" : 0, "A" : 0, "R" : 0, "C" : 0, "H" : 0}
for s in S :
    if s[0] in "MARCH" :
        dict[s[0]] += 1

counter = list(dict.values())
ret = 0
for i in range(len(counter)) :
    for j in range(i + 1, len(counter)) :
        for k in range(j + 1, len(counter)) :
            ret += counter[i] * counter[j] * counter[k]
print(ret)

Submission status: Accepted

Solution code:
n=int(input())
s=list(input() for i in range(n))
mc=ac=rc=cc=hc=0
cnt=0
for i in range(n):
    if s[i][0] == "M":
        mc+=1
    elif s[i][0] == "A":
        ac+=1
    elif s[i][0] == "R":
        rc+=1
    elif s[i][0] == "C":
        cc+=1
    elif s[i][0] == "H":
        hc+=1
lis = [mc,ac,rc,cc,hc]
if sum(lis) == 0:
    print(0)
else:
    for i in range(5):
        for j in range(i+1,5):
            for k in range(j+1,5):
                cnt+=lis[i]*lis[j]*lis[k]
    print(cnt)

Submission status: Accepted

Solution code:
from itertools import combinations as c
n=int(input());l=[input() for _ in range(n)];m="MARCH";p=[0]*5;r=0
for s in l:
  for i in range(5):
    if s[0]==m[i]:p[i]+=1
for d in c(p,3):r+=d[0]*d[1]*d[2]
print(r)

Submission status: Accepted

Solution code:
N = int(input())
S = [0 for i in range(N)]
for i in range(N):
  S[i] = input()
 
dic = {"M":0, "A":0, "R":0, "C":0, "H":0}
for i in range(N):
  if S[i][0] in dic:
    dic[S[i][0]] += 1
    
ans = dic["M"]*dic["A"]*dic["R"]+dic["M"]*dic["A"]*dic["C"]+dic["M"]*dic["A"]*dic["H"]+dic["M"]*dic["R"]*dic["C"]+dic["M"]*dic["R"]*dic["H"]+dic["M"]*dic["C"]*dic["H"]+dic["A"]*dic["R"]*dic["C"]+dic["A"]*dic["R"]*dic["H"]+dic["A"]*dic["C"]*dic["H"]+dic["R"]*dic["C"]*dic["H"]
print(ans)

Submission status: Accepted

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

c = []
c.append(s.count("M"))
c.append(s.count("A"))
c.append(s.count("R"))
c.append(s.count("C"))
c.append(s.count("H"))
c_len = len(c)
ans = 0
for i in range(c_len):
    for j in range(i+1, c_len):
        for k in range(j+1, c_len):
            ans += c[i] * c[j] * c[k]

print(ans)

Submission status: Accepted

Solution code:
Nm = 0
Na = 0
Nr = 0
Nc = 0
Nh = 0
S = []
N = int(input())
for i in range(N):
  S.append(input())
for i in range(N):
  if S[i][0] == "M":
    Nm += 1
  if S[i][0] == "A":
    Na += 1
  if S[i][0] == "R":
    Nr += 1
  if S[i][0] == "C":
    Nc += 1
  if S[i][0] == "H":
    Nh += 1
s = 0
s += Nm*Na*Nr
s += Nm*Na*Nc
s += Nm*Na*Nh
s += Nm*Nr*Nc
s += Nm*Nr*Nh
s += Nm*Nc*Nh
s += Na*Nr*Nc
s += Na*Nr*Nh
s += Na*Nc*Nh
s += Nr*Nc*Nh
print(s)

Submission status: Accepted

Solution code:
n=int(input())
name=[list(input()) for _ in range(n)]
march=[0]*5
for s in name:
  if s[0]=='M':
    march[0]=march[0]+1
  if s[0]=='A':
    march[1]=march[1]+1
  if s[0]=='R':
    march[2]=march[2]+1
  if s[0]=='C':
    march[3]=march[3]+1
  if s[0]=='H':
    march[4]=march[4]+1
march.sort()
a=0
if march[2]==0:
  print(0)
else:
  a=a+march[0]*march[1]*march[2]
  a=a+march[0]*march[1]*march[3]
  a=a+march[0]*march[1]*march[4]
  a=a+march[0]*march[2]*march[3]
  a=a+march[0]*march[2]*march[4]
  a=a+march[0]*march[3]*march[4]
  a=a+march[1]*march[2]*march[3]
  a=a+march[1]*march[2]*march[4]
  a=a+march[1]*march[3]*march[4]
  a=a+march[2]*march[3]*march[4]
  print(a)

Submission status: Accepted

Solution code:

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

mydict = {'M':1,'A':2,'R':3,'C':4,'H':5}
count = [0] * 6
for i in range(N):
    s = S[i][0]
    if s in mydict:
        count[mydict[s]] += 1
ans = 0
for i in range(1,6):
    for j in range(i+1,6):
        if i==j:continue
        for k in range(j+1,6):
            if i==k or j == k:continue
            ans += count[i] * count[j] * count[k]
            
            
print(ans)

Submission status: Accepted

Solution code:
import itertools
from functools import reduce

N = int(input())
S = [input() for _ in range(N)]
T = [0] * 5
for s in S:
    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
ans = 0
for t in itertools.combinations(T, 3):
    ans += reduce(lambda a,b:a*b, t)
print(ans)

Submission status: Accepted

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

m,a,r,c,h=0,0,0,0,0
for s_i in s:
    if s_i[0] == "M":
        m+=1
    if s_i[0] == "A":
        a+=1
    if s_i[0] == "R":
        r+=1
    if s_i[0] == "C":
        c+=1
    if s_i[0] == "H":
        h+=1

lst=[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):
            ans+=lst[i]*lst[j]*lst[k]

print(ans)

Submission status: Accepted

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

dic={}
for i in s:
    if i[0]=='M' or i[0]=='A' or i[0]=='R' or i[0]=='C' or i[0]=='H':
        if i[0] in dic:
            dic[i[0]]+=1
        else:
            dic[i[0]]=1
if len(dic)<3:
    ans=0
else:
    if len(dic)==3:
        ans = 1
        for i in dic.values():
            ans *=i
    elif len(dic)==4:
        li4 = []
        for i in dic.values():
            li4.append(i)
        ans = li4[0]*li4[1]*li4[2]+li4[0]*li4[1]*li4[3]+li4[0]*li4[2]*li4[3]+li4[1]*li4[2]*li4[3]
    else:
        li5 = []
        for i in dic.values():
            li5.append(i)
        ans =li5[0]*li5[1]*li5[2]+li5[0]*li5[1]*li5[3]+li5[0]*li5[1]*li5[4]+li5[0]*li5[2]*li5[3]+li5[0]*li5[2]*li5[4]+li5[0]*li5[3]*li5[4]+li5[1]*li5[2]*li5[3]+li5[1]*li5[2]*li5[4]+li5[1]*li5[3]*li5[4]+li5[2]*li5[3]*li5[4]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def solve():
  n = int(input())
  s = [input() for _ in range(n)]
  march = [0]*5
  for i in range(n):
    if s[i][0] == "M":
      march[0] += 1
    elif s[i][0] == "A":
      march[1] += 1
    elif s[i][0] == "R":
      march[2] += 1
    elif s[i][0] == "C":
      march[3] += 1
    elif s[i][0] == "H":
      march[4] += 1
  ans = 0
  for i in range(3):
    for j in range(3):
      for k in range(3):
        if i < j+1 and j<k+1:
          ans += march[i]*march[j+1]*march[k+2]
  print(ans)
solve()

Submission status: Accepted

Solution code:
n = int(input())
s = [input() for _ in range(n)]
s = [t[0] for t in s if t[0] in 'MARCH']
d = {}
for t in s:
  if t in d:
    d[t] += 1
  else:
    d[t] = 1
l = list(d.keys())
result = 0
for i in range(len(l) - 2):
  for j in range(i + 1, len(l) - 1):
    for k in range(j + 1, len(l)):
      result += d[l[i]] * d[l[j]] * d[l[k]]
print(result)

Submission status: Accepted

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

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""
# それぞれの単語数をカウントしておく
# 全探索で組み合わせ数が分かるはず

N = int(sys.stdin.readline())

target = {"M":0,"A":0,"R":0,"C":0,"H":0}
cnt = 0
for i in range(N):
    s = list(sys.stdin.readline().rstrip())
    if s[0] in target.keys():
        target[s[0]] += 1

k = list(target.keys())
ans = 0
for i in range(3):
    for j in range(i + 1, 5):
        for h in range(j + 1, 5):
            ans += target[k[i]] * target[k[j]] * target[k[h]]

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
count = [0] * 5
c = "MARCH"

for i in range(N):
    s = input()
    for j in range(5):
        if s[0] == c[j]:
            count[j] += 1
            break

ind = []
for i in range(5):
    if count[i] > 0:
        ind.append(count[i])

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

Submission status: Accepted

Solution code:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

import itertools

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

# MARCH
C = [0] * 5
for s in S:
    i = -1
    if s[0] == 'M': i = 0
    if s[0] == 'A': i = 1
    if s[0] == 'R': i = 2
    if s[0] == 'C': i = 3
    if s[0] == 'H': i = 4

    if i > -1:
        C[i] += 1

count = 0
for x in itertools.combinations("01234", 3):
    (a, b, c) = map(int, x)
    count += C[a]*C[b]*C[c]
#    print(x, count, C)

print(count)

Submission status: Accepted

Solution code:
import itertools

n = int(input())

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

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

l = list(d.keys())
comb = list(itertools.combinations(l, 3))

ans = 0
for i in comb:
    temp = 1
    for j in i:
        temp *= d[j]

    ans += temp

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=[input() for i in range(n)]
cnt1,cnt2,cnt3,cnt4,cnt5=0,0,0,0,0
for i in s:
    if i[0]=='M':
        cnt1+=1
    elif i[0]=='A':
        cnt2+=1
    elif i[0]=='R':
        cnt3+=1
    elif i[0]=='C':
        cnt4+=1
    elif i[0]=='H':
        cnt5+=1
print(cnt1*cnt2*cnt3+cnt1*cnt2*cnt4+cnt1*cnt2*cnt5+cnt1*cnt3*cnt4+cnt1*cnt3*cnt5+cnt1*cnt4*cnt5+cnt2*cnt3*cnt4+cnt2*cnt3*cnt5+cnt2*cnt4*cnt5+cnt3*cnt4*cnt5)

Submission status: Accepted

Solution code:
import fractions
import itertools
N = int(input())
M =[]
A = []
R = []
C = []
H = []


for i in range(N):
    name = input()
    initial = name[0]
    if initial == "M":
        M.append(name)
    elif initial == "A":
        A.append(name)
    elif initial == "R":
        R.append(name)
    elif initial == "C":
        C.append(name)
    elif initial == "H":
        H.append(name)

count = 0
S = []
if len(M) > 0:
    S.append(len(M))
if len(A) > 0:
    S.append(len(A))
if len(R) > 0:
    S.append(len(R))
if len(C) > 0:
    S.append(len(C))
if len(H) > 0:
    S.append(len(H))

if len(S) < 3:
    print("0")
    exit(0)

a = itertools.combinations(S,3)
ans = 0
for x in list(a):
    tmp = 1
    for y in x:
        tmp *= y
    ans += tmp
print(ans)

Submission status: Accepted

Solution code:
a=int(input())
lis=[input()[0] for i in range(a)]
lis2=[0,0,0,0,0]
dellist=[]
for m in lis:
  if m=="M":
    lis2[0]+=1
  elif m=="A":
    lis2[1]+=1
  elif m=="R":
    lis2[2]+=1
  elif m=="C":
    lis2[3]+=1
  elif m=="H":
    lis2[4]+=1
a=sum(lis2)
def c3(a):
  return a*(a-1)*(a-2)/6
def c2(a):
  return  a*(a-1)/2
ans=c3(a)
for i in lis2:
  ans=ans-c3(i)-c2(i)*(a-i)
print(int(ans))

Submission status: Accepted

Solution code:
from itertools import*;N,*S=open(0);print(sum(a*b*c for a,b,c in combinations([sum(1for s in S if s[0]==c)for c in"MARCH"],3)))

Submission status: Accepted

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

M = len([S[i] for i in range(N) if S[i][0] == "M"])
A = len([S[i] for i in range(N) if S[i][0] == "A"])
R = len([S[i] for i in range(N) if S[i][0] == "R"])
C = len([S[i] for i in range(N) if S[i][0] == "C"])
H = len([S[i] for i in range(N) if S[i][0] == "H"])

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

Submission status: Accepted

Solution code:
def slove():
    import sys, collections, itertools
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    name = [str(input().rstrip('\n'))[0] for _ in range(n)]
    name = collections.Counter(name)
    name = dict(name.items())
    ls = list("MARCH")
    t = 0
    for i in itertools.combinations(ls, 3):
        if i[0] in name and i[1] in name and i[2] in name:
            t += (name[i[0]] * name[i[1]] * name[i[2]])
    print(t)


if __name__ == '__main__':
    slove()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

from itertools import combinations

N = I()
S = ['0']*N
x = [0]*5
for i in range(N):
    S[i] = str(input())
    if S[i].startswith('M'):
        x[0] += 1
    elif S[i].startswith('A'):
        x[1] += 1
    elif S[i].startswith('R'):
        x[2] += 1
    elif S[i].startswith('C'):
        x[3] += 1
    elif S[i].startswith('H'):
        x[4] += 1

ans = 0
A = list(combinations(range(5),3))
for a in A:
    ans += x[a[0]]*x[a[1]]*x[a[2]]

print(ans)

Submission status: Accepted

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

import operator

GOOD_LETTERS = "MARCH"
PEOPLE = 3

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

for _ in range(n):
  first = input()[0]
  if first in GOOD_LETTERS:
    c.update(first)

ways = 0
for tup in combinations(GOOD_LETTERS, PEOPLE):
  ways += reduce(operator.mul, [c[ch] for ch in tup], 1)

print(ways)

Submission status: Accepted

Solution code:
import sys
from statistics import *
from collections import *
from operator import itemgetter
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
ct = 0
cap = ["M", "A", "R", "C", "H"]
ct = [0] * 5
for i in range(n):
    s = input()
    for i in range(5):
        if s[0] == cap[i]:
            ct[i] += 1
ans = 0
for a in range(5):
    for b in range(a+1, 5):
        for c in range(b+1, 5):
            ans += ct[a] * ct[b] * ct[c]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections
import itertools
ok = ['M', 'A', 'R', 'C', 'H']
n = int(input())
d = collections.defaultdict(int)
for _ in range(n):
    s = input()
    if any([s[0] == x for x in ok]): d[s[0]] += 1
p = [a for a in itertools.combinations(ok, 3) if all([x in d for x in a])]
ans = 0
for a, b, c in p:
    ans += d[a] * d[b] * d[c]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
nM = 0
nA = 0
nR = 0
nC = 0
nH = 0
for i in range(N):
  S = input()
  if S[0] == "M": nM += 1
  if S[0] == "A": nA += 1
  if S[0] == "R": nR += 1
  if S[0] == "C": nC += 1
  if S[0] == "H": nH += 1
r = 0
r += nM*nA*nR
r += nM*nA*nC
r += nM*nA*nH
r += nM*nR*nC
r += nM*nR*nH
r += nM*nC*nH
r += nA*nR*nC
r += nA*nR*nH
r += nA*nC*nH
r += nR*nC*nH
print(r)

Submission status: Accepted

Solution code:
n = int(input())
groups = [0] * 5
for _ in range(n):
    s = input()
    if s[0] == "M":
        groups[0] += 1
    elif s[0] == "A":
        groups[1] += 1
    elif s[0] == "R":
        groups[2] += 1
    elif s[0] == "C":
        groups[3] += 1
    elif s[0] == "H":
        groups[4] += 1
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 += groups[i] * groups[j] * groups[k]
print(ans//6)

Submission status: Accepted

Solution code:
n = int(input())
s = [input() for i in range(n)]
m = 0
a = 0
r = 0
c = 0
h = 0
for j in range(n):
    if s[j][0] == "M":
        m += 1
    elif s[j][0] == "A":
        a += 1
    elif s[j][0] == "R":
        r += 1
    elif s[j][0] == "C":
        c += 1
    elif s[j][0] == "H":
        h += 1
print(m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h)

Submission status: Accepted

Solution code:
n = int(input())
d = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
ans = 0
for i in range(n):
    s = input()
    if s[0] in d:
        d[s[0]] += 1
va = list(d.values())
v = len(va)

for i in range(v):
    for j in range(i+1,v):
        for k in range(j+1,v):
            ans += va[i]*va[j]*va[k]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
d = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
va = []
ans = 0
for i in range(n):
    s = input()
    if s[0] in d:
        d[s[0]] += 1
for i in d:
    if d[i] > 0:
        va.append(d[i])
v = len(va)

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

Submission status: Accepted

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

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

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
from itertools import combinations

counter = Counter()

n = int(input())
for _ in range(n):
    line = input()
    if line[0] in "MARCH":
        counter[line[0]] += 1

ans = 0
for a, b, c in combinations("MARCH", 3):
    c = counter[a] * counter[b] * counter[c]
    ans += c

print(ans)

Submission status: Accepted

Solution code:
import itertools
import collections

n = int(input().split()[0])
s_list = []

for _ in range(n):
    s = input().split()[0]
    s_list.append(s)

target_list = [s[0] for s in s_list if s[0] in list('MARCH')]
counter = collections.Counter(target_list)
c = 0

if len(set(target_list)) < 3:
    ans = 0
else:
    p_list = itertools.combinations(set(target_list), 3)

    for p in p_list:
        c += counter[p[0]] * counter[p[1]] * counter[p[2]]
    ans = c
print(c)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())

counter = Counter()
for _ in range(N):
    s = input()[0]
    if s in ('MARCH'):
        counter[s] += 1
if len(counter) < 3:
    print(0)
    exit()

import itertools

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

Submission status: Accepted

Solution code:
from collections import defaultdict
import itertools


def resolve():
    n = int(input())
    d = defaultdict(int)
    for _ in range(n):
        d[input()[0]] += 1
    print(sum([d[c1] * d[c2] * d[c3] for c1, c2, c3 in itertools.combinations(["M", "A", "R", "C", "H"], 3)]))


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
from collections import defaultdict
import itertools


def resolve():
    n = int(input())
    d = defaultdict(int)
    for _ in range(n):
        s = input()
        d[s[0]] += 1
    print(sum([d[c1] * d[c2] * d[c3] for c1, c2, c3 in itertools.combinations(["M", "A", "R", "C", "H"], 3)]))


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
from collections import defaultdict
import itertools


def resolve():
    n = int(input())
    d = defaultdict(list)
    for _ in range(n):
        s = input()
        d[s[0]].append(s)
    print(sum([len(d[c1]) * len(d[c2]) * len(d[c3]) for c1, c2, c3 in itertools.combinations(["M", "A", "R", "C", "H"], 3)]))


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
import itertools

first = {"M":0, "A":0, "R":0, "C":0, "H":0}
n = int(input())
s = [input() for i in range(n)]
for j in s:
    if j[0] in first:
        first[j[0]] += 1
    else:
        first[j[0]] = 1
ll = [[1,1,1,0,0],[1,1,0,1,0],[1,1,0,0,1],[1,0,1,1,0],[1,0,1,0,1],[1,0,0,1,1],[0,1,1,1,0],\
    [0,1,0,1,1],[0,1,1,0,1],[0,0,1,1,1]]

ans =0
for k in range(10):
    num = []
    if ll[k][0] == 1:
        num.append(first["M"])
    if ll[k][1] == 1:
        num.append(first["A"])
    if ll[k][2] == 1:
        num.append(first["R"])
    if ll[k][3] == 1:
        num.append(first["C"])
    if ll[k][4] == 1:
        num.append(first["H"])
    st = 1
    for m in num:
        st *= m
    ans += st
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

m = [name for name in s if name[0] == "M"]
a = [name for name in s if name[0] == "A"]
r = [name for name in s if name[0] == "R"]
c = [name for name in s if name[0] == "C"]
h = [name for name in s if name[0] == "H"]

march = [len(m),len(a),len(r),len(c),len(h)]
march = [i for i in march if i!= 0]

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

result = 0
for i in range(len(march)):
  for j in range(len(march)):
    for k in range(len(march)):
      if i != j and j != k and k != i:
        result += march[i]*march[j]*march[k]

print(int(result/6))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools

N = int(input())
d = {}

for i in range(N):
    tmp = list(input())
    k = tmp[0]
    if k in 'MARCH':
        if k in d:
            d[k] += 1
        else:
            d[k] = 1

l = len(d)
ans = 0
key = d.keys()

if l >= 3:
    for a in itertools.combinations(key,3):
        ans += d[a[0]] * d[a[1]] * d[a[2]]

print(ans)

Submission status: Accepted

Solution code:
import itertools

n = int(input())
count_m = 0
count_a = 0
count_r = 0
count_c = 0
count_h = 0
sum = 0


for i in range(n):
    a = input()
    if a[0] == 'A':
        count_a += 1
    elif a[0] == 'C':
        count_c += 1
    elif a[0] == 'H':
        count_h += 1
    elif a[0] == 'M':
        count_m += 1
    elif a[0] == 'R':
        count_r += 1

l = [count_m, count_a, count_r, count_c, count_h]
c = itertools.combinations(l, 3)

for f, j, k in c:
    sum += f*j*k

print(sum)