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:
from collections import Counter
import itertools
N = int(input())
S = []
for i in range(N):
    tmp = list(input())
    S.append(tmp[0])
Ini = Counter(S)
seq = ['M','A','R','C','H']
COMB = list(itertools.combinations(seq, 3))
sum = 0
for i in range(len(COMB)):
    sum += Ini[str(COMB[i][0])] * Ini[str(COMB[i][1])] * Ini[str(COMB[i][2])]
print(sum)

Submission status: Accepted

Solution code:
import itertools

N = int(input())

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

MARCH = []
initials = []

for _ in range(N):
    s = input()
    initials.append(s[0])

for x in march:
    MARCH.append(initials.count(x))

L = [i for i in range(5)]
C = itertools.combinations(L, 3)

ans = 0

for c in C:
    ans += MARCH[c[0]] * MARCH[c[1]] * MARCH[c[2]]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for i,j,k in combinations('MARCH',3):
    ans += ctr[i]*ctr[j]*ctr[k]
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
from itertools import combinations
N = int(input())
S = [input()[0]  for i in range(N)]
dic ={'M':S.count('M'),'A':S.count('A'),'R':S.count('R'),'C':S.count('C'),'H':S.count('H')}
cnt=0
for i,j,k in combinations(dic.values(),3):
    cnt+=i*j*k
print(cnt)

Submission status: Accepted

Solution code:
def combination_list(data, r):
    if r == 0 or r > len(data):
        return []

    result = []
    _combination_list(data, r, 0, [], result)
    return result


def _combination_list(data, r, start, progress, result):
    if r == 0:
        result.append(progress)
        return

    for i in range(start, len(data)):
        _combination_list(data, r - 1, i + 1, progress + [data[i]], result)


n = int(input())

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

# print(names)

l = list(names.values())
# print(l)

combis = combination_list(l, 3)

count = 0
for combi in combis:
    val = 1
    for i in combi:
        val *= i

    count += val

print(count)

Submission status: Accepted

Solution code:
from itertools import combinations

import sys
sdin = sys.stdin.readline

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

# marchで始まっている人をカウント
m = len([si for si in s if si.startswith("M")])
a = len([si for si in s if si.startswith("A")])
r = len([si for si in s if si.startswith("R")])
c = len([si for si in s if si.startswith("C")])
h = len([si for si in s if si.startswith("H")])

cmb = []
for char in [m,a,r,c,h]:
    if char > 0:
        cmb.append(char)

res = 0
cands = list(combinations(cmb,3))
for x,y,z in cands:
    res += x*y*z
    
print(res)

Submission status: Accepted

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

R = [i for i in range(5)]
rec = 0
for a, b, c in itertools.combinations(R, 3):
    rec += q[a] * q[b] * q[c]

print(rec)

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
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+r*c*h+a*c*h
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = [0, 0, 0, 0, 0]
for i in range(N):
  S = input()
  if S[0] =='M':
    A[0] += 1
  if S[0] =='A':
    A[1] += 1
  if S[0] =='R':
    A[2] += 1
  if S[0] =='C':
    A[3] += 1
  if S[0] =='H':
    A[4] += 1
ans = 0
for i in range(5):
  for j in range(i+1, 5):
    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 _ in range(N)]

a = [0] * 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

S = 0
for k in range(5):
    for l in range(k + 1, 5):
        for m in range(l + 1, 5):
            S += a[k] * a[l] * a[m]

print(S)

Submission status: Accepted

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

march = ['M','A','R','C','H']
dp = [0]*5

for s in S:
    for i in range(5):
        if march[i] == s[0]:
            dp[i] += 1

ans = 0
for x in range(5):
    for y in range(x+1, 5):
        for z in range(y+1, 5):
            ans += dp[x] * dp[y] * dp[z]

print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
N = int(input())
cntA = [0] * 5
str = "MARCH"

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

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

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


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

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

a = [0]*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
        
S=0
for k in range(5):
    for l in range(k+1, 5):
        for m in range(l+1, 5):
            S += a[k]*a[l]*a[m]
            
print(S)

Submission status: Accepted

Solution code:
import itertools
n = int(input())
march = [0]*5
for _ in range(n):
    s = input()[0]
    if s=='M':
        march[0] += 1
    if s=='A':
        march[1] += 1
    if s=='R':
        march[2] += 1
    if s=='C':
        march[3] += 1
    if s=='H':
        march[4] += 1
res = 0
for l in list(itertools.combinations(range(5),3)):
    res += march[l[0]] * march[l[1]] * march[l[2]]
print(res)

Submission status: Accepted

Solution code:
N = int(input())
dic = [0]*128
for _ in range(N): dic[ord(input()[0])] += 1
M,A,R,C,H = [dic[ord(x)] for x in list('MARCH')]
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
N = int(input())
d = [0]*128
for _ in range(N): d[ord(input()[0])] += 1
print(sum([d[ord(p0)]*d[ord(p1)]*d[ord(p2)] for p0,p1,p2 in combinations('MARCH', 3)]))

Submission status: Accepted

Solution code:
from itertools import combinations
from collections import Counter
N = int(input())
S = Counter()
for _ in range(N):
  S[input()[0]] += 1
print(sum([S[p0]*S[p1]*S[p2] for p0,p1,p2 in combinations('MARCH', 3)]))
quit()

Submission status: Accepted

Solution code:
def main():
    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
        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)
main()

Submission status: Accepted

Solution code:
n = int(input())
s = [input() for _ in range(n)]
p = [(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)]
march = [0] * 5
for i in s:
    if i[0] == "M": march[0] += 1
    if i[0] == "A": march[1] += 1
    if i[0] == "R": march[2] += 1
    if i[0] == "C": march[3] += 1
    if i[0] == "H": march[4] += 1
ans = 0
for a, b, c in p:
    ans += march[a] * march[b] * march[c]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
char_map = {'M':0,'A':0,'R':0,'C':0,'H':0}
comb = [['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']]

for i in range(N):
    tmp_str = input()
    try:
        char_map[tmp_str[0]] += 1
    except KeyError:
        pass

result = 0
for i in comb:
    tmp = 1
    for j in i:
        tmp *= char_map[j]
    result += tmp
    
print(result)

Submission status: Accepted

Solution code:
n = int(input())

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

for _ in range(n):
    temp = list(input())
    if temp[0] == 'M':
        a[0] += 1
    elif temp[0] == 'A':
        a[1] += 1
    elif temp[0] == 'R':
        a[2] += 1
    elif temp[0] == 'C':
        a[3] += 1
    elif temp[0] == '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:
# -*- coding: utf-8 -*-
"""
Created on Wed Aug  8 22:52:39 2018

@author: Yuki
"""

N = int(input())
S = {}
S['M'] = []
S['A'] = []
S['R'] = []
S['C'] = []
S['H'] = []

for i in range(N):
    tmp = input()
    if tmp[0] == 'M':
        S['M'].append(tmp)
    elif tmp[0] == 'A':
        S['A'].append(tmp)
    elif tmp[0] == 'R':
        S['R'].append(tmp)
    elif tmp[0] == 'C':
        S['C'].append(tmp)
    elif tmp[0] == 'H':
        S['H'].append(tmp)

def get_factorial(number = 2):
    if number == 1:
        return 1
    else:
        return number * get_factorial(number-1)
def get_initial_from_2sin(string):
    res = []
    if string[0] == '1':
        res.append('M')
    if string[1] == '1':
        res.append('A')
    if string[2] == '1':
        res.append('R')
    if string[3] == '1':
        res.append('C')
    if string[4] == '1':
        res.append('H')
    return res

        
res_cnt = 0
for i in range(2**5):
    tmp = bin(i)[2:].zfill(5)
    result = get_initial_from_2sin(tmp)
    if len(result) == 3:
        res_cnt += len(S[result[0]]) * len(S[result[1]]) * len(S[result[2]])
print(res_cnt)

Submission status: Accepted

Solution code:
import itertools

N = int(input())
# 1 <=    N <= 10^5
# 1 <= |Si| <= 10

count = [0, 0, 0, 0, 0]
char = ['M', 'A', 'R', 'C', 'H']
S = []
for n in range(N):
    s = input()
    S.append(s)
    for i, c in enumerate(char):
        if s[0] == c:
            count[i] += 1
        
# print(march)

# Choose three letters from MARCH.
# Number of combinations with the three letters are the multiplication of the sizes.
itr = itertools.combinations(range(5), 3)

total = 0
for cmb in itr:
    total += count[cmb[0]] * count[cmb[1]] * count[cmb[2]]

print(total)

Submission status: Accepted

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

list_march=[]
march="MARCH"
for i in march:
    for j in march:
        if j==i: break
        for k in march:
            if k==j: break
            list_march.append([i, j, k])

list_b=[[],[],[],[],[]]
for i in S:
    for j, k in enumerate("MARCH"):
        if i[0]==k:
            list_b[j].append(i)

ans=0
for mar in list_march:
    list_123=[]
    for j in range(3):
        for k, m in enumerate(march):
            if mar[j]==m:
                list_123.append(len(list_b[k]))
    ans+=list_123[0]*list_123[1]*list_123[2]
print(ans)

Submission status: Accepted

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

list_march=[]
march=['m', 'a', 'r', 'c', 'h']
for i in march:
    for j in march:
        if j==i: break
        for k in march:
            if k==j: break
            if i!=j and j!=k and k!=i:
                list_march.append([i, j, k])

list_b=[[],[],[],[],[]]
for i in S:
    if i[0]=='M':
        list_b[0].append(i)
    elif i[0]=='A':
        list_b[1].append(i)
    elif i[0]=='R':
        list_b[2].append(i)
    elif i[0]=='C':
        list_b[3].append(i)
    elif i[0]=='H':
        list_b[4].append(i)

ans=0
for mar in list_march:
    list_xyz=[]
    for j in range(0,3):
        for k, m in enumerate(march):
            if mar[j]==m:
                list_xyz.append(len(list_b[k]))
    ans+=list_xyz[0]*list_xyz[1]*list_xyz[2]
print(ans)

Submission status: Accepted

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

t = [[s_i[0] for s_i in s].count(c) for c in "MARCH"]

sum_num = 0
for i in range(5):
	t_dummy_i = list(tuple(t))
	i_num = t_dummy_i.pop(i)
	for j in range(4):
		t_dummy_j = list(tuple(t_dummy_i))
		j_num = t_dummy_j.pop(j)
		for k in range(3):
			sum_num += i_num * j_num * t_dummy_j[k]

print(sum_num//6)

Submission status: Accepted

Solution code:
N = int(input())
names = {}

ms = 'MARCH'

for i in list(ms) :
    names[i] = 0
    
for i in range(N) :
    s = input()
    if s[0] in list(ms) :
        names[s[0]] += 1
        
perms = []
def perm(s, idx, n) :
    if n == 3 :
        perms.append(s)
    else :
        if idx < len(ms) :
            perm(s + ms[idx], idx + 1, n + 1)
            perm(s, idx + 1, n)        
perm("", 0, 0)

sum_over = 0
for p in perms :
    sum_over += names[p[0]] * names[p[1]] * names[p[2]]
    
print(sum_over)

Submission status: Accepted

Solution code:
from itertools import combinations
N=int(input())
d={}
for _ in range(N):
  s=input()
  if not s[0] in ["M","A","R","C","H"]:continue 
  if not s[0] in d:
    d[s[0]]=1
  else:
    d[s[0]]+=1
res=0
for i in combinations(d.keys(),3):
  res+=d[i[0]]*d[i[1]]*d[i[2]]
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools

N = int(input())
S = "MARCH"
dic = {s: 0 for s in S}
for s in filter(lambda s: s in S, [input()[0] for _ in range(N)]):
    dic[s] += 1

print(sum([dic[a] * dic[b] * dic[c]
           for (a, b, c) in itertools.product(S, repeat=3) if a < b < c]))

Submission status: Accepted

Solution code:
N = int(input())
S = "MARCH"
dic = {s:0 for s in S}
for _ in range(N):
    s = input()[0]
    if s in S:
        dic[s] += 1
        
print(sum([dic[a] * dic[b] * dic[c] for a in S for b in S for c in S if a < b < c]))

Submission status: Accepted

Solution code:
N = int(input())
S = "ACHMR"
dic = {s:0 for s in S}
for _ in range(N):
    s = input()[0]
    if s in S:
        dic[s] += 1
        
        
res = 0
for s0 in S:
    for s1 in S:
        if s1 <= s0:
            continue
        for s2 in S:
            if s2 <= s1 or s2 <= s0:
                continue
            res += dic[s0] * dic[s1] * dic[s2]    
print(res)

Submission status: Accepted

Solution code:
N = int(input())
S = "MARCH"
dic = {s:0 for s in "MARCH"}
for _ in range(N):
    s = input()[0]
    if s in "MARCH":
        dic[s] += 1
        
        
res = 0
for i0 in range(3):
    s0 = S[i0]
    if dic[s0] == 0:
        continue
    for i1 in range(i0 + 1, 4):
        s1 = S[i1]
        if dic[s1] == 0:
            continue
        if s1 == s0:
            continue
        for i2 in range(i1 + 1, 5):
            s2 = S[i2]
            if dic[s2] == 0:
                continue
            if s2 in (s0, s1):
                continue
            res += dic[s0] * dic[s1] * dic[s2]    
print(res)

Submission status: Accepted

Solution code:
from itertools import combinations

n = int(input())
s = [input() for _ in range(n)]
march = list('MARCH')
d = {x:0 for x in march}
for x in s:
    if x[0] in march:
        d[x[0]] += 1
l = [v for v in d.values() if v > 0]

ans = 0
if len(l) >= 3:
    for gp in combinations(l, 3):
        buf = 1
        for x in gp:
            buf *= x
        ans += buf
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import Counter
from itertools import combinations

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

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

Submission status: Accepted

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

def main():
    n = int(input())
    name_list = []

    for i in range(n):
        name = input()
        if name[0] in ['M', 'A', 'R', 'C', 'H']:
            name_list.append(name[0])
    
    name_set = set(name_list)
    if len(name_set) <= 2:
        combi = 0
    else:
        name_combi = list(itertools.combinations(name_set, 3))
        combi = 0
        for i in name_combi:
            combi += name_list.count(i[0]) * name_list.count(i[1]) * name_list.count(i[2])
    
    print(combi)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
T = [input() for i in range(N)]
S = [x[:1] for x in T]
CS = Counter(S)
A = [CS['M'],CS['A'],CS['R'],CS['C'],CS['H']]
ans = 0
for i in range(0,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()[0] for i in range(N)]
M = S.count('M')
A = S.count('A')
R = S.count('R')
C = S.count('C')
H = S.count('H')
print(M*A*R + M*A*C + M*A*H + M*R*C + M*R*H + M*C*H + A*R*C + A*R*H + A*C*H + R*C*H)

Submission status: Accepted

Solution code:
n = int(input())

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

hj = []
hj.append(s.count('M'))
hj.append(s.count('A'))
hj.append(s.count('R'))
hj.append(s.count('C'))
hj.append(s.count('H'))

c = 0

for i in range(0,3):
    for j in range(i+1,4):
        for h in range(j+1,5):
            c += hj[i]*hj[j]*hj[h]
print(c)

Submission status: Accepted

Solution code:
from itertools import combinations

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

M = len(list(filter(lambda x: x[0] == 'M', S)))
A = len(list(filter(lambda x: x[0] == 'A', S)))
R = len(list(filter(lambda x: x[0] == 'R', S)))
C = len(list(filter(lambda x: x[0] == 'C', S)))
H = len(list(filter(lambda x: x[0] == 'H', S)))

march = ['M', 'A', 'R', 'C', 'H']
ans = 0
for a, b, c in combinations(march, 3):
    ans += eval(a) * eval(b) * eval(c)

print(ans)

Submission status: Accepted

Solution code:
namelist="MARCH"
N=int(input())
bucket=[0,0,0,0,0]

for i in range(N):
	msg=input()
	for k in range(5):
		if(msg[0]==namelist[k]):
			bucket[k]+=1;

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

Submission status: Accepted

Solution code:
N = int(input())
_dict = [0 for i in range(128)]
for i in range(N):
    s = input()
    _dict[ord(s[0])] += 1

march = ['M', 'A', 'R', 'C', 'H']
ord_march = [ord(march_i) for march_i in march]

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

print(ans)

Submission status: Accepted

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

npS = np.array(S)
march = np.zeros(5,dtype = int)
tmp = 'MARCH'

for i in range(5):
    march[i] = np.sum(npS == tmp[i])

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


print(ans)

Submission status: Accepted

Solution code:
n = int(input())

l = ['M', 'A', 'R', 'C', 'H']
nl = {'M': [], 'A': [], 'R': [], 'C': [], 'H': []}
for _ in range(n):
    name = input()
    if name[0] in l:
        nl[name[0]].append(name)

from itertools import combinations
ans = 0
for comb in combinations(l, 3):
    a,b,c = comb
    ans += len(nl[a]) * len(nl[b]) * len(nl[c])
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    ss = [input() for _ in range(n)]

    m = [0, 0, 0, 0, 0]
    for s in ss:
        try:
           m['MARCH'.index(s[0])] += 1
        except ValueError:
            pass

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

    print(c)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
jop=[0]*5
for i in range(n):
    lop=input()
    if lop[0]=='M':
        jop[0]+=1
    elif lop[0]=='A':
        jop[1]+=1
    elif lop[0]=='R':
        jop[2]+=1
    elif lop[0]=='C':
        jop[3]+=1
    elif lop[0]=='H':
        jop[4]+=1
kip=0
for j in range(3):
    for k in range(j+1,5):
        for l in range(k+1,5):
            kip+=jop[j]*jop[k]*jop[l]
print(kip)

Submission status: Accepted

Solution code:
x=int(input())
y=[]
for i in range(0,x):
  y.append(str(input()))
m=0
a=0
r=0
c=0
h=0

for i in y:
  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

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(s)

Submission status: Accepted

Solution code:
n=int(input())
march=[]
for i in range(n):
    x=input()
    march.append(x[0])

m=march.count('M')
a=march.count('A')
r=march.count('R')
c=march.count('C')
h=march.count('H')
ways=m*a*r+m*a*c+m*a*h+m*r*c+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h+m*r*h
print(ways)

Submission status: Accepted

Solution code:
n = int(input())
cnt = {c:0 for c in 'MARCH'} # how many 

for i in range(n):
    s = input()
    if s[0] in 'MARCH':
        cnt[s[0]] += 1

# all possible combinations
ret = cnt['M']*cnt['A']* (cnt['R'] + cnt['C'] + cnt['H']) \
      + cnt['M']*cnt['R']* (cnt['C'] + cnt['H'])  + cnt['M']*cnt['C']*cnt['H'] \
      + cnt['A']*cnt['R']* (cnt['C'] + cnt['H'])  + cnt['A']*cnt['C']*cnt['H'] \
      + cnt['R']*cnt['C']*cnt['H']
    
print(ret)

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


totalM = M*A*R + M*A*C + M*A*H + M*R*C + M*R*H + M*C*H
totalA = A*R*C + A*R*H + A*C*H
totalR = R*C*H
total = totalM + totalA + totalR
print(total)

Submission status: Accepted

Solution code:
n = int(input())
s = [input() for i in range(n)]
m,a,r,c,h,el = [],[],[],[],[],[]
cnt=0
for i in range(n):
    if s[i][0]=='M': m.append(s[i])
    elif s[i][0]=='A': a.append(s[i])
    elif s[i][0]=='R': r.append(s[i])
    elif s[i][0]=='C': c.append(s[i])
    elif s[i][0]=='H': h.append(s[i])
    else:el.append(s[i])
march =[len(x) for x in [m,a,r,c,h]]
for i in range(5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            cnt += march[i]*march[j]*march[k]
print(cnt)

Submission status: Accepted

Solution code:
from itertools import combinations

n = int(input())
s = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for _ in range(n):
	head = list(input())[0]
	if head == "M" or head == "A" or head == "R" or head == "C" or head == "H":
		s[head] += 1

ans = 0

for a, b, c in combinations(s.items(), 3):
	ans += a[1] * b[1] * c[1]

print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
N = int(input())
S = set([input() for i8 in range(N)])
march = dict(zip("MARCH",[0,0,0,0,0]))

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

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

Submission status: Accepted

Solution code:
from collections import Counter
from itertools import combinations
N = int(input())
S = [input() for _ in range(N)]
S = Counter([i[0] for i in S if i[0] in "MARCH"])
if len(S) < 3:
    print(0)
    exit()
count = 0
for x,y,z in combinations(S.keys(),3):
    count += S[x] * S[y] * S[z]
print(count)

Submission status: Accepted

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

nameCount = {"M":0, "A":0, "R":0, "C":0, "H":0}
for i in nameList:
    a = list(i)
    try:
        nameCount[a[0]]+=1
    except:
        pass

nameCountList = []
for i in ["M","A","R","C","H"]:
    nameCountList.append(nameCount[i])


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

print(x)

Submission status: Accepted

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

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

letters = 'MARCH'
counts = Counter(c for c in name_starts if c in letters)

print(sum(reduce(mul, (counts[c] for c in combo)) for combo in combinations(letters, 3)))

Submission status: Accepted

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

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

for i in range(n):
	s = raw_input()
	if d.has_key(s[0]):
		d[s[0]] += 1

count = 0

for comb in list(itertools.combinations(d.keys(),3)):
	count += d[comb[0]]* d[comb[1]]*d[comb[2]]

print count

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 13 17:57:26 2018


N人の名前から 以下の条件を満たす3人を選ぶ

•全ての人の名前が 'M','A','R','C','H' のどれかから始まっている
•同じ文字から始まる名前を持つ人が複数いない

※選ぶ順番は問わない

何通り存在するか

入力
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO

出力
7


@author: Yuya
"""

N = int(input())

n = [0, 0, 0, 0, 0]




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

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

Submission status: Accepted

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

for i in range(N):
 S=input()
 for j in range(5):
  if S[0]==head[j]:
   count[j]+=1


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

print(answer)

Submission status: Accepted

Solution code:
N = int(input())
s = []
for i in range(N):
    s.append(input())
m = 0
a = 0
r = 0
c = 0
h = 0
for person in s:
  if person[0]=='M':
    m += 1
  elif person[0]=='A':
    a += 1
  elif person[0]=='R':
    r += 1
  elif person[0]=='C':
    c += 1
  elif person[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(int(ans))

Submission status: Accepted

Solution code:
head="MARCH"
cnt=[0]*5
n=int(input())
# 頭文字MARCHで始まった人がそれぞれ何人か調べる
for i in range(n):
    s=input()
    for j in range(5):
        if s[0]==head[j]:
            cnt[j]+=1
# 全探索で足し合わせる
ret=0
for i in range(5):
    for j in range(i):
        for k in range(j):
            ret+=cnt[i]*cnt[j]*cnt[k]
print(ret)

Submission status: Accepted

Solution code:
n = int(input())
dic = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
for i in range(n):
    s = input()[0]
    if s in dic.keys():
        dic[s] = dic[s] + 1
ans = 0
for i in dic.keys():
    for j in dic.keys():
        if i == j:
            break
        for k in dic.keys():
            if j == k or k == i:
                break
            ans += dic[i] * dic[j] * dic[k]
print(ans)