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())
S = []
for i in range(N):
    S.append(input())
r = ["M","A","R","C","H"]
x = dict()
#O(N)
for i in range(N):
    if S[i][0] not in r:
        continue
    if S[i][0] in x:
        x[S[i][0]] += 1
    else:
        x[S[i][0]] = 1

l = []
num = 0
#O(26)
for idx in x:
    l.append(x[idx])

n = len(l)
ans = 0
if n<=2:
    print(0)
    exit()
#O(26)
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            ans += l[i]*l[j]*l[k]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

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

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]

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

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

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
from itertools import combinations
import numpy as np
n=int(input())
L=[]
for i in range(n):
    w=input()
    L.append(w[0])
CNT=Counter(L)
m=CNT['M']
a=CNT['A']
r=CNT['R']
c=CNT['C']
h=CNT['H']
comb=combinations([m,a,r,c,h], 3)
ans=0
for kumi in comb:
    ans+=np.prod(kumi)
print(ans)

Submission status: Accepted

Solution code:
import itertools

def solve(n, S):
    initials = ('M', 'A', 'R', 'C', 'H')
    d = {}
    for s in S:
        if s[0] in initials:
            d[s[0]] = d.get(s[0], 0) + 1
    return sum(d[x] * d[y] * d[z] for x, y, z in itertools.combinations(d.keys(), 3))

_n = int(input())
_S = [input() for _ in range(_n)]
print(solve(_n, _S))

Submission status: Accepted

Solution code:
n = int(input())
l = [0]*5
for i in range(n):
    a = input()
    if a[0] == "M":
        l[0] += 1
    elif a[0] == "A":
        l[1] += 1
    elif a[0] == "R":
        l[2] += 1
    elif a[0] == "C":
        l[3] += 1
    elif a[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:
n = int(input())
data = {'M':0 , 'A':0 , 'R':0 , 'C':0 , 'H':0 }
for i in range(n):
  s = input()
  if(s[0] == 'M'):
    data['M'] += 1
  if(s[0] == 'A'):
    data['A'] += 1
  if(s[0] == 'R'):
    data['R'] += 1
  if(s[0] == 'C'):
    data['C'] += 1
  if(s[0] == 'H'):
    data['H'] += 1
Data = sorted(data.values())
ans = 0
for i in range(0,5):
  for j in range(i+1,5):
    for k in range(j+1,5):
      ans += Data[i]*Data[j]*Data[k]
      
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
from itertools import combinations

n=int(input())
s=[input() for i in range(n)]
name=['M','A','R','C','H']

cnt=defaultdict(lambda:0)
for i in range(n):
    if s[i][0] in name:
        cnt[s[i][0]]+=1

cnt=cnt.values()
if len(cnt)<3:
    print(0)
    exit()
ans=0

# listから２つ選ぶ組み合わせ
for x,y,z in combinations(cnt,3):
    ans+=x*y*z

print(ans)

Submission status: Accepted

Solution code:
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
  elif i[0]=='A':
    A+=1
  elif i[0]=='R':
    R+=1
  elif i[0]=='C':
    C+=1
  elif i[0]=='H':
    H+=1
ans=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
print(ans)

Submission status: Accepted

Solution code:
import itertools
N=int(input())
S=list(str(input()) for i in range(N))
m,a,r,c,h=[0]*5
ans=0
for i in range(len(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

x=[m,a,r,c,h]
for i in itertools.combinations(x,3):
  ans+=i[0]*i[1]*i[2]
print(ans)

Submission status: Accepted

Solution code:
import itertools

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

Submission status: Accepted

Solution code:
n=int(input())
m,a,r,c,h=0,0,0,0,0
for i in range(n):
  x=input()[0]
  if x=="M":
    m+=1
  elif x=="A":
    a+=1
  elif x=="R":
    r+=1
  elif x=="C":
    c+=1
  elif x=="H":
    h+=1
s=[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]
print(sum(s))

Submission status: Accepted

Solution code:
from collections import Counter
from itertools import combinations
N=int(input())
S=[input()[0] for i in range(N)]
S=Counter(S)
h=combinations(['M','A','R','C','H'],3)
h_dic={'M':0,'A':0,'R':0,'C':0,'H':0}
ans = 0
for key,value in S.items():
    if key in h_dic:
        h_dic[key] = value

for i in h:
    tmp = 1
    for j in i:
        tmp *= h_dic[j]
    ans += tmp
print(ans)

Submission status: Accepted

Solution code:
import itertools
import numpy as np
n = int(input())

names = {}
for i in range(n):
    initial = input()[0]
    names[initial] = names.get(initial, 0) + 1

print(np.sum(np.prod(pattern) for pattern in itertools.combinations([names.get(v, 0) for v in 'MARCH'], r=3)))

Submission status: Accepted

Solution code:
# WIP
from itertools import combinations

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

# Filter1
filter_1 = {'M', 'A', 'R', 'C', 'H'}
canditates = [S for S in SSS if S[0] in filter_1]
cand_inits = [c[0] for c in canditates]
cand_inits_set = set(cand_inits)
init_counts = {init_c: cand_inits.count(init_c) for init_c in filter_1}

n_combi = 0
for init_combi in combinations(cand_inits_set, 3):
    tmp_combi = 1
    for init_c in init_combi:
        tmp_combi *= init_counts[init_c]

    n_combi += tmp_combi

print(n_combi)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]

class Util():
    def round_up(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Util.round_up(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x

N = cin.int()
S = cin.stringList(N)
A = [0] * 5
for key,value in itertools.groupby(sorted(S),key = lambda x : x[0]):
    if key in "MARCH":
        A["MARCH".index(key)] = len(list(value))
ans = 0        
for p in itertools.combinations(range(5),3):
    ans += A[p[0]] * A[p[1]] * A[p[2]]
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
import itertools
N = int(input())
dic = defaultdict(int)
for i in range(N):
    S = input()[0]
    dic[S] += 1
lis = itertools.combinations(["M","A","R","C","H"],3)
ans = 0
for a,b,c in lis:
    ans += dic[a]*dic[b]*dic[c]
print(ans)

Submission status: Accepted

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

d = defaultdict(int)
for name in names:
    tmp = name[0]
    if tmp in 'MARCH':
        d[tmp] += 1

keys = d.keys()
if len(keys) < 3:
    print(0)
else:
    cnt = 0
    for a, b, c in combinations(keys, 3):
        cnt += d[a] * d[b] * d[c]
    print(cnt)

Submission status: Accepted

Solution code:
from functools import reduce
from operator import mul
from itertools import combinations

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

march = ['M', 'A', 'R', 'C', 'H']

c = [ss.count(x) for x in march]
combi = list(combinations(c, 3))

print(sum([reduce(mul, x) for x in combi]))

Submission status: Accepted

Solution code:
import itertools
N = int(input())
M = {'M':0,'A':0,'R':0,'C':0,'H':0}
for _ in range(N):
    s = input()
    if M.get(s[0]) != None:
        M[s[0]] += 1
X = [M[key] for key in M.keys()]
Z = [i for i in range(5)]
Y = list(itertools.combinations(Z,r=3))
ans = 0
for i in Y:
    tmp = 1
    for j in i:
        tmp *= X[j]
    ans += tmp
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

M = []
A = []
R = []
C = []
H = []
for _ in range(N):
  s = input()
  if s[0] == 'M':
    M.append(s)
  if s[0] == 'A':
    A.append(s)
  if s[0] == 'R':
    R.append(s)
  if s[0] == 'C':
    C.append(s)
  if s[0] == 'H':
    H.append(s)
m_len = len(M)
a_len = len(A)
r_len = len(R)
c_len = len(C)
h_len = len(H)
ans = 0
ans += m_len * a_len * r_len
ans += m_len * a_len * c_len
ans += m_len * a_len * h_len
ans += m_len * r_len * c_len
ans += m_len * r_len * h_len
ans += m_len * c_len * h_len
ans += a_len * r_len * c_len
ans += a_len * r_len * h_len
ans += a_len * c_len * h_len
ans += r_len * c_len * h_len

print(ans)

Submission status: Accepted

Solution code:
import sys
import collections
import itertools

input = sys.stdin.readline


def main():
    N = int(input())
    C = collections.Counter()
    for _ in range(N):
        S = input().strip()
        C[S[0]] += 1

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

    print(ans)



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter
import itertools
n = int(input()) 
l = [input()[0] for _ in range(n)]
l = [i for i in l if i in {'M','A','R','C','H'}]

if len(l) < 3:
    print(0)
else:
    c = Counter(l)
    cl = list(itertools.combinations(c,3))
    ans = 0
    for i in cl:
        ans += c[i[0]] * c[i[1]] * c[i[2]]
    print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import itertools
N=int(input())
A=[[]]*5
L=['M','A','R','C','H']

C=[0]*5

for i in range(N):
    name=input()
    if name[0] in L:
        C[L.index(name[0])]+=1

n=0
ans=0
for i in range(5):
    if C[i]!=0:
        n+=1
        
if n<3:
    print(0)
else:
    C_=[]
    for i in range(5):
        if C[i]!=0:
            C_.append(C[i])
    #print(C_)
    #c = itertools.combinations(C, 3)
    #print(list(c)[0])
    l=len(C_)
    
    for i in range(l-2):
        for j in range(i+1,l-1):
            for k in range(j+1,l):
                
                #print(i,j,k)
                m=C_[i]*C_[j]*C_[k]
                ans+=m
                m=0
    print(ans)

Submission status: Accepted

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

for _ in range(n):
    t = input()
    for i in range(5):
        if t[0] == s[i]:
            m[i] += 1

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

print(ans)

Submission status: Accepted

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

ans=0
ans+=(m*a*r)
ans+=(m*a*c)
ans+=(m*a*h)
ans+=(m*c*r)
ans+=(m*h*r)
ans+=(m*c*h)
ans+=(a*r*c)
ans+=(a*r*h)
ans+=(a*c*h)
ans+=(r*c*h)
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations

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

march = ["M", "A", "R", "C", "H"]
d = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
cnt = 0
for i in range(N):
    if Sn[i][0] not in march:
        continue
    d[Sn[i][0]] += 1
    cnt += 1

ans = 0
for a, b, c in combinations(march, 3):
    ans += d[a] * d[b] * d[c]

print(ans)

Submission status: Accepted

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

ls_cn = [0] * 5

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

x = 0

for j in range(2**5):
    ls_mul = []
    for k in range(n):
        if ((j >> k) & 1):
            ls_mul.append(ls_cn[k])
    
    if len(ls_mul) == 3:
        x += ls_mul[0] * ls_mul[1] * ls_mul[2]

print(x)

Submission status: Accepted

Solution code:
from collections import Counter
from itertools import combinations
S = [input()for _ in range(int(input()))]
C = Counter(s[0] for s in S)
march = [s for s in "MARCH" if s in C]
ans = 0
for p in combinations(march, 3):
    ans += C[p[0]]*C[p[1]]*C[p[2]]
print(ans)

Submission status: Accepted

Solution code:
import functools
import itertools
import operator

required_char = 'MARCH'
N = int(input())
name_counter = {s: 0 for s in required_char}
for _ in range(N):
    S = input()
    if S[0] in required_char:
        name_counter[S[0]] += 1
ans = 0
for cmb in itertools.combinations(name_counter.values(), 3):
    ans += functools.reduce(operator.mul, cmb)
print(ans)

Submission status: Accepted

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

cont_M = 0
cont_A = 0
cont_R = 0
cont_C = 0
cont_H = 0

for i in range(N):
    if A[i][0][0] =='M':
        cont_M += 1
    elif A[i][0][0] =='A':   
        cont_A += 1
    elif A[i][0][0] =='R':   
        cont_R += 1
    elif A[i][0][0] =='C': 
        cont_C += 1
    elif A[i][0][0] =='H': 
        cont_H += 1
B = [cont_M , cont_A , cont_R , cont_C , cont_H ]

#Mで始まる人の人数 x Aで始まる人の人数 x Rで始まる人の人数 これを全ての仮定パターン（5C3の通り)の組み合わせの和を求める。

import itertools

c = list(itertools.combinations(B, 3))

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

Submission status: Accepted

Solution code:
import sys

if sys.platform =='ios':
	sys.stdin=open('input_file.txt')
	
#+++++
import itertools
n=int(input())
a={}
for _ in range(n):
	s=input().strip()
	t=a.get(s[0], 0)
	a[s[0]]=t+1

ans=0
for x,y,z in itertools.combinations(list('MARCH'), 3):
	ans+=a.get(x, 0)*a.get(y, 0)*a.get(z, 0)
	
print(ans)

Submission status: Accepted

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

lst1 = [0]*5
lst2 = [ "M","A","R","C","H" ]
for i in range(n):
    s = input()
    for j in range(5):
        if s[0] == lst2[j]:
            lst1[j] += 1
            break
    
l = (itertools.combinations(lst1,3))
ans = 0
for i in l:
    ans += i[0]*i[1]*i[2]
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
import itertools

march = set('MARCH')
count = defaultdict(int)
n = int(input())
for _ in range(n):
    name = input()
    if name[0] in march:
        count[name[0]] += 1


num_of_people = []
for s in 'MARCH':
    num_of_people.append(count[s])


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

print(ans)

Submission status: Accepted

Solution code:
import itertools
N=int(input())
S=[list(input()) for _ in range(N)]
d={'M':0,'A':1,'R':2,'C':3,'H':4}
a=[0]*5
l=set('MARCH')
for s in S:
    if s[0] in l:
        a[d[s[0]]]+=1
for i in reversed(range(5)):
    if a[i]==0:
        del a[i]
X=list(itertools.combinations(a,3))
len_x=len(X)
ans=0
def f(ary,i):
    if i==0:
        return ary[i]
    return ary[i]*f(ary,i-1)
for x in X:
    ans+=f(x,2)
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
m=0
a=0
r=0
c=0
h=0
for _ 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
ans=0
ans+=m*a*r
ans+=m*a*c
ans+=m*a*h
ans+=m*r*c
ans+=m*r*h
ans+=m*c*h
ans+=a*r*c
ans+=a*r*h
ans+=a*c*h
ans+=r*c*h
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
dic = dict(zip(list("MARCH"),[0]*len("MARCH")))
N = int(input())
for i in range(N):
    tmp = input()[0]
    if tmp in "MARCH":
        dic[tmp] += 1
c = combinations(list("MARCH"),3)
ans = 0
for i in c:
    ans += dic[i[0]]*dic[i[1]]*dic[i[2]]
print(ans)

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 i in s:
  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

nan=0
li=[m,a,r,c,h]

for i in li:
  if i>0:
    nan+=1

import itertools

if nan<3:
  print(0)
else:
  ans=0
  for x,y,z in itertools.combinations(range(5),3):
    ans+=li[x]*li[y]*li[z]
  print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=[list(input())for i in range(n)]
d={'M':0,"A":0,"R":0,'C':0,'H':0}
for i in a:
    if i[0] in d:
        d[i[0]]+=1
dl=[]
for i in d.values():
    dl.append(i)
ans=0
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            ans+=dl[i]*dl[j]*dl[k]
print(ans)

Submission status: Accepted

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

ite=itertools.combinations("MARCH",3)
print(sum([data[a]*data[b]*data[c] for a,b,c in ite]))

Submission status: Accepted

Solution code:
from collections import defaultdict
from itertools import combinations

N = int(input())
S = [input()[0] for _ in range(N)]
dic_S = defaultdict(int)
for s in S:
  if s in "MARCH":
    dic_S[s] += 1

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

Submission status: Accepted

Solution code:
N= int(input())
S = ['M','A','R','C','H']
C = [0]*5
for _ in range(N):
  X = (input())[0]
  if X in S:
    C[S.index(X)] += 1
from itertools import permutations, combinations,combinations_with_replacement,product
L = list(combinations(range(5), 3))   #nCr
ans = 0
for i in L:
  ans += C[i[0]]*C[i[1]]*C[i[2]]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n=int(input())
S=[input().strip() for _ in range(n)]
a=[]

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


from collections import Counter
for s in S:
    if s[0] in ["M","A","R","C","H"]:
        a.append(s[0])

if len(a)<=2:
    print(0)
    exit()

a=Counter(a)
#print(a)

asum=sum(a.values())
b=0
c=0
for i in a.values():
    if i ==1:
        continue
    if i==2:
        b+=asum-i
    if i>=3:
        b+=cmb(i,2)*(asum-i)
        c+=cmb(i,3)
print(cmb(asum,3)-b-c)

Submission status: Accepted

Solution code:
N = int(input())
k = [0]*5
ans = 0
for i in range(N):
  S = input()
  if S[0] == "M":
    k[0] += 1
  elif S[0] == "A":
    k[1] += 1
  elif S[0] == "R":
    k[2] += 1
  elif S[0] == "C":
    k[3] += 1
  elif S[0] == "H":
    k[4] += 1
  else:
    continue
ans += k[0]*k[1]*k[2]
ans += k[0]*k[1]*k[3]
ans += k[0]*k[1]*k[4]
ans += k[0]*k[2]*k[3]
ans += k[0]*k[2]*k[4]
ans += k[0]*k[3]*k[4]
ans += k[1]*k[2]*k[3]
ans += k[1]*k[2]*k[4]
ans += k[1]*k[3]*k[4]
ans += k[2]*k[3]*k[4]
print(ans)

Submission status: Accepted

Solution code:
import itertools as it

N = int(input())
march = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for i in range(N):
    ini = input()[0]
    if ini in march:
        march[ini] += 1
ans = 0
for i, j, k in it.combinations("MARCH", 3):
    ans += march[i] * march[j] * march[k]
print(ans)

Submission status: Accepted

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

ans=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
print(ans)

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()
  if S[0] in D:
    D[S[0]] += 1
L1 = [D[i] for i in D]
M = 0
for i in range(3):
  for j in range(i+1, 4):
    for k in range(j+1, 5):
      M += L1[i]*L1[j]*L1[k]
print(M)

Submission status: Accepted

Solution code:
from itertools import combinations

N = int(input())
name=[]
m,a,r,c,h=0,0,0,0,0
for i in range(N):
    si = input()
    if si[0] in ['M', 'A', 'R', 'C', 'H']:
        name.append(si)
        if si[0]=='M':
            m+=1
        if si[0]=='A':
            a+=1
        if si[0]=='R':
            r+=1
        if si[0]=='C':
            c+=1
        if si[0]=='H':
            h+=1

if name==[]:
    print(0)
    exit()

names=dict({'m':m,'a':a,'r':r,'c':c,'h':h})
ans=0
for n in list(combinations(['m','a','r','c','h'],3)):
    ans += names[n[0]] * names[n[1]] * names[n[2]]
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=[]
for i in range(n):
    s.append(input())
march_dict={"M":0,"A":1,"R":2,"C":3,"H":4}
march_list=[0,0,0,0,0]
for i in range(n):
    if s[i][0] in march_dict:
        march_list[march_dict[s[i][0]]]+=1
ans=0
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            ans+=march_list[i]*march_list[j]*march_list[k]
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
from collections import Counter

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

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

print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations

n = int(input())
d = [0] * 5

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

d = [n for n in d if n !=0]

comb = combinations(d, 3)
ans = 0
for c in comb:
    ans += c[0]*c[1]*c[2]

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from itertools import product

def solve(N: int, S: "List[str]"):
    answer = 0
    march_dict = {'M':0,'A':0,'R':0,'C':0,'H':0}
    for i in range(N):
        if march_dict.get(S[i][0]) != None:
            march_dict[S[i][0]] += 1
    values = list(march_dict.values())
    bit_list = product([0,1],repeat=5)

    for bit in bit_list:
        if bit.count(1) == 3:
            a = 1
            for i in range(5):
                if bit[i] == 1:
                    a *= values[i]
            answer += a

    print(answer)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = [next(tokens) for _ in range(N)]  # type: "List[str]"
    solve(N, S)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
d = {'M': 0, "A": 0, "R": 0, "C": 0, "H": 0}
for _ in range(N):
    try:
        d[input()[0]] += 1
    except KeyError:
        pass

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

Submission status: Accepted

Solution code:
n = int(input())
s = [input() for i in range(n)]
dic = {'M':0,'A':1,'R':2,'C':3,'H':4}
ar = [0, 0, 0, 0, 0]
for i in s:
    if i[0] not in dic:
        continue
    ar[dic[i[0]]]+=1
dp = [[0 for i in range(6)] for j in range(6)]
dp[0][0] = 1
for i in range(1, 6):
    for j in range(6):
        dp[i][j] = dp[i-1][j]
        if j==0:
            continue
        dp[i][j] += dp[i-1][j-1]*ar[i-1]
print(dp[5][3])

Submission status: Accepted

Solution code:
n = int(input())
s = [input() for i in range(n)]
lst = ["M","A","R","C","H"]
dct = {c:0 for c in lst}
ans = 0

for name in s:
    if name[0] in dct:
        dct[name[0]] += 1

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

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
name=[]
for i in range(n):
    name.append(input().split(" "))
m, a, r, c, h=0, 0, 0, 0, 0
for w in range(n):
    if name[w][0][0]=='M':
        m+=1
    if name[w][0][0]=='A':
        a+=1
    if name[w][0][0]=='R':
        r+=1
    if name[w][0][0]=='C':
        c+=1
    if name[w][0][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:
from itertools import combinations

capital = ['M', 'A', 'R', 'C', 'H']
count = [0 for i in range(5)]

N = int(input())

for i in range(N):
  name = input()
  init = name[0]
  for i, c in enumerate(capital):
    if init == c:
      count[i] += 1
    
ret = 0
for comb in combinations(count, 3):
  ret += comb[0] * comb[1] * comb[2]
  
print(ret)

Submission status: Accepted

Solution code:
from itertools import combinations

# from scipy.special import comb
import sys

n = int(input())
march = ["M", "A", "R", "C", "H"]
num_mar = {}
# num_mar = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
s = []
for i in range(n):
    t = input()
    if t[0] not in march:
        continue
    s.append(t)
    if t[0] not in num_mar.keys():
        num_mar[t[0]] = 1
    else:
        num_mar[t[0]] += 1

# print(num_mar, s)

len_num_mar = len(num_mar.keys())
# print(len_num_mar)


if len_num_mar < 3:
    print(0)
    sys.exit()

# first_pick = comb(len_num_mar, 3, exact=True)
# ans = first_pick
ans = 0

for keys in combinations(num_mar.keys(), 3):
    res = 1
    for k in keys:
        res *= num_mar[k]
    ans += res


# for k in num_mar.keys():
#     ans *= num_mar[k]
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
n=int(input())
c=["M","A","R","C","H"]
d=defaultdict(int, {})
ans=0
for _ in range(n):
  s=input()
  d[s[0]]+=1
for i in range(len(c)):
  for j in range(i+1,len(c)):
    for k in range(j+1,len(c)):
      ans+=d[c[i]]*d[c[j]]*d[c[k]]
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
M=['M','A','R','C','H']
S = {'M':0,'A':0,'R':0,'C':0,'H':0}
for _ in range(n):
  a = input()
  if a[0] in S:
  	S[a[0]] +=1
ANS=0
for i in range(len(M)):
  for j in range(i+1,len(M)):
    for k in range(j+1,len(M)):
      ANS += (S[M[i]] * S[M[j]]* S[M[k]])
print(ANS)

Submission status: Accepted

Solution code:
def main():
    n=int(input())
    S=list(input() for _ in range(n))
    a,b,c,d,e=0,0,0,0,0
    for s in S:
        if s[0]=="M": a += 1
        if s[0]=="A": b += 1
        if s[0]=="R": c += 1
        if s[0]=="C": d += 1
        if s[0]=="H": e += 1
    print(c*(a+b)*(d+e)+a*b*(c+d+e)+d*e*(a+b+c))
main()

Submission status: Accepted

Solution code:
import itertools
from operator import mul
from functools import reduce
heads = ["M","A","R","C","H"]

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

for i in range(N):
  s = input()[0]
  if s in heads:
    n = heads.index(s)
    S[n] += 1

S = [i for i in S if i != 0]

nums = list(itertools.combinations(S,3))

total = 0

for list in nums:
  total += reduce(mul,list)

print(total)

Submission status: Accepted

Solution code:
N = int(input())
c, MARCH = [0] * 5, ["M", "A", "R", "C", "H"]
for _ in range(N):
    ini = input()[0]
    if ini in MARCH:
        c[MARCH.index(ini)] += 1
print(c[0]*c[1]*(c[2]+c[3]+c[4]) + (c[0]+c[1])*c[2]*(c[3]+c[4]) + (c[0]+c[1]+c[2])*c[3]*c[4])

Submission status: Accepted

Solution code:
import itertools

N = int(input())
nums = {key: 0 for key in "MARCH"}

for _ in range(N):
    name = input()
    if name[0] in nums:
        nums[name[0]] += 1

result = 0
for combination in itertools.combinations("MARCH", 3):
    first, second, third = combination
    result += nums[first] * nums[second] * nums[third]

print(result)

Submission status: Accepted

Solution code:
n=int(input())
s=[input() for i in range(n)]
d={}
for i in range(n):
  if (s[i][0]=='M' or s[i][0]=='A' or s[i][0]=='C' or s[i][0]=='R' or s[i][0]=='H') and s[i][0] not in d:
    d[s[i][0]]=1
  elif s[i][0] in d:
    d[s[i][0]]+=1
nd=list(d.values())
if len(nd)<3:
  print(0)
else:
  ans=0
  for i in range(len(nd)-2):
    for j in range(i+1,len(nd)-1):
      for k in range(j+1,len(nd)):
        ans+=nd[i]*nd[j]*nd[k]
  print(ans)

Submission status: Accepted

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

MARCH = set('MARCH')

n = int(sys.stdin.readline().rstrip())
s = [x[0] for x in sys.stdin.read().split() if x[0] in MARCH]

def main():
    c = Counter(s)
    ways = 0
    for comb in combinations('MARCH', 3):
        res = 1
        for i in comb:
            res *= c.get(i, 0)
        ways += res
    
    return ways

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

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

ans = 0
march = ["M","A","R","C","H"]
for i in range(len(march)):
    for j in range(i, len(march)):
        for k in range(j, len(march)):
            if march[i] != march[j] and march[i] != march[k] and march[j] != march[k]:
                ans += inis[march[i]] * inis[march[j]] * inis[march[k]]

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

w = "MARCH"
count = {key: 0 for key in w}

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

ans = 0
M = len(w)

for i in range(M):
    for j in range(i + 1, M):
        for k in range(j + 1, M):
            ans += count[w[i]] * count[w[j]] * count[w[k]]

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
d = {c: 0 for c in 'MARCH'}
for i in range(n):
    s = input()
    c = s[0]
    if c in d:
        d[c] += 1
v = [d[c] for c in d]

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