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 numpy as np
from collections import deque

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

S0 = list(map(lambda s: s[0], S))
n_MARCH = []
n_MARCH.append(S0.count('M'))
n_MARCH.append(S0.count('A'))
n_MARCH.append(S0.count('R'))
n_MARCH.append(S0.count('C'))
n_MARCH.append(S0.count('H'))

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

Submission status: Accepted

Solution code:
import itertools

n = int(input())
M=0
A=0
R=0
C=0
H=0
cnt=0
for _ in range(n):
    newstr = str(input())
    if newstr[0] == "M":
        M+=1
    elif  newstr[0] == "A":
        A+=1
    elif  newstr[0] == "R":
        R+=1
    elif  newstr[0] == "C":
        C+=1
    elif  newstr[0] == "H":
        H+=1
lis = [M,A,R,C,H]
#print(lis)
lis2 = [_ for _ in lis if _ != 0]
#print(lis2)
if len(lis2) < 3:
    print(0)
    exit()
else:
    for i in itertools.combinations(lis2, r=3):
        cnt += i[0] * i[1] * i[2]
print(cnt)

Submission status: Accepted

Solution code:
from itertools import combinations 

N = int(input())
d = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
ans = 0
for _ in range(N):
    s = input()
    head = s[0]
    if d.get(head) != None:
        d[head] += 1

for chars in combinations("MARCH", 3):
    ans += d[chars[0]] * d[chars[1]] * d[chars[2]]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
m, a, r, c, h = 0, 0, 0, 0, 0
for _ in range(N):
	S = input()
	if S[0] == "M":
		m += 1
	elif S[0] == "A":
		a += 1
	elif S[0] == "R":
		r += 1
	elif S[0] == "C":
		c += 1
	elif S[0] == "H":
		h += 1
print(m * a * r + m * a * c + m * a * h + m * r * c + m * r * h + m * c * h + a * r * c + a * r * h + a * c * h + r * c * h)

Submission status: Accepted

Solution code:
from collections import Counter
from itertools import combinations
n = int(input())
S = list(input() for i in range(n))
S = [s[0] for s in S if s[0] in 'MARCH']
c = Counter(S)
ans = 0
for xyz in list(combinations(c.keys(), 3)):
    x, y, z = xyz
    ans += c[x] * c[y] * c[z]
print(ans)

Submission status: Accepted

Solution code:
#ABC089-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=I()
count={"M":0,"A":0,"R":0,"C":0,"H":0}
for i in range(n):
    h=S()[0]
    if h in count:
        count[h]+=1

cl=list(count.values())
ans=0
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            ans+=cl[i]*cl[j]*cl[k]
print(ans)

Submission status: Accepted

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

for i in range(N):
  d[input()[0]]+=1
ans=0
for A,B,C in itertools.combinations("MARCH",3):
  ans+=d[A]*d[B]*d[C]
print(ans)

Submission status: Accepted

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

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

psum = 0
psum += sm["M"] * sm["A"] * sm["R"]
psum += sm["M"] * sm["A"] * sm["C"]
psum += sm["M"] * sm["A"] * sm["H"]
psum += sm["M"] * sm["R"] * sm["C"]
psum += sm["M"] * sm["R"] * sm["H"]
psum += sm["M"] * sm["C"] * sm["H"]
psum += sm["A"] * sm["R"] * sm["C"]
psum += sm["A"] * sm["R"] * sm["H"]
psum += sm["A"] * sm["C"] * sm["H"]
psum += sm["R"] * sm["C"] * sm["H"]

#print(sm)
print(psum)

Submission status: Accepted

Solution code:
N = int(input())
name = [input() for i in range(N)]
m = 0
a = 0
r = 0
c = 0
h = 0
for i in name :
    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

li = [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 += li[i]*li[j]*li[k]
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import itertools
cnt = 0
N = int(input())
S = {'M':0,'A':0,'R':0,'C':0,'H':0}
march = ['M','A','R','C','H']
for i in range(N):
    s = input()[0]
    if s in march:
        S[s] += 1
seq = S.values()
for i in list(itertools.combinations(seq, 3)):
    i = np.array(i)
    cnt += np.prod(i)

print(cnt)

Submission status: Accepted

Solution code:
n=int(input())
cnt=[0]*5
check='MARCH'
for i in range(n):
  s=input()
  for j in range(5):
    if s[0]==check[j]:
      cnt[j]+=1
      break
ans=0
for i in range(5):
  for j in range(i+1,5):
    for k in range(j+1,5):
      ans+=cnt[i]*cnt[j]*cnt[k]
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations as comb

B = [0,0,0,0,0]
for i in range(int(input())):
    z = input()[0]
    if z == 'M':
        B[0] += 1
    elif z == 'A':
        B[1] += 1
    elif z == 'R':
        B[2] += 1
    elif z == 'C':
        B[3] += 1
    elif z == 'H':
        B[4] += 1
ans = 0
for b in list(comb(B,3)):
    ans += b[0]*b[1]*b[2]
print(ans)

Submission status: Accepted

Solution code:
import itertools
N = int(input())
S = [input()[0] for _ in range(N)]
S = [v for v in S if v in 'MARCH']
s = list(set(S))
c = 0
for v in itertools.combinations(s, 3):
  c += S.count(v[0]) * S.count(v[1]) * S.count(v[2])
print(c)

Submission status: Accepted

Solution code:
from itertools import combinations

N = int(input())
S = [input() for i in range(N)]
march = {"M":0, "A":0, "R":0, "C":0, "H":0}

for i in S:
    if i[0] in march:
        march[i[0]] += 1

ans = 0
for first, second, third in combinations(march.values(), 3):
    ans += first * second * third

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = [input() for i in range(N)]
march = {"M":0, "A":0, "R":0, "C":0, "H":0}

for i in S:
    if i[0] in march:
        march[i[0]] += 1

ans = 0
for key1, value1 in march.items():
    for key2, value2 in march.items():
        for key3, value3 in march.items():
            if key1 < key2 < key3:
                ans += value1 * value2 * value3

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def cnt_digit(n):
    return 0 if n ==0 else (n&1) + cnt_digit(n//2)

def solve():
    n = f()[0]
    g = {}
    start = ['M', 'A', 'R', 'C', 'H']
    for i in start:
        g[i] = 0

    for i in range(n):
        s = input()
        if s[0] in start:
            g[s[0]] += 1


    ans  = 0
    for i in range(2**5):
        if cnt_digit(i) == 3:
            cur_ans = 1
            for j in range(5):
                if i&(1<<j):
                    cur_ans *= g[start[j]]
            ans += cur_ans
    
    print(ans)






solve()

Submission status: Accepted

Solution code:
import collections
import itertools
S=[]
N=input()
[S.append(input()) for n in range(int(N))]

S_head=[]

for name in S:
    if name[0] in ['M','A','R','C','H']:
        S_head.append(name[0])
        
S_head_unique = list(set(S_head))
num = collections.Counter(S_head)

if len(S_head_unique) >= 3:
    sum=0
    for comb in list(itertools.combinations(S_head_unique,3)):
        sum = sum+num[comb[0]]*num[comb[1]]*num[comb[2]]
    print(sum)
else:
    print(0)

Submission status: Accepted

Solution code:
N = int(input())
S = [input() for _ in range(N)]
A = [[0,1,2],[0,1,3],[0,1,4],[0,2,3],[0,2,4],[0,3,4],[1,2,3],[1,2,4],[1,3,4],[2,3,4]]
chrs = {'M':0,'A':1,'R':2,'C':3,'H':4}
X = [0]*5
for i in S:
    if(i[0] in chrs):
        X[chrs[i[0]]] += 1
ans = 0
for i in A:
    ans += X[i[0]]*X[i[1]]*X[i[2]]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, input().split()))
ns = lambda: input()

N=ni()
m=[0]*5
for i in range(N):
    tmp = input()
    if(tmp[0]=="M"):
        m[0]+=1
    elif(tmp[0]=="A"):
        m[1]+=1
    elif(tmp[0]=="R"):
        m[2]+=1
    elif(tmp[0]=="C"):
        m[3]+=1
    elif(tmp[0]=="H"):
        m[4]+=1
ans = 0
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            ans += m[i]*m[j]*m[k]
#print(m)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = [input() for i in range(n)]
c = [0, 0, 0, 0, 0]
cnt = 0
ans = 0

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

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

Submission status: Accepted

Solution code:


def read_input():
    n = int(input())

    names = []
    for i in range(n):
        names.append(input())

    return n, names


# MARCHのうち3つの取り出すパターンを作成
def initial_pattern():
    return [
        ['A', 'M', 'R'],
        ['A', 'C', 'M'],
        ['A', 'H', 'M'],
        ['C', 'M', 'R'],
        ['H', 'M', 'R'],
        ['C', 'H', 'M'],
        ['A', 'C', 'R'],
        ['A', 'H', 'R'],
        ['A', 'C', 'H'],
        ['C', 'H', 'R']]


def submit():
    n, names = read_input()

    name_file = {'M':[], 'A':[], 'R':[], 'C':[], 'H':[]}
    for n in names:
        if n[0] in 'MARCH':
            name_file[n[0]].append(n)

    count = 0
    initials = initial_pattern()

    for initial in initials:
        count += len(name_file[initial[0]]) * len(name_file[initial[1]]) * len(name_file[initial[2]])

    print(count)

if __name__ == '__main__':
    submit()

Submission status: Accepted

Solution code:
import sys
n=int(input())
s=[input() for i in range(n)]
c=[0,0,0,0,0]
cnt=0
ans=0
for i in s:
	if i[0] == 'M':
		c[0]+=1
	elif i[0] == 'A':
		c[1]+=1
	elif i[0] == 'R':
		c[2]+=1
	elif i[0] == 'C':
		c[3]+=1
	elif i[0] == 'H':
		c[4]+=1
	else:
		cnt+=1
if n-cnt < 3:
	print(ans)
	sys.exit()
for i in range(5):
	for j in range(i+1,5):
		for k in range(j+1,5):
			ans+=c[i]*c[j]*c[k]
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
import itertools
 
N = int(input())
src = [input() for i in range(N)]
 
counter = Counter()
for s in src:
    counter.update(s[0])
    
ans = 0
for pattern in itertools.combinations('MARCH',3):
    a,b,c = pattern
    ans += counter[a] * counter[b] * counter[c]
print(ans)

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
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())
S = [input() for _ in range(N)]
march = "MARCH"
dic = {"M":0,"A":0,"R":0,"C":0,"H":0}
for s in S:
    if s[0] in march:
        dic[s[0]] += 1
ans = 0
ans += dic["M"]*dic["A"]*dic["R"]
ans += dic["M"]*dic["A"]*dic["C"]
ans += dic["M"]*dic["A"]*dic["H"]
ans += dic["M"]*dic["R"]*dic["C"]
ans += dic["M"]*dic["R"]*dic["H"]
ans += dic["M"]*dic["C"]*dic["H"]
ans += dic["A"]*dic["R"]*dic["C"]
ans += dic["A"]*dic["R"]*dic["H"]
ans += dic["A"]*dic["C"]*dic["H"]
ans += dic["R"]*dic["C"]*dic["H"]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = []
march = ['M', 'A', 'R', 'C', 'H']
S_sub = []
for i in range(N):
    S.append(input())
    if S[i][0] in march:
        S_sub.append(S[i][0])
m_cnt = S_sub.count('M')
a_cnt = S_sub.count('A')
r_cnt = S_sub.count('R')
c_cnt = S_sub.count('C')
h_cnt = S_sub.count('H')
mar_cnt = m_cnt*a_cnt*r_cnt
mac_cnt = m_cnt*a_cnt*c_cnt
mah_cnt = m_cnt*a_cnt*h_cnt
mrc_cnt = m_cnt*r_cnt*c_cnt
mrh_cnt = m_cnt*r_cnt*h_cnt
mch_cnt = m_cnt*c_cnt*h_cnt
arc_cnt = a_cnt*r_cnt*c_cnt
arh_cnt = a_cnt*r_cnt*h_cnt
ach_cnt = a_cnt*c_cnt*h_cnt
rch_cnt = r_cnt*c_cnt*h_cnt
print(mar_cnt+mac_cnt+mah_cnt+mrc_cnt+mrh_cnt+mch_cnt+arc_cnt+arh_cnt+
      ach_cnt+rch_cnt)

Submission status: Accepted

Solution code:
import itertools
N = int(input())
names = []
chars = ["M","A","R","C","H"]
name_dic = {}
for i in range(N):
    name = input()
    if name[0] in chars:
        if   name[0] not in name_dic:
            name_dic[name[0]] = 1
        else:
            name_dic[name[0]] += 1


# print(name_dic)
chars2 = []
for c in chars:
    if  c in name_dic:
        chars2.append(c)
ans = 0
p = 0
coms= itertools.combinations(chars2,3)

for com in coms:
    temp = 1
    for c in com:
        temp*=name_dic[c]
    ans +=temp
print(ans)

Submission status: Accepted

Solution code:
# 2019/04/26
# AtCoder Beginner Contest 089 - C

# Input
n = int(input())
cl = ["M", "A", "R", "C", "H"]
ml = [0] * 5

# Count char
for i in range(n):
    wkc = input()
    for j in range(len(cl)):
        if cl[j] == wkc[0]:
            ml[j] += 1
            break
ans = 0
for x in range(len(cl) - 2):
    for y in range(x+1, len(cl) - 1):
        for z in range(y+1, len(cl)):
            ans += ml[x] * ml[y] * ml[z]

print(ans)

Submission status: Accepted

Solution code:
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
import collections
from operator import itemgetter
#以下てんぷら
def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)

p = "MARCH"
n = ip()                                     #入力整数1つ
#n,k= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
# a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#k = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#こっから本文
c = [0 for i in range(5)]
for i in range(n):
    if a[i][0] in p:
        b = p.index(a[i][0])
        c[b]+=1
s = 0
for i in range(3):
    for k in range(i+1,4):
        for l in range(k+1,5):
            s+=c[i]*c[k]*c[l]
print(s)

Submission status: Accepted

Solution code:
N=int(input())
a=[0]*5
for i in range(N):
    s=input()[0]
    if s=="M": a[0]+=1
    elif s=="A": a[1]+=1
    elif s=="R": a[2]+=1
    elif s=="C": a[3]+=1
    elif s=="H": a[4]+=1

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

Submission status: Accepted

Solution code:
N = int(input())
S = [input() for i in range(N)]
cm, ca, cr, cc, ch = 0, 0, 0, 0, 0
s = ''
c = 1
v = []

def dfs(s, c):
    if len(s) >= 2:
        if s[len(s)-1] == s[len(s)-2]:
            s = s[:-1]
            return 0
    if len(s) >= 3:
        if s[len(s)-1] == s[len(s)-3]:
            s = s[:-1]
            return 0
    if len(s) == 3:
        if s in v:
            s = s[:-1]
            return 0
        for i in range(3):
            for j in range(3):
                for k in range(3):
                    v.append(s[i] + s[j] + s[k])
        s = s[:-1]
        return c

    c = dfs(s+'M', c*cm) + dfs(s+'A', c*ca) + dfs(s+'R', c*cr) + dfs(s+'C', c*cc) + dfs(s+'H', c*ch)

    s = s[:-1]
    return c

for w in S:
    if w[0] == 'M':
        cm += 1
    elif w[0] == 'A':
        ca += 1
    elif w[0] == 'R':
        cr += 1
    elif w[0] == 'C':
        cc += 1
    elif w[0] == 'H':
        ch += 1

c = dfs(s, c)

if cm + ca + cr + cc + ch != 0:
    print(c)
else:
    print(0)

Submission status: Accepted

Solution code:
N = int(input())
S = [input() for _ in [0]*N]
n = {c:0 for c in "MARCH"}
for c in S:
    if c[0] in "MARCH":
        n[c[0]] += 1
march = list(n.values())
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:
import itertools
n=int(input())
l=[]
for i in range(n):l.append(input()[0])
c=[]
ul=["M","A","R","C","H"]
for i in ul:c.append(l.count(i))
cc=itertools.combinations(c, 3)
ans=0
for i,j,k in cc:ans+=i*j*k
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = []
for i in range(n):
  a = input()[0]
  if a in ["M","A","R","C","H"]:
    s.append(a)
ans = 0    
import itertools
for i,j,k in itertools.combinations(["M","A","R","C","H"], 3):
  ans += s.count(i) * s.count(j) * s.count(k)
print(ans)

Submission status: Accepted

Solution code:
import itertools

n = int(input())
m, a, r, c, h = 0, 0, 0, 0, 0

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

ans = 0

for a1, a2, a3 in itertools.combinations([m, a, r, c, h], 3):
    ans += (a1*a2*a3)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

n = {}
n["M"] = 0
n["A"] = 0
n["R"] = 0
n["C"] = 0
n["H"] = 0
heads = ["M","A","R", "C","H"]
for _ in range(N):
  s = input()
  if heads.count(s[0]) == 1:
    n[s[0]] += 1
    
ans = n["M"]*n["A"]*n["R"] + n["M"]*n["A"]*n["C"] + n["M"]*n["A"]*n["H"] \
    + n["M"]*n["R"]*n["C"] + n["M"]*n["R"]*n["H"] + n["M"]*n["C"]*n["H"] \
    + n["A"]*n["R"]*n["C"] + n["A"]*n["R"]*n["H"] + n["A"]*n["C"]*n["H"] + n["R"]*n["C"]*n["H"]
    
  
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

d = dict()
array = 'MARCH'
for i in array:
    d[i] = 0

for i in range(N):
    s = input()
    if s[0] in array:
        d[s[0]] += 1

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

print(ans)

Submission status: Accepted

Solution code:
from itertools import*
n,*a=open(0).read().split()
print(sum(p*q*r for p,q,r in combinations(map([i[0]for i in a].count,"MARCH"),3)))

Submission status: Accepted

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

from collections import Counter
dic = Counter(S)

from itertools import combinations

result = 0
for a, b, c in combinations("MARCH", 3):
    result += dic[a] * dic[b] * dic[c]
print(result)

Submission status: Accepted

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

n = int(input())
# s = [list(input().split()) for _ in range(n)]

s = []
m = 0
a = 0
r = 0
c = 0
h = 0

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

ans = 0

ans += m*a*r
ans += m*a*c
ans += m*a*h
ans += m*r*c
ans += m*c*h
ans += m*r*h
ans += a*r*c
ans += a*r*h
ans += a*c*h
ans += r*c*h

print(ans)

Submission status: Accepted

Solution code:
n,r,c,t,ans=int(input()),{"M":0,"A":0,"R":0,"C":0,"H":0},0,("M","A","R","C","H"),0
for i in range(n):
  s=input()
  if s[0] in r:
    if r[s[0]]==0:c+=1
    r[s[0]]+=1
for i in range(3):
  for j in range(i+1,4):
    for h in range(j+1,5):ans+=r[t[i]]*r[t[j]]*r[t[h]]
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
S=[input()[0] for _ in range(N)]
C=[S.count(c) for c in "MARCH"]
print(C[0]*C[1]*C[2]+C[0]*C[1]*C[3]+C[0]*C[1]*C[4]+C[0]*C[2]*C[3]+C[0]*C[2]*C[4]+C[0]*C[3]*C[4]+C[1]*C[2]*C[3]+C[1]*C[2]*C[4]+C[1]*C[3]*C[4]+C[2]*C[3]*C[4])

Submission status: Accepted

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

S1=[]
for i in S:
    if i[0] == "M":
        S1.append(i)
    if i[0] == "A":
        S1.append(i)
    if i[0] == "R":
        S1.append(i)
    if i[0] == "C":
        S1.append(i)
    if i[0] == "H":
        S1.append(i)

dict={}
for i in range(len(S1)):
    x=S1[i]
    if x[0] in dict:
        dict[x[0]] += 1
    else:
        dict[x[0]] = 1

if len(dict) < 3:
    print("0")

if len(dict) == 3:
    list3 = list(dict.values())
    print(list3[0]*list3[1]*list3[2])

if len(dict) == 4:
    list4 = list(dict.values())
    print((list4[0]*list4[1]*list4[2])+(list4[0]*list4[2]*list4[3])+(list4[1]*list4[2]*list4[3])+(list4[0]*list4[1]*list4[3]))

if len(dict) == 5:
    a = list(dict.values())
    print((a[0]*a[1]*a[2])+(a[0]*a[2]*a[3])+(a[0]*a[3]*a[4])+(a[0]*a[1]*a[3])+(a[0]*a[1]*a[4])+(a[1]*a[2]*a[3])+(a[1]*a[2]*a[4])+(a[1]*a[3]*a[4])+(a[2]*a[3]*a[4])+(a[0]*a[2]*a[4]))

Submission status: Accepted

Solution code:
import itertools

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

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

combi = [i for i in ppl if i != 0]

ans = 0
if len(combi) < 3:
    pass
else:
    combinations = list(itertools.combinations(combi, 3))
    for i in combinations:
        ans += i[0] * i[1] * i[2]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
def MI(): return map(int, input().split())
def II(): return int(input())
def IS(): return input()
def LI(): return list(map(int, input().split()))


n = II()
s = [IS()[0] for _ in range(n)]
m = s.count('M');
a = s.count('A');
r = s.count('R');
c = s.count('C');
h = s.count('H');

march = ['M','A','R','C','H']
ans = 0
for combination in list(itertools.combinations(march, 3)):
    count = 1
    for char in combination:
        if char == 'M':
            count *= m
        elif char == 'A':
            count *= a
        elif char == 'R':
            count *= r
        elif char == 'C':
            count *= c
        else:  # char == 'h'
            count *= h
    ans += count
print(ans)

Submission status: Accepted

Solution code:
from math import factorial
import itertools


def combination(n, r):  # n個からr個選ぶ場合の数
    if n < r:
        return 0
    else:
        return factorial(n)//(factorial(r) * factorial(n-r))


N = int(input())
l = ["M", "A", "R", "C", "H"]
S = [input()[0] for i in range(N)]
ans = 0
anagram = list(itertools.combinations([0, 1, 2, 3, 4], 3))

for ana in anagram:
    ans += S.count(l[ana[0]])*S.count(l[ana[1]])*S.count(l[ana[2]])

print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
n = int(input())
s = list(map(lambda s:s[0], [input() for _ in range(n)]))
marchn = [s.count(c) for c in list("MARCH")]
ans = 0
for li in combinations(marchn, 3):
    ans += li[0] * li[1] * li[2]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
d = dict()
d['M'] = 0
d['A'] = 0
d['R'] = 0
d['C'] = 0
d['H'] = 0
for i in range(n):
    s = input()
    if s[0] in 'MARCH':
        d[s[0]] += 1
s = "MARCH"
ans = 0
for i in range(5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            ans += d[s[i]] * d[s[j]] * d[s[k]]

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

Name = []
Initial = {}
for n in range(N):
    name = input()
    Name.append(name)
    if name[0] in Initial:
        Initial[name[0]] += 1
    else:
        Initial[name[0]] = 1

ans = 0

# 5C3=5*4*3/3*2*1=10
ans += Initial.get("M", 0) * Initial.get("A", 0) * Initial.get("R", 0)
ans += Initial.get("M", 0) * Initial.get("A", 0) * Initial.get("C", 0)
ans += Initial.get("M", 0) * Initial.get("A", 0) * Initial.get("H", 0)
ans += Initial.get("M", 0) * Initial.get("R", 0) * Initial.get("C", 0)
ans += Initial.get("M", 0) * Initial.get("R", 0) * Initial.get("H", 0)
ans += Initial.get("M", 0) * Initial.get("C", 0) * Initial.get("H", 0)
ans += Initial.get("A", 0) * Initial.get("R", 0) * Initial.get("C", 0)
ans += Initial.get("A", 0) * Initial.get("R", 0) * Initial.get("H", 0)
ans += Initial.get("A", 0) * Initial.get("C", 0) * Initial.get("H", 0)
ans += Initial.get("R", 0) * Initial.get("C", 0) * Initial.get("H", 0)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
initial = ['M', 'A', 'R', 'C', 'H']
num = [0]*5

for i in range(N):
    S = input()
    for j in range(len(initial)):
        if S[0]==initial[j]:
            num[j] += 1
            break

ans = 0
ans += num[0]*num[1]*(num[2]+num[3]+num[4])
ans += num[0]*num[2]*(num[3]+num[4])
ans += num[0]*num[3]*num[4]
ans += num[1]*num[2]*(num[3]+num[4])
ans += num[1]*num[3]*num[4]
ans += num[2]*num[3]*num[4]

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
d = {}
for i in range(N):
    s = input()[0]
    if s not in d.keys():
        d[s] = 0
    d[s] += 1
march = ["M","A","R","C","H"]
lis = []
for a in d.keys():
    if a in march:
        lis.append(a)
import itertools
ans = 0
for l in list(itertools.combinations(lis,3)):
    ans += d[l[0]]*d[l[1]]*d[l[2]]
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=[input()[0] for _ in range(n)]
a=['M','A', 'R', 'C', 'H']
import itertools
num=[0]* 5
for i in range(5):
    num[i]=s.count(a[i])
ans=0
if num.count(0)<=2:
    m=[x for x in num if x > 0]
    p=list(itertools.combinations(m, 3))
    for j in range(len(p)):
        ans+=p[j][0]*p[j][1]*p[j][2]
print(ans)

Submission status: Accepted

Solution code:
n=int(raw_input())
s=[str(raw_input()) for i in range(n)]
m,a,r,c,h=0,0,0,0,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

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

ans=[]

for i in range(10):
	tmpl=[]
	ctr=0
	for k in range(5):
		if tl[i][k]*sl[k]!=0:
			ctr+=1
			tmpl.append(tl[i][k]*sl[k])
	if ctr==3:
		ans.append(tmpl[0]*tmpl[1]*tmpl[2])
print sum(ans)

Submission status: Accepted

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

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

import math
counter = 0
s_list_nonzero = []
for i in range(5):
    if s_list[i] != 0:
        counter += 1
        s_list_nonzero.append(s_list[i])

if counter < 3:
    print(0)
elif counter == 3:
    print(s_list_nonzero[0] * s_list_nonzero[1] * s_list_nonzero[2])
elif counter == 4:
    print(s_list_nonzero[0] * s_list_nonzero[1] * s_list_nonzero[2] +
            s_list_nonzero[0] * s_list_nonzero[1] * s_list_nonzero[3] +
            s_list_nonzero[0] * s_list_nonzero[2] * s_list_nonzero[3] +
            s_list_nonzero[1] * s_list_nonzero[2] * s_list_nonzero[3])
elif counter == 5:
    print(s_list_nonzero[0] * s_list_nonzero[1] * s_list_nonzero[2] +
            s_list_nonzero[0] * s_list_nonzero[1] * s_list_nonzero[3] +
            s_list_nonzero[0] * s_list_nonzero[1] * s_list_nonzero[4] +
            s_list_nonzero[0] * s_list_nonzero[2] * s_list_nonzero[3] +
            s_list_nonzero[0] * s_list_nonzero[2] * s_list_nonzero[4] +
            s_list_nonzero[0] * s_list_nonzero[3] * s_list_nonzero[4] +
            s_list_nonzero[1] * s_list_nonzero[2] * s_list_nonzero[3] +
            s_list_nonzero[1] * s_list_nonzero[2] * s_list_nonzero[4] +
            s_list_nonzero[1] * s_list_nonzero[3] * s_list_nonzero[4] +
            s_list_nonzero[2] * s_list_nonzero[3] * s_list_nonzero[4])

Submission status: Accepted

Solution code:
N = int(input())
S = [input() for i in range(N)]
S_march = []
MARCH = ["M", "A", "R", "C", "H"]

cmb = []
ans = 0

N_march = [0]*5

for Si in S:
  for j in range(5):
    if Si[:1] == MARCH[j]:
      N_march[j] += 1

for i in range(2**5):
  check = [False]*5
  for j in range(5):
    if (i>>j) & 1:
      check[j] = True
  if check.count(True) == 3:
    cmb.append(check)

for i in cmb:
  tmp_list = []
  for j in range(5):
    if i[j]:
      tmp_list.append(N_march[j])
  ans += tmp_list[0]*tmp_list[1]*tmp_list[2]
  
print(ans)
      
      
#for i in range(2*N):
#  for j in range(N):
#    if (i>>j) & 1:
#      if S[j][:1] in MARCH:
#        check[j] = True
#        MARCH.pop(S[j][:1])
#  if check.count(True) == 3:
#    ans += 1
#print(ans)

Submission status: Accepted

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

a,b,c,d,e = list2[0],list2[1],list2[2],list2[3],list2[4]
ans = a*b*c + a*b*d + a*b*e + a*c*d + a*c*e + a*d*e
ans += b*c*d + b*c*e + b*d*e 
ans += c*d*e
print(ans)

Submission status: Accepted

Solution code:
from itertools import*;s,*_=zip(*open(0));print(sum(p*q*r for p,q,r in combinations(map(s.count,'MARCH'),3)))

Submission status: Accepted

Solution code:
import itertools
n = int(input())
L = [[]for i in range(5)]
for i in range(n):
    s = str(input())
    if s[0] == "M":
        L[0].append(s)
    elif s[0] == "A":
        L[1].append(s)
    elif s[0] == "R":
        L[2].append(s)
    elif s[0] == "C":
        L[3].append(s)
    elif s[0] == "H":
        L[4].append(s)
L = [ i for i in L if len(i) > 0]
ans = 0
for i in itertools.combinations(L, 3):
    ans += len(i[0])*len(i[1])*len(i[2])
print(ans)