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 itertools
N = int(input())
S = [input() for i in range(N)]
U = []
n = [0,0,0,0,0]
result = 0

for i in range(N):
    if S[i][0] == 'M' or S[i][0] == 'A' or S[i][0] == 'R' or S[i][0] == 'C' or S[i][0] == 'H':
        U.append(S[i][0])
    
    if S[i][0] == 'M':
        n[0] += 1
    if S[i][0] == 'A':
        n[1] += 1
    if S[i][0] == 'R':
        n[2] += 1
    if S[i][0] == 'C':
        n[3] += 1
    if S[i][0] == 'H':
        n[4] += 1
        
c = list(itertools.combinations(n,3))

for i in range(10):
    result = result + c[i][0]*c[i][1]*c[i][2]

print(result)

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()[0]
    if s in d:
        d[s]+=1

ans = 0
for s1 in d:
    for s2 in d:
        for s3 in d:
            if s1 != s2 and s2 != s3 and s3 != s1:
                ans += d[s1]*d[s2]*d[s3]
print(ans//6)

Submission status: Accepted

Solution code:
march = ['M', 'A', 'R', 'C', 'H']
counts = [0 for _ in range(len(march))]
N = int(input())

for _ in range(N):
    tmp = input()[0]
    if tmp in march:
        counts[march.index(tmp)] += 1

res = 0
c = 0
for i in range(len(counts)):
    for j in range(i + 1, len(counts)):
        for k in range(j + 1, len(counts)):
            tmp = counts[i] * counts[j] * counts[k]
            res += tmp

print(res)

Submission status: Accepted

Solution code:
import itertools

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

top = [0 for i in range(5)]
ans = 0

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

comb = [0 for i in range(10)]
comb = list(itertools.combinations(top,3))


for i in range(len(comb)):
    mul = 1
    for j in comb[i]:
        mul *= j
    ans += mul

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):
    name=input()
    if name[0]=="M":
        M+=1
    elif name[0]=="A":
        A+=1
    elif name[0]=="R":
        R+=1
    elif name[0]=="C":
        C+=1
    elif name[0]=="H":
        H+=1

count=0
list1=[M,A,R,C,H]
#print(list1)
for j in range(3):
    
    for k in range(j+1,4):
        
            for l in range(k+1,5):
                #print(list1[j]*list1[k]*list1[l])
                count=count+list1[j]*list1[k]*list1[l]
print(count)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import itertools

N = int(input())
name_dict = {"M":0, "A":0, "R":0, "C":0, "H":0}

# 各イニシャル毎に集計
for i in range(N):
    name_str = input()
    if name_str[0] == "M":
        name_dict["M"] += 1
    if name_str[0] == "A":
        name_dict["A"] += 1
    if name_str[0] == "R":
        name_dict["R"] += 1
    if name_str[0] == "C":
        name_dict["C"] += 1
    if name_str[0] == "H":
        name_dict["H"] += 1

# MARCHから3文字を選ぶ組み合わせ
cmb_list = list(itertools.combinations(["M","A","R","C","H"], 3))

ans = 0
for cmb in cmb_list:
    # 各イニシャルの人数毎に掛け合わせて合計していく
    ans += name_dict[cmb[0]] * name_dict[cmb[1]] * name_dict[cmb[2]]
    
print(ans)

Submission status: Accepted

Solution code:
def m():
    n = int(input())
    S = [str(input()) for _ in range(n)]
    m = 0
    a = 0
    r = 0
    c = 0
    h = 0
    x = [0, 0, 0, 0, 0, 0, 1, 1, 1, 2]
    y = [1, 1, 1, 2, 2, 3, 2, 2, 3, 3]
    z = [2, 3, 4, 3, 4, 4, 3, 4, 4, 4]
    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
    ans = 0
    d = [m, a, r, c, h]
    for j in range(10):
        ans += d[x[j]] * d[y[j]] * d[z[j]]
    return ans
print(m())

Submission status: Accepted

Solution code:
from functools import reduce
from itertools import combinations
N = int(input())
S = {"M": [], "A": [], "R": [], "C": [], "H": []}
for _ in range(N):
    i = input()
    head = i[0]
    if head == "M":
        S["M"].append(i)
    elif head == "A":
        S["A"].append(i)
    elif head == "R":
        S["R"].append(i)
    elif head == "C":
        S["C"].append(i)
    elif head == "H":
        S["H"].append(i)
counter = [len(S[head]) for head in list("MARCH") if len(S[head]) != 0]
combs = list(combinations(counter, 3))
ans = sum([reduce(lambda x, y: x * y, e) for e in combs])
print(ans)

Submission status: Accepted

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

# 入力された文字に対する辞書の生成
for i in range(0, N):
    if S[i][0] in nameDict.keys():
        nameDict[S[i][0]] += 1

for i in nameDict.values():
    List.append(i)

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

Submission status: Accepted

Solution code:
from itertools import combinations

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

num = {
    'M': 0,
    'A': 0,
    'R': 0,
    'C': 0,
    'H': 0,
}
for s_i in s:
    for x in 'MARCH':
        if s_i[0] == x:
            num[x] += 1
            break

ans = 0
for x1, x2, x3 in combinations('MARCH', 3):
    ans += num[x1] * num[x2] * num[x3]
print(ans)

Submission status: Accepted

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

for i in range(N):
    temp = input()
    init_temp = list(temp)   
    if 'M' == init_temp[0]:
        M.append(temp)
    elif 'A' == init_temp[0]:
        A.append(temp)
    elif 'R' == init_temp[0]:
        R.append(temp)
    elif 'C' == init_temp[0]:
        C.append(temp)
    elif 'H' == init_temp[0]:
        H.append(temp)
    else:
        pass

M = len(list(set(M)))
A = len(list(set(A)))
R = len(list(set(R)))
C = len(list(set(C)))
H = len(list(set(H)))

D = [M, A, R, C, H]
#10通り書き出す
A = [0, 0, 0, 0, 0, 0, 1, 1, 1, 2]
B = [1, 1, 1, 2, 2, 3, 2, 2, 3, 3]
C = [2, 3, 4, 3, 4, 4, 3, 4, 4, 4]

ans = 0

for i in range(10):
    ans += D[A[i]] * D[B[i]] * D[C[i]]

print(ans)

Submission status: Accepted

Solution code:
from functools import reduce
from operator import mul
import itertools
N = int(input())
x = [input() for _ in range(N)]
M = len([m for m in x if m.startswith('M')])
A = len([a for a in x if a.startswith('A')])
R = len([r for r in x if r.startswith('R')])
C = len([c for c in x if c.startswith('C')])
H = len([h for h in x if h.startswith('H')])
y = [M,A,R,C,H]
yy = [i for i in y if i > 0]
yl = len(yy)
s = 0
if yl < 3:
    print(0)
    exit()
else:
    for o in itertools.combinations(yy,3):
        s += reduce(mul,o)
    print(s)

Submission status: Accepted

Solution code:
n = int(input())
sd = {}
hl = ["M","A","R","C","H"]
for i in range(n):
    s = input()
    head = s[0]
    
    if not head in hl:
        continue
        
    if head in sd:
        sd[head] += 1
    else:
        sd[head] = 1
        
values = list(sd.values())
#print(values)
length = len(values)
counts = 0
if length < 3:
    print(0)
else:
    for i in range(length-2):
        for j in range(i+1,length-1):
            for k in range(j+1,length):
#                print(i,j,k)
                counts += values[i]*values[j]*values[k]

    print(counts)

Submission status: Accepted

Solution code:
n=int(input())
m=['M','A','R','C','H']
d={}
for _ in range(n):
    s=input()[0]
    if s in m:
        if s in d:d[s]+=1
        else:d[s]=1
d=list(d.values())
r=0
l=len(d)
for i in range(l):
    for j in range(i+1,l):
        for k in range(j+1,l):
            r+=d[i]*d[j]*d[k]
print(r)

Submission status: Accepted

Solution code:
import itertools
from collections import Counter
N = int(input())
src = [input() for i in range(N)]
ctr = Counter([s[0] for s in src])

ans = 0
for ptn in itertools.combinations('MARCH',3):
    ans += ctr[ptn[0]]*ctr[ptn[1]]*ctr[ptn[2]]
print(ans)

Submission status: Accepted

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

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

def make_count_list(names):
    firsts = list(map(lambda x: x[0], names))
    counts = []
    for c in "MARCH":
        counts.append(firsts.count(c))
    return counts

def main():
    counts = make_count_list(S)
    comb_num = 3
    ans = 0
    for comb in combinations(counts, comb_num):
        ans += reduce(mul, comb)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import itertools

N = int(input())

S = []
for _ in range(N):
    S.append(input())
    
M, A, R, C, H = [], [], [], [], []

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

for s in S:
    top = s[0]
    if top in march:
        if top == "M":
            M.append(s)
        elif top == "A":
            A.append(s)
        elif top == "R":
            R.append(s)
        elif top == "C":
            C.append(s)
        elif top == "H":
            H.append(s)

MARCH = [len(M), len(A), len(R), len(C), len(H)]

if MARCH.count(0) >= 3:
    print(0)

else:
    x = 0
    pattern = list(itertools.combinations(MARCH, 3))
    for i in pattern:
        x += i[0]*i[1]*i[2]
    print(x)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
S = []
for i in range(N):
    s = input()
    if s[0] in ["M","A","R","C","H"]:
        S.append(s[0])
C = Counter(S).most_common()
lenC = len(C)
Ans = 0
for i in range(lenC):
    for j in range(i+1,lenC):
        for k in range(j+1,lenC):
            Ans += C[i][1]*C[j][1]*C[k][1]
print(Ans)

Submission status: Accepted

Solution code:
from itertools import groupby, combinations
N = int(input())
Names = [input()[0] for _ in range(N)]
Names.sort()
Initials = {k: len(list(g)) for k, g in groupby(Names) if k in ['M', 'A', 'R', 'C', 'H']}
L = combinations(Initials.keys(), 3)
cnt = 0
for c in L:
    cnt += Initials[c[0]] * Initials[c[1]] * Initials[c[2]]
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
text = list("MARCH")
dict = {}
for t in text:
    dict[t] = 0
for _ in range(N):
    x = input()[0]
    if x in text:
        dict[x] += 1

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

Submission status: Accepted

Solution code:
import itertools

N = int(input())
march_d = dict()
for c in "MARCH":
  march_d[c] = 0
for _ in range(N):
  name = input()
  if name[0] in "MARCH":
    march_d[name[0]] += 1
    
#頭文字の選び方１０通り
ans = 0
for n1, n2, n3 in itertools.combinations("MARCH", 3):
  ans += march_d[n1] * march_d[n2] * march_d[n3]

print(ans)

Submission status: Accepted

Solution code:
n = int(raw_input())
a = [0 for _ in range(5)]
for _ in range(n):
  s = raw_input()
  if s[0] == 'M':
    a[0] += 1
  elif s[0] == 'A':
    a[1] += 1
  elif s[0] == 'R':
    a[2] += 1
  elif s[0] == 'C':
    a[3] += 1
  elif s[0] == 'H':
    a[4] += 1
ct = 0
for i in range(5):
  for j in range(i+1,5):
    for k in range(j+1,5):
      ct += a[i] * a[j] * a[k]
print ct

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri Mar  9 16:34:45 2018

@author: Narita
"""
import collections
import itertools

def main():
    N = int(input())
    S = []
    for i in range(N):
        S.append(input())
#    print(S)
    
    result = 0
    match_str = "MARCH"
    combi_str = list(itertools.combinations(list(match_str), 3))
#    print(combi_str)
    initial_char = []
    for i in range(N):
#        print(S[i][0])
#        print(S[i][0] in match_str)
        if(S[i][0] in match_str):
            initial_char.append(S[i][0])
#    print(initial_char)
    c = collections.Counter(initial_char)
#    print(c)
    for li in combi_str:
        result += c[li[0]] * c[li[1]] * c[li[2]]
    print(result)
    
if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
import itertools
n = int(input())
l = []
counts = []
ans = 0
for i in range(5):
  l.append(set([]))

for i in range(n):
  temp = input()
  
  if temp[0] == 'M':
    l[0].add(temp)
  elif temp[0] == 'A':
    l[1].add(temp)
  elif temp[0] == 'R':
    l[2].add(temp)
  elif temp[0] == 'C':
    l[3].add(temp)
  elif temp[0] == 'H':
    l[4].add(temp)

for i in l:
  if not len(i) == 0:
    counts.append(len(i))

if len(counts) >= 3:
  for count in itertools.combinations(counts, 3):
    ans += count[0]*count[1]*count[2]

print(ans)

Submission status: Accepted

Solution code:
import itertools
n = int(input())
cnt = [0, 0, 0, 0, 0]
perm = [0, 1, 2, 3, 4]
for i in range(n):
    name = input()
    if name[0] == 'M':
        cnt[0] += 1
    elif name[0] == 'A':
        cnt[1] += 1
    elif name[0] == 'R':
        cnt[2] += 1
    elif name[0] == 'C':
        cnt[3] += 1
    elif name[0] == 'H':
        cnt[4] += 1
ans = 0
for i, j, k in itertools.combinations(perm, 3):
    ans += cnt[i] * cnt[j] * cnt[k]
print(ans)

Submission status: Accepted

Solution code:
# PROBLEM C
from collections import Counter
from itertools import combinations

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

fl2c = Counter(s[0] for s in ss if s[0] in 'MARCH')
res = 0
for a, b, c in combinations(fl2c, 3):
    res += fl2c[a] * fl2c[b] * fl2c[c]
print(res)

Submission status: Accepted

Solution code:
N = int(input())

lst = [0] * 5

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

count = 0

for i in range(5):
    for j in range(i + 1, 5):
        for k in range(j + 1, 5):
            count += lst[i] * lst[j] * lst[k]

print(count)

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}
str_s = "MARCH"
ans = 0

import re
for item in dict_s.keys():
    for word in s:
        if(re.match(item, word) != None):
            dict_s[item] += 1

for i in range(3):
    for j in range(i+1,5):
        for k in range(j+1,5):
            ans += dict_s[str_s[i]] * dict_s[str_s[j]] * dict_s[str_s[k]]
            # print("[%d] [%d] [%d]" %(i,j,k))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = input()
keywords = list("MARCH")
m = len(keywords)
D = dict(zip(keywords, [0] * m))
for i in range(n):
    s = raw_input()
    c = s[0]
    if c in D:
        D[c] += 1
ans = 0
for i in range(m):
    for j in range(i+1, m):
        for k in range(j+1, m):
            ans += D[keywords[i]] * D[keywords[j]] * D[keywords[k]]
print ans

Submission status: Accepted

Solution code:
def ii():
    return int(input())


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


def lvi(N):
    l = []
    for _ in range(N):
        l.append(ii())
    return l


def lv(N):
    l = []
    for _ in range(N):
        l.append(input())
    return l


def C():
    N = ii()
    d = {'M': 0, 'A':0, 'R':0,'C':0,'H':0}
    for _ in range(N):
        s = input()
        if s[0] in d.keys():
            d[s[0]] += 1

    from itertools import combinations

    ans = 0
    for e1, e2, e3 in combinations(d.keys(), 3):
        ans += d[e1] * d[e2] * d[e3]

    print(ans)

if __name__ == '__main__':
    C()

Submission status: Accepted

Solution code:
from collections import defaultdict
import itertools

N = int(input())

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

if len(P)<3:
    print(0)
else:
    ans = 0
    for a,b,c in itertools.combinations(P,3):
        ans += P[a]*P[b]*P[c]
    print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from collections import defaultdict
from itertools import combinations
N = int(input())
C = [0, 0, 0, 0, 0, 0]
D = defaultdict(int)
for i, m in enumerate("MARCH", start=1):
    D[m] = i

for _ in range(N):
    C[D[input()[0]]] += 1

ans = 0
for a, b, c in combinations(range(1, 6), r=3):
    ans += C[a]*C[b]*C[c]
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from itertools import combinations
N = int(input())
C = [0, 0, 0, 0, 0]
march = set(list("MARCH"))
for _ in range(N):
    S = input()[0]
    if S in march:
        C["MARCH".index(S)] += 1

ans = 0
for a, b, c in combinations(range(5), r=3):
    ans += C[a]*C[b]*C[c]
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=[input()for i in range(n)]
m_cnt,a_cnt,r_cnt,c_cnt,h_cnt=0,0,0,0,0
import itertools
ans=0
for i in range(n):
    if s[i][0]=="M":
        m_cnt+=1
    elif s[i][0]=="A":
        a_cnt+=1
    elif s[i][0]=="R":
        r_cnt+=1
    elif s[i][0]=="C":
        c_cnt+=1
    elif s[i][0]=="H":
        h_cnt+=1
x=list(itertools.combinations((m_cnt,a_cnt,r_cnt,c_cnt,h_cnt),3))
for i in x:
    ans+=i[0]*i[1]*i[2]
print(ans)

Submission status: Accepted

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

numM, numA, numR, numC, numH = 0,0,0,0,0
ans=0

for i in range(N):
    if S[i][0]=='M':
        numM+=1
    elif S[i][0]=='A':
        numA+=1
    elif S[i][0]=='R':
        numR+=1
    elif S[i][0]=='C':
        numC+=1
    elif S[i][0]=='H':
        numH+=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=list()
D.append(numM)
D.append(numA)
D.append(numR)
D.append(numC)
D.append(numH)

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
ss = []
for _ in range(n):
    ss.append(input())
hs = dict()
keys = ['M', 'A', 'R', 'C', 'H']
for k in keys:
    hs[k] = 0
ss = sorted(ss)
for i, s in enumerate(ss, 0):
    c = s[0]
    if c in keys:
        if c in hs:
            hs[c] += 1
        else:
            hs[c] = 1
import itertools
combs = list(itertools.combinations(keys,3))
ans = 0
for comb in combs:
    ans += hs[comb[0]] * hs[comb[1]] * hs[comb[2]]
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
N=int(input())
nums={}
for i in "MARCH":
    nums[i]=0
for i in range(N):
    s=input().strip()
    if s[0] in "MARCH":
        nums[s[0]]+=1
ct=0
for a,b,c in combinations("MARCH",3):
    ct+=nums[a]*nums[b]*nums[c]
print(ct)

Submission status: Accepted

Solution code:
from itertools import combinations

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

s_comb_list = list(combinations('MARCH', 3))
v = 0
for s_comb in s_comb_list:
    v += (d[s_comb[0]] * d[s_comb[1]] * d[s_comb[2]])
print(v)

Submission status: Accepted

Solution code:
import itertools

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

num = [0, 0, 0, 0, 0]
index = ['M', 'A', 'R', 'C', 'H']
for i in range(n):
    for j in range(5):
        if s[i][0] == index[j]:
            num[j] += 1
            pass

if num.count(0) >= 3:
    print(0)
    exit()

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

if len(data) == 3:
    print(data[0] * data[1] * data[2])

elif len(data) == 4:
    print(data[0]*data[1]*data[2] + data[0]*data[1]*data[3] + data[0]*data[2]*data[3] + data[1]*data[2]*data[3])

else:
    print(data[0]*data[1]*data[2] + data[0]*data[1]*data[3] + data[0]*data[1]*data[4] + data[0]*data[2]*data[3] + data[0]*data[2]*data[4] + data[0]*data[3]*data[4] + data[1]*data[2]*data[3] + data[1]*data[2]*data[4] + data[1]*data[3]*data[4] + data[2]*data[3]*data[4])

Submission status: Accepted

Solution code:
n = int(input())
ss = []
for _ in range(n):
    ss.append(input())
hs = dict()
#hhs = dict()
keys = ['M', 'A', 'R', 'C', 'H']
for k in keys:
    hs[k] = 0
ss = sorted(ss)
for i, s in enumerate(ss, 0):
    c = s[0]
    if c in keys:
        if c in hs:
            hs[c] += 1
        else:
            hs[c] = 1
#        if i > 0 and s == ss[i - 1]:
#            if s in hhs:
#                hhs[s] += 1
#            else:
#                hhs[s] = 1
import itertools
combs = list(itertools.combinations(keys,3))
ans = 0
for comb in combs:
    ans += hs[comb[0]] * hs[comb[1]] * hs[comb[2]]
print(ans)

Submission status: Accepted

Solution code:
# your code goes here
N = int(input())

cnt = [0]*5

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

Submission status: Accepted

Solution code:
N = int(input())
S = []
march = [0, 0, 0, 0, 0]

for i in range(0, 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

#print(march)

ans = 0

for i in range(2, 5):
    ans = ans + march[0] * march[1] * march[i]
for i in range(3, 5):
    ans = ans + march[0] * march[2] * march[i]

ans = ans + march[0] * march[3] * march[4]

for i in range(3, 5):
    ans = ans + march[1] * march[2] * march[i]

ans = ans + march[1] * march[3] * march[4]

ans = ans + march[2] * march[3] * march[4]

print(ans)

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

print(ans)
"""

Submission status: Accepted

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

Submission status: Accepted

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

march = [m,a,r,c,h]
for i in range(0,5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            answer = answer + march[i]*march[j]*march[k]
print(answer)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
S = [None]*N
for i in range(N):
    S[i] = input()

S_M = [S[i] for i in range(N) if S[i][0] == 'M']
S_A = [S[i] for i in range(N) if S[i][0] == 'A']
S_R = [S[i] for i in range(N) if S[i][0] == 'R']
S_C = [S[i] for i in range(N) if S[i][0] == 'C']
S_H = [S[i] for i in range(N) if S[i][0] == 'H']

souwa = 0
kahi = [0]*5
kahi[0] = len(S_M)
kahi[1] = len(S_A)
kahi[2] = len(S_R)
kahi[3] = len(S_C)
kahi[4] = len(S_H)

for i in range(len(kahi)-2):
    for j in range(i+1, len(kahi)-1):
        for k in range(j+1, len(kahi)):
            souwa += kahi[i]*kahi[j]*kahi[k]
print(souwa)

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
    if s[0] == "A":   a += 1
    if s[0] == "R":   r += 1
    if s[0] == "C":   c += 1
    if 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())
nli = []

nlid = {'M':0,'A':0,'R':0,'C':0,'H':0}

for i in range(n):
    p = str(input())
    nli.append(p)
    q = list(p)
    po = q[0].upper()
    if po in nlid :
        nlid[po] = nlid[po] + 1
    else:
        None
    
#print(nlid)
count = nlid['M'] * nlid['A'] * nlid['R'] + nlid['M'] * nlid['A'] * nlid['C'] + nlid['M'] * nlid['A'] * nlid['H'] + nlid['M'] * nlid['R'] * nlid['C'] + nlid['M'] * nlid['R'] * nlid['H'] + nlid['M'] * nlid['C'] * nlid['H'] + nlid['A'] * nlid['R'] * nlid['C'] + nlid['A'] * nlid['R'] * nlid['H'] + nlid['A'] * nlid['C'] * nlid['H'] + nlid['R'] * nlid['C'] * nlid['H']
                
print(count)

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 A in s:
    if A[0]=='M':
        m+=1
    elif A[0]=='A':
        a+=1
    elif A[0]=='R':
        r+=1
    elif A[0]=='C':
        c+=1
    elif A[0]=='H':
        h+=1
x = []
for i in [m,a,r,c,h]:
    if i != 0:
        x.append(i)
if len(x)<3:
    print(0)
elif len(x)==3:
    print(x[0]*x[1]*x[2])
elif len(x)==4:
    print(x[0]*x[1]*x[2]+x[0]*x[1]*x[3]+x[0]*x[2]*x[3]+x[1]*x[2]*x[3])
else:
    print(x[0]*x[1]*x[2]+x[0]*x[1]*x[3]+x[0]*x[2]*x[3]+x[1]*x[2]*x[3]
         +x[0]*x[1]*x[4]+x[0]*x[2]*x[4]+x[1]*x[2]*x[4]
         +x[2]*x[3]*x[4]+x[1]*x[3]*x[4]+x[0]*x[3]*x[4])

Submission status: Accepted

Solution code:
n = int(input())
a = []
for i in range(n):
    a.append(input())
b = 0
c = 0
d = 0
e = 0
f = 0
for i in range(n):
    if a[i][0] =='M':
        b += 1
    elif a[i][0] =='A':
        c += 1
    elif a[i][0] =='R':
        d += 1
    elif a[i][0] =='C':
        e += 1
    elif a[i][0] =='H':
        f += 1
print(b*c*d+b*c*e+b*c*f+b*d*e+b*d*f+b*e*f+c*d*e+c*d*f+c*e*f+d*e*f)

Submission status: Accepted

Solution code:
from itertools import combinations

names = [input() for _ in range(int(input()))]
march = [list(filter(lambda x: x[0] == c, names)) for c in 'MARCH']
ways = 0
for combo in combinations(march, 3):
    ways += len(combo[0]) * len(combo[1]) * len(combo[2])
print(ways)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
ans=0
cnt=[0,0,0,0,0]

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

if cnt.count(0)<=2:
    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:
n = int(input())

d = {"M":0,"R":0,"A":0,"C":0,"H":0}
S = []
num = 0

for i in range(n):
    S.append(input())


for s in S:
    #キーの中にs[0]の文字があるときのみ
    if s[0] in list(d.keys()):
        d[s[0]] += 1



for al1 in list(d.keys()):
    for al2 in list(d.keys()):
        for al3 in list(d.keys()):
            if al1 != al2 and al1 != al3 and al2 != al3:
                num += d[al1]*d[al2]*d[al3]

print(int(num/6))

Submission status: Accepted

Solution code:
N = int(input())
S = []
temp = 0

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

for i in range(N):
    S.append(input())

for s in S:
    if s[0] in list(cnt.keys()):
        cnt[s[0]] += 1

for i in list(cnt.keys()):
    for j in list(cnt.keys()):
        for k in list(cnt.keys()):
            if i != j and j != k and i != k:
                temp += cnt[i]*cnt[j]*cnt[k]

print(int(temp/6))

Submission status: Accepted

Solution code:
N = int(input())
A = []
for i in range(N):
    A.append(input())
k = 0
c = [ 0,0,0,0,0]
for i in A:
  if i[0] == 'M':
    c[0] += 1
  if i[0] == 'A':
    c[1] += 1
  if i[0] == 'R':
    c[2] += 1
  if i[0] == 'C':
    c[3] += 1
  if i[0] == 'H':
    c[4] += 1


if not c.count(0) >= 3:
  k += 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] 

print(k)

Submission status: Accepted

Solution code:
from itertools import combinations

n = int(input())
names = {"M":0, "A":0, "R":0, "C":0, "H":0}
for _ in range(n):
    name = input()
    if name[0] in names.keys():
        names[name[0]] += 1

patterns = list(combinations(names.keys(), 3))

count = 0
for pattern in patterns:
    count += names[pattern[0]] * names[pattern[1]] * names[pattern[2]]

print(count)

Submission status: Accepted

Solution code:
def solve():
    N = int(input())

    dic = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
    for i in range(N):
        name = input()
        if name[0] in list('MARCH'):
            dic[name[0]] += 1
    ans = 0
    march = 'MARCH'
    for i in range(5):
        for j in range(i+1, 5):
            for k in range(j+1, 5):
                ans += dic[march[i]] * dic[march[j]] * dic[march[k]]
    print(ans)


solve()

Submission status: Accepted

Solution code:
N= int(input())
M=0
A=0
R=0
C=0
H=0
for i in range (N):
    a=(input())
    a_split=list(a)
    if a_split[0]=='M':
        M=M+1
    elif a_split[0]=='A':
        A=A+1
    elif a_split[0]=='R':
        R=R+1
    elif a_split[0]=='C':
        C=C+1
    elif a_split[0]=='H':
        H=H+1

count=0
#M
count=count+M*A*R
count=count+M*A*C
count=count+M*A*H

#A
count=count+M*R*C
count=count+M*R*H
count=count+M*C*H

count=count+A*R*C
count=count+A*R*H
count=count+A*C*H

count=count+R*C*H

print (count)

Submission status: Accepted

Solution code:
n = int(input())

march = [0 for i in range(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

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

print(c)