Problem:


Score : 300 points

Problem Statement

There are N people. The name of the i-th person is S_i.

We would like to choose three people so that the following conditions are met:

The name of every chosen person begins with M, A, R, C or H.

There are no multiple people whose names begin with the same letter.

How many such ways are there to choose three people, disregarding order?

Note that the answer may not fit into a 32-bit integer type.

Constraints

1 \leq N \leq 10^5

S_i consists of uppercase English letters.

1 \leq |S_i| \leq 10

S_i \neq S_j (i \neq j)

Input

Input is given from Standard Input in the following format:

N
S_1
:
S_N

Output

If there are x ways to choose three people so that the given conditions are met, print x.

Sample Input 1

5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI

Sample Output 1

2

We can choose three people with the following names:

MASHIKE, RUMOI, HABORO

MASHIKE, RUMOI, HOROKANAI

Thus, we have two ways.

Sample Input 2

4
ZZ
ZZZ
Z
ZZZZZZZZZZ

Sample Output 2

0

Note that there may be no ways to choose three people so that the given conditions are met.

Sample Input 3

5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO

Sample Output 3

7



Sample input:
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI


Sample output:
2

Submission status: Accepted

Solution code:
import numpy as np
import scipy as sp
from collections import Counter

N = int(input())
S = []
for _ in range(N):
    a = input()[0]
    if a in {'M','A','R','C','H'}:
        S.append(a)

a = Counter(S)

num = list(a.values())

l = len(num)
s = 0
for i in range(l-2):
    for j in range(i+1,l-1):
        for k in range(j+1,l):
            s += num[i] * num[j] * num[k]
print(s)

Submission status: Accepted

Solution code:
import itertools

N = int(input())

num = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
for i in range(N):
    S = input()
    if S[0] in num:
        num[S[0]] += 1

vs = num.values()

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

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env pypy3


import collections
import itertools


def solve(names):
    ctr = collections.Counter(name[0] for name in names)
    res = 0
    for x, y, z in itertools.combinations("MARCH", 3):
        res += ctr[x] * ctr[y] * ctr[z]
    return res


def main():
    names = [input() for _ in range(int(input()))]
    print(solve(names))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
b = []
c = []
answer = 0
for i in range(0,5):
    c.append(int(0))
for i in range(0,n):
    b.append(input())
for i in range(0,n):
    if b[i][0] == 'M':
        c[0] += 1
    else:
        if b[i][0] == 'A':
            c[1] += 1
        else:
            if b[i][0] == 'R':
                c[2] += 1
            else:
                if b[i][0] == 'C':
                    c[3] += 1
                else:
                    if b[i][0] == 'H':
                        c[4] += 1
for i in range(0,3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            answer += c[i]*c[j]*c[k]
print(answer)

Submission status: Accepted

Solution code:
N=int(input())
M,A,R,C,H=0,0,0,0,0
S=""
for i in range(N):
    S=input()
    if S[0]=="M":
        M+=1
        continue
    if S[0]=="A":
        A+=1
        continue
    if S[0]=="R":
        R+=1
        continue
    if S[0]=="C":
        C+=1
        continue
    if S[0]=="H":
        H+=1
        continue
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:
# standard library# {{{
import sys
import os
import time
import re
from pydoc import help
import string
import math
import numpy as np
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools
sys.setrecursionlimit(10**7)
inf = 10**20
gosa = 1.0 / 10**10
mod = 10**9+7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]
# }}}


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

    S = [0]*5
    for s in range(N):
        s = input()
        if s[0] == 'M':
            S[0] += 1
        if s[0] == 'A':
            S[1] += 1
        if s[0] == 'R':
            S[2] += 1
        if s[0] == 'C':
            S[3] += 1
        if s[0] == 'H':
            S[4] += 1

    res = 0
    for c in itertools.combinations([0,1,2,3,4], 3):
        i,j,k = c
        res += S[i] * S[j] * S[k]

    print(res)

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
def c_march(N, S):
    from collections import defaultdict
    from itertools import combinations
    import math
    count = defaultdict(int)
    for s in S:
        if s[0] in 'MARCH':
            count[s[0]] += 1
    kind = len(count)
    ans = 0
    if len(count) <= 2:
        return 0
    else:
        ans = 0
        s = ''
        for k, v in count.items():
            s += k
        string = combinations(s, 3)
        for s in string:
            tmp = 1
            for c in s:
                tmp *= count[c]
            ans += tmp
    return ans

N = int(input())
S = [input().strip() for _ in range(N)]
print(c_march(N, S))

Submission status: Accepted

Solution code:
import sys,collections;sys.setrecursionlimit(10**7)
import itertools
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

n = I()
d = collections.defaultdict(int)
for _ in range(n):
    s = S()[0]
    if list("MARCH").count(s) > 0:
        d[s] += 1
if len(d) < 3:
    print(0)
    exit()
c = list(itertools.combinations(d.items(),3))
sum = 0
for e in c:
    sum += e[0][1]*e[1][1]*e[2][1]
print(sum)

Submission status: Accepted

Solution code:
from collections import defaultdict
if __name__ == "__main__":
    dic = defaultdict(int)
    N = int(input())
    for i in range(N):
        S = input()
        if S[0] in "M A R C H":
            dic[S[0]] += 1
    res = []
    if len(dic) < 3:
        print(0)
        exit(0)
    value = 1
    for key in dic:
        val = dic[key]
        res.append(val)
        value *= val
    if len(dic) == 3:
        print(value)
        exit(0)
    result = 0
    if len(dic) == 4:
        for i in res:
            result += value // i
    if len(dic) == 5:
        for i in range(len(res)):
            for j in range(i + 1, len(res)):
                result += value // (res[i] * res[j])
    print(result)

Submission status: Accepted

Solution code:
import itertools

def name_count(names):
    counter = [0,0,0,0,0]
    capitals = ["M", "A", "R", "C", "H"]
    for name in names:
        for i in range(5):
            if name[0] == capitals[i]:
                counter[i] += 1
    return counter
    
n = int(input())

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

name_counter = name_count(names)

cnt = 0
for comb in itertools.combinations(range(5), 3):
    temp = 1
    for i in comb:
        temp *= name_counter[i]
    cnt += temp

print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
h = [0 for _ in range(5)]

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

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

print(ans)

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    N = int(input())
    M = []
    A = []
    R = []
    C = []
    H = []
    for i in range(N):
        buf = str(input())
        if buf[0] == 'M':
            M.append(buf)
        elif buf[0] == 'A':
            A.append(buf)
        elif buf[0] == 'R':
            R.append(buf)
        elif buf[0] == 'C':
            C.append(buf)
        elif buf[0] == 'H':
            H.append(buf)
    M_cnt = len(M)
    A_cnt = len(A)
    R_cnt = len(R)
    C_cnt = len(C)
    H_cnt = len(H)
#    obj = {'M':M_cnt, 'A':A_cnt, 'R':R_cnt, 'C':C_cnt, 'H':H_cnt}
    cnt =  M_cnt * A_cnt * R_cnt + \
           M_cnt * A_cnt * C_cnt + \
           M_cnt * A_cnt * H_cnt + \
           M_cnt * R_cnt * C_cnt + \
           M_cnt * R_cnt * H_cnt + \
           M_cnt * C_cnt * H_cnt + \
           A_cnt * R_cnt * C_cnt + \
           A_cnt * R_cnt * H_cnt + \
           A_cnt * C_cnt * H_cnt + \
           R_cnt * C_cnt * H_cnt
    print(cnt)

Submission status: Accepted

Solution code:

N = int(input())

ans = 0
m = 0
a = 0
r = 0
c = 0
h = 0
mb = False
ab = False
rb = False
cb = False
hb = False

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

num = 0
if mb:
    num += 1
if ab:
    num += 1
if rb:
    num += 1
if cb:
    num += 1
if hb:
    num += 1

if num < 3:
    print(0)
else:
    ans += m*a*r
    ans += m*a*c
    ans += m * a * h
    ans += m*r*c
    ans += m * r * h
    ans += m*c*h
    ans += a*r*c
    ans += a*c*h
    ans += a * r * h
    ans += r*c*h

    print(ans)

Submission status: Accepted

Solution code:
import itertools
from collections import defaultdict

if __name__ == '__main__':
    n = int(input())
    names = [input() for _ in range(n)]

    first_char_dict = defaultdict(int)
    for name in names:
        if name[0] not in set("MARCH"):
            continue

        first_char_dict[name[0]] += 1

    chars = set(first_char_dict.keys())
    # 3文字未満なら組み合わせはないので0
    if len(chars) < 3:
        print(0)
        exit(0)

    n_combinations = 0
    for c in itertools.combinations(chars, 3):
        n_combinations += first_char_dict[c[0]] * first_char_dict[c[1]] * \
                          first_char_dict[c[2]]

    print(n_combinations)

Submission status: Accepted

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

List = []
indexList = ['M', 'A', 'R', 'C', 'H']
for index in indexList:
    temp = []
    for i in range(N):
        if S[i][0] == index:
            temp.append(S[i])
    List.append(temp)
ans = 0
ans += len(List[0])*len(List[1])*len(List[2])
ans += len(List[0])*len(List[1])*len(List[3])
ans += len(List[0])*len(List[1])*len(List[4])
ans += len(List[0])*len(List[2])*len(List[3])
ans += len(List[0])*len(List[2])*len(List[4])
ans += len(List[0])*len(List[3])*len(List[4])
ans += len(List[1])*len(List[2])*len(List[3])
ans += len(List[1])*len(List[2])*len(List[4])
ans += len(List[1])*len(List[3])*len(List[4])
ans += len(List[2])*len(List[3])*len(List[4])
print(ans)

Submission status: Accepted

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

cnt = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
for si in s:
  if si[0] in cnt:
    cnt[si[0]] += 1

res = 0
res += cnt['M'] * cnt['A'] * cnt['R']
res += cnt['M'] * cnt['A'] * cnt['C']
res += cnt['M'] * cnt['A'] * cnt['H']
res += cnt['M'] * cnt['R'] * cnt['C']
res += cnt['M'] * cnt['R'] * cnt['H']
res += cnt['M'] * cnt['C'] * cnt['H']
res += cnt['A'] * cnt['R'] * cnt['C']
res += cnt['A'] * cnt['R'] * cnt['H']
res += cnt['A'] * cnt['C'] * cnt['H']
res += cnt['R'] * cnt['C'] * cnt['H']

print(res)

Submission status: Accepted

Solution code:
from collections import defaultdict
import itertools

N=input()
l=["M","A","R","C","H"]
C=defaultdict(lambda: 0)

for i in range(N):
	S=raw_input()
	if S[0] in l:
		C[S[0]]+=1

P=list(itertools.combinations(C.keys(),3))

ans=0
for x,y,z in P:
	ans+=C[x]*C[y]*C[z]

print ans

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import combinations

#
N = int(input())
cnt = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
for i in range(N):
    name = input()
    if name[0] in cnt:
        cnt[name[0]] += 1

#
letters = [_ for _ in 'MARCH' if cnt[_]>0]
if len(letters)<3:
    print(0)
    exit()

#
ans = 0
for combi in combinations(letters, 3):
    tmp = 1
    for i in combi:
        tmp *= cnt[i]
    ans += tmp

#
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = []
M_num = 0
A_num = 0
R_num = 0
C_num = 0
H_num = 0
ans = 0
for i in range(N):
    S.append(input())
# print(S)

for i in range(N):
    temp = str(S[i])
    if temp[0] == "M":
        M_num += 1
    elif temp[0] == "A":
        A_num += 1
    elif temp[0] == "R":
        R_num += 1
    elif temp[0] == "C":
        C_num += 1
    elif temp[0] == "H":
        H_num += 1
ans += M_num*A_num*R_num
ans += M_num*A_num*C_num
ans += M_num*A_num*H_num

ans += A_num*R_num*C_num
ans += A_num*R_num*H_num

ans += R_num*C_num*H_num
ans += M_num *C_num*H_num
ans += M_num*R_num*C_num

ans += A_num * C_num * H_num
ans += M_num * R_num * H_num
print(ans)

Submission status: Accepted

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

counts = [0] * 5
for i, c in enumerate('MARCH'):
    counts[i] = len([s for s in S if s[0] == c])

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

print(count)

Submission status: Accepted

Solution code:
n=int(input())
M=set();A=set();R=set();C=set();H=set()
for i in range(n):
    a=input()
    if a.startswith("M"):
        M.add(a)
    elif a.startswith("A"):
        A.add(a)
    elif a.startswith("R"):
        R.add(a)
    elif a.startswith("C"):
        C.add(a)
    elif a.startswith("H"):
        H.add(a)
m=len(M);a=len(A);r=len(R);c=len(C);h=len(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 = [input() for _ in range(N)]

L = [0, 0, 0, 0, 0]

for i in S:
	if i[0] == "M":
		L[0] += 1
	elif i[0] == "A":
		L[1] += 1
	elif i[0] == "R":
		L[2] += 1
	elif i[0] == "C":
		L[3] += 1
	elif i[0] == "H":
		L[4] += 1

pattern = 0

for i in range(5):
	for j in range(5):
		for k in range(5):
			if i < j < k:
				pattern += L[i] * L[j] * L[k]

print(pattern)

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 s in S:
	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
res = 0
if M * A * R != 0:
	res += M * A * R
if M * A * C != 0:
	res += M * A * C
if M * A * H != 0:
	res += M * A * H
if M * R * C != 0:
	res += M * R * C
if M * R * H != 0:
	res += M * R * H
if M * C * H != 0:
	res += M * C * H

if A * R * C != 0:
	res += A * R * C
if A * R * H != 0:
	res += A * R * H
if A * C * H != 0:
	res += A * C * H
if R * C * H != 0:
	res += R * C * H

print(res)

Submission status: Accepted

Solution code:
import collections
import itertools
from pprint import pprint as pp

N = int(input())
S = collections.defaultdict(int)
for _ in range(N):
  s = input()
  if s[0] not in ('MARCH'):
    continue
  S[s[0]] += 1
cnt = 0
for (a,b,c) in itertools.combinations('MARCH', 3):
  cnt += S[a] * S[b] * S[c]
print(cnt)

Submission status: Accepted

Solution code:
N=int(input())
Mlen=Alen=Rlen=Clen=Hlen=0

for i in range(N):
	IN=list(input())
	if IN[0]=="M":
		Mlen+=1
	elif IN[0]=="A":
		Alen+=1
	elif IN[0]=="R":
		Rlen+=1
	elif IN[0]=="C":
		Clen+=1
	elif IN[0]=="H":
		Hlen+=1
	else:
		pass

name=[Mlen,Alen,Rlen,Clen,Hlen]
ans=0

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
m=0
a=0
r=0
c=0
h=0
name = [list(str(input().split())) for i in range(n)]
for i in range(n):
    if name[i][2] == "M":
        m = m+1
    elif name[i][2] == "A":
        a = a+1
    elif name[i][2] == "R":
        r = r+1
    elif name[i][2] == "C":
        c = c+1
    elif name[i][2] == "H":
        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:
count=int(input())

data=[]
for i in range(count):
    data.append(input()[0])

counts=[0,0,0,0,0]

M=0
A=0
R=0
C=0
H=0

for i in data:
    if i=='M':
        counts[0]+=1
    if i=='A':
        counts[1]+=1
    if i=='R':
        counts[2]+=1
    if i=='C':
        counts[3]+=1
    if i=='H':
        counts[4]+=1

ans=0

select=[(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)]

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

Submission status: Accepted

Solution code:
def solve():
    n = int(input())
    s = [0,0,0,0,0]
    for i in range(n):
        name = input()
        if name[0] == 'M':
            s[0] += 1
        if name[0] == 'A':
            s[1] += 1
        if name[0] == 'R':
            s[2] += 1
        if name[0] == 'C':
            s[3] += 1
        if name[0] == 'H':
            s[4] += 1

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

    import itertools
    ans = 0

    if len(u) < 3:
        print(ans)
        return
    # print(s)
    # print(u)
    for com in itertools.combinations(u, 3):
        # print(com)
        ans += s[com[0]]*s[com[1]]*s[com[2]]
    print(ans)

solve()

Submission status: Accepted

Solution code:
n = int(input())
s = []
for i in range(n):
    s.append(str(input()))
m = 0
a = 0
r = 0
c = 0
h = 0
for i in range(n):
    if s[i].startswith("M"):
        m = m + 1
    if s[i].startswith("A"):
        a = a + 1
    if s[i].startswith("R"):
        r = r + 1
    if s[i].startswith("C"):
        c = c + 1
    if s[i].startswith("H"):
        h = h + 1
march = [m, a, r, c, h]
choice = 0
for i in range(5):
    for j in range(5):
        for k in range(5):
            if i != j and i != k and j != k:
                choice = choice + march[i] * march[j] * march[k]
print(int(choice/6))

Submission status: Accepted

Solution code:
import itertools

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

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

if num.count(0) >= 3:
    print(0)
else:
    nonzero = [n for n in num if n != 0]
    case = list(itertools.combinations(nonzero, 3))
    total = sum([tpl[0]*tpl[1]*tpl[2] for tpl in case])
    
    print(total)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
N=int(input())
S=[]
for i in range(N):
    S.append(input()[0])
    
Count=[]
Count.append(S.count("M"))
Count.append(S.count("A"))
Count.append(S.count("R"))
Count.append(S.count("C"))
Count.append(S.count("H"))

Zero=Count.count(0)
if(Zero>=3):print(0)
elif(Zero==2):
    Count.remove(0)
    Count.remove(0)
    pat=1
    for i in Count:pat*=i
    print(pat)
elif(Zero==1):
    Count.remove(0)
    patA=1
    for i in Count:patA*=i
    pat=0
    for i in Count:pat+=patA//i
    print(pat)
elif(Zero==0):
    patA=1
    for i in Count:patA*=i
    pat=0
    for i in range(5):
        for j in range(5):
            if(i==j):continue
            else:
                pat+=patA//Count[i]//Count[j]
    print(pat//2)

Submission status: Accepted

Solution code:
n = int(input())

names = [input()[0] for i in range(n)]
prefix = 'MARCH'
cnt = [names.count(c) for c in prefix]

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

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
s = []
for i in range(n):
    temp = input()[0]
    if temp in 'MARCH':
        s.append(temp)
c = Counter(s)
if len(c) < 3:
    print(0)
else:
    num = []
    for i in c:
        num.append(c[i])
    l = len(num)
    ans = 0
    for i in range(0, l):
        for j in range(i+1, l):
            for k in range(j+1, l):
                ans += num[i]*num[j]*num[k]
    print(ans)

Submission status: Accepted

Solution code:
from sys import exit, setrecursionlimit
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

setrecursionlimit(1000000)

N = read()
dic = defaultdict(int)

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

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

print(result)

Submission status: Accepted

Solution code:
import itertools
from collections import Counter
n=int(input())
a0=[input()[0] for i in range(n)]
a =[i for i in a0 if i in ["M","A","R","C","H"]]
c = dict(Counter(a))

if len(set(a))<=2:
  print(0)
else:
  x=0
  for i1, i2, i3 in itertools.combinations(set(a), 3):
    x+=c[i1]*c[i2]*c[i3]
  print(x)

Submission status: Accepted

Solution code:
import collections
n=int(input())
name = [input()[0] for x in range(n)]
c = collections.Counter(name)
march = [c['M'],c['A'],c['R'],c['C'],c['H']]
# ((a+b+c+d+e)^3-3(a^2+b^2+c^2+d^2+e^2)*(a+b+c+d+e)+2(a^3+b^3+c^3+d^3+e^3))//6
s = sum(march)
s2 = sum([x**2 for x in march])
s3 = sum([x**3 for x in march])
print((s**3-3*s2*s+2*s3)//6)

Submission status: Accepted

Solution code:
n = int(input())
table = "MARCH"
arr = [0] * len(table)

for i in range(n):
    A = input()
    for j in range(len(table)):
        if A[0] == table[j]:
            arr[j]+=1

res = 0
for i in range(len(table)):
    for j in range(i+1,len(table)):
        for k in range(j+1,len(table)):
            res+=arr[i]*arr[j]*arr[k]

print(res)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!A=int(input())

N=int(input())
S=[]
for i in range(N):
    S.append(input())
M = 0
A = 0
R = 0
C = 0
H = 0
for i in S:
    if i[0] == 'M':
        M += 1
    elif i[0] == 'A':
        A += 1
    elif i[0] == 'R':
        R += 1
    elif i[0] == 'C':
        C += 1
    elif i[0] == 'H':
        H += 1
#    print(i[0])
#print(M,A,R,C,H)
def baai(X, x):
    if x == 0:
        return 1
    if x == 1:
        return X
    else:
        return -1
    


num = 0
for m in range(2):
    for a in range(2):
        for r in range(2):
            for c in range(2):
                for h in range(2):
                    if (m + a + r + c + h) == 3:
                        num += baai(M,m)*baai(A,a)*baai(R,r)*baai(C,c)*baai(H,h)
print(num)

Submission status: Accepted

Solution code:
import itertools as it

def c(n,k):
  if k>n:
    return 0
  ret = 1
  for i in range(n, n-k, -1):
    ret *= i
  for i in range(k, 1, -1):
    ret /= i
  return ret


n = int(input())
dic = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
for person in range(n):
  name = input()
  if name[0] in 'MARCH':
    dic[name[0]] += 1

answer = 0
for a,b,c in it.combinations('MARCH', 3):
  answer += dic[a] * dic[b] * dic[c]
print(answer)

Submission status: Accepted

Solution code:
from itertools import combinations

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

cand = ['M', 'A', 'R', 'C', 'H']
count = [0 for _ in range(5)]
for s in S:
    for i, c in enumerate(cand):
        if c == s[0]:
            count[i] += 1

if count.count(0) < 3:
    for i in list(range(5))[::-1]:
        if count[i] == 0:
            del count[i]
    P = list(combinations(count, 3))
    result = 0
    for p in P:
        result += p[0] * p[1] * p[2]
else:
    result = 0

print(int(result))

Submission status: Accepted

Solution code:
# coding=utf-8

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

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

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    march = [0] * 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
    march_sum = 0
    for i in range(0, 3):
        for j in range(i+1, 4):
            for k in range(j+1, 5):
                march_sum += march[i] * march[j] * march[k]
    print(march_sum)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

fields = [0 for x in "MARCH"]
index = {v:i for i, v in enumerate("MARCH")}

for i in a:
    try:
        fields[index[i[0]]] += 1
    except:
        pass

import itertools
result = 0
for i in itertools.combinations(fields, 3):
    result += list(itertools.accumulate(i, lambda l, r: l * r))[-1]
print(result)

Submission status: Accepted

Solution code:
from collections import defaultdict
from itertools import combinations
n=int(input())

c=defaultdict(int)
for _ in range(n):
    s=input()
    if s[0] in 'MARCH':
        c[s[0]]+=1
res=0
for comb in combinations('MARCH',3):
    res+=c[comb[0]]*c[comb[1]]*c[comb[2]]
print(res)

Submission status: Accepted

Solution code:

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

ch = "MARCH"
xs = [0] * 5

for s in S:
    if s[0] in ch:
        i = ch.index(s[0])
        xs[i] += 1

from itertools import combinations

def calc(xs):
    r = 0
    for ys in combinations([0, 1, 2, 3, 4], 3):
        r += xs[ys[0]] * xs[ys[1]] * xs[ys[2]]
    return r

print(calc(xs))

Submission status: Accepted

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

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

ans = A[0]*A[1]*A[2] + 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[0]*A[3]*A[4] + A[1]*A[2]*A[3] + A[1]*A[2]*A[4] + A[1]*A[3]*A[4] + A[2]*A[3]*A[4]

print(ans)

Submission status: Accepted

Solution code:
import itertools
n = int(input())
m = 0
a = 0
r = 0
c = 0
h = 0

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

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = [input()[0] for i in range(N)]
B = {}
for c in S:
    if c not in 'MARCH':
        continue
    B[c] = B.get(c, 0) + 1
A = sum(B.values())
ans = A*(A-1)*(A-2)//6
for c1 in B:
    ans -= B[c1] * (B[c1]-1) * (B[c1]-2) // 6
    for c2 in B:
        if not c1 < c2:
            continue
        ans -= B[c1] * (B[c1]-1) * B[c2] // 2
        ans -= B[c2] * (B[c2]-1) * B[c1] // 2
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=[]
number=[0,0,0,0,0] #MARCH

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


k=[]
k.append(number[0]*number[1]*number[2])
k.append(number[0]*number[1]*number[3])
k.append(number[0]*number[1]*number[4])
k.append(number[0]*number[2]*number[3])
k.append(number[0]*number[2]*number[4])
k.append(number[0]*number[3]*number[4])

k.append(number[1]*number[2]*number[3])
k.append(number[1]*number[2]*number[4])
k.append(number[1]*number[3]*number[4])
k.append(number[2]*number[3]*number[4])

print(sum(k))

Submission status: Accepted

Solution code:
ini_list = \
    [('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')]

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

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

result = 0

for a, b, c in ini_list:
    result += name_dict[a] * name_dict[b] * name_dict[c]

print(result)

Submission status: Accepted

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

import os
import sys
import math
import numpy as np
import collections
import itertools
import functools
import operator

N = int(input())
names = collections.defaultdict(list)


for i in range(N):
    name = input()
    names[name[0]].append(names)

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

ans = 0
prod = functools.partial(functools.reduce, operator.mul)

for heads in itertools.combinations(march, 3):
    nums = [len(names[head]) for head in heads]
    ans += prod(nums)

print(ans)

Submission status: Accepted

Solution code:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
n=i1()
from collections import Counter
a=[]
for i in range(n):
 s=input()
 if s[0]=="M" or s[0]=="A" or s[0]=="R" or s[0]=="C" or s[0]=="H":
   a.append(s[0])
c= Counter(a)
cv=list(c.values())
import itertools
b=list(itertools.combinations(range(len(cv)),3))
d=0
for i in b:
 d+=cv[i[0]]*cv[i[1]]*cv[i[2]]
print(d)

Submission status: Accepted

Solution code:
import itertools
n = int(input())
a = [0,0,0,0,0]
for i in range(n):
	s = 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
seq = (0,1,2,3,4)
b = list(itertools.combinations(seq,3))
ans = 0
for i in range(len(b)):
	ans += a[b[i][0]]*a[b[i][1]]*a[b[i][2]]
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations


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

    f(S)


def f(S):
    march = list("MARCH")
    n = {k: 0 for k in march}
    for s in S:
        if s[0] in march:
            n[s[0]] += 1

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools
m = a = r = c = h = 0
for i in xrange(input()):
    s = raw_input()
    if s[0] == "M":
        m += 1
    elif s[0] == "A":
        a += 1
    elif s[0] == "R":
        r += 1
    elif s[0] == "C":
        c += 1
    elif s[0] == "H":
        h += 1
ans = 0
for i in itertools.combinations((m,a,r,c,h), 3):
    ans += i[0]*i[1]*i[2]
print ans