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

Solution (Python):
from itertools import combinations

import sys
sdin = sys.stdin.readline

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


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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):


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

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)]))

Solution (Python):
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()

Solution (Python):
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()

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):

"""
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)

Solution (Python):
import itertools

N = int(input())



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
        




itr = itertools.combinations(range(5), 3)

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

print(total)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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]))

Solution (Python):
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]))

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):

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

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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()

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
n = int(input())
cnt = {c:0 for c in 'MARCH'} 

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


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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)))

Solution (Python):
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

Solution (Python):

"""
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)

Solution (Python):
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)

Solution (Python):
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))

Solution (Python):
head="MARCH"
cnt=[0]*5
n=int(input())

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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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]

for j in range(3):
    
    for k in range(j+1,4):
        
            for l in range(k+1,5):
                
                count=count+list1[j]*list1[k]*list1[l]
print(count)

Solution (Python):


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


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)

Solution (Python):
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())

Solution (Python):
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)

Solution (Python):
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)