Problem:


Score : 300 points

Problem Statement

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

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

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

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

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

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

Constraints

1 \leq N \leq 10^5

S_i consists of uppercase English letters.

1 \leq |S_i| \leq 10

S_i \neq S_j (i \neq j)

Input

Input is given from Standard Input in the following format:

N
S_1
:
S_N

Output

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

Sample Input 1

5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI

Sample Output 1

2

We can choose three people with the following names:

MASHIKE, RUMOI, HABORO

MASHIKE, RUMOI, HOROKANAI

Thus, we have two ways.

Sample Input 2

4
ZZ
ZZZ
Z
ZZZZZZZZZZ

Sample Output 2

0

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

Sample Input 3

5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO

Sample Output 3

7



Sample input:
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI


Sample output:
2

Submission status: Accepted

Solution code:
import itertools as it

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

HeadCharCnt = [0 for i in range(5)]
MARCH = 'MARCH'

for i in range(N):
    whichChar = MARCH.find(S[i][0])
    if whichChar != -1:
        HeadCharCnt[whichChar] = HeadCharCnt[whichChar] + 1

HeadCharCntPos = []
for j in HeadCharCnt:
    if j > 0:
        HeadCharCntPos.append(j)
validComb = list(it.combinations(HeadCharCntPos, 3))
ans = 0
for v in validComb:
    ans = ans + v[0] * v[1] * v[2]

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
march=[0,0,0,0,0]
for i in range(n):
    l=input()
    if l[0] in 'MARCH':
        index='MARCH'.find(l[0])
        march[index]+=1
result=0
result+=march[0]*march[1]*march[2]
result+=march[0]*march[1]*march[3]       
result+=march[0]*march[1]*march[4]
result+=march[0]*march[2]*march[3]
result+=march[0]*march[2]*march[4]
result+=march[0]*march[3]*march[4]
result+=march[1]*march[2]*march[3]
result+=march[1]*march[2]*march[4]
result+=march[1]*march[3]*march[4]
result+=march[2]*march[3]*march[4]
print(result)

Submission status: Accepted

Solution code:
import itertools
n = int(input())
ls = [input()[:1] for _ in range(n)]
ans = 0
cmb = list(itertools.combinations(list("MARCH"), 3))

for c in cmb:
    ans += ls.count(c[0]) * ls.count(c[1]) * ls.count(c[2])

print(ans)

Submission status: Accepted

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# --------------------------------------------

dp = None

def main():
    N = int(input())
    name_list = [input() for i in range(N)]
    first_letter_dict = collections.defaultdict(lambda: 0)

    for name in name_list:
        first_letter_dict[name[0]] += 1

    first_letter_combination = [
        "MAR", "MAC", "MAH", "MRC", "MRH", "MCH", "ARC", "ARH", "ACH", "RCH"
    ]

    combinations = 0

    for f_comb in first_letter_combination:
        combinations += first_letter_dict[f_comb[0]] * first_letter_dict[f_comb[1]] * first_letter_dict[f_comb[2]]

    print(combinations)


main()

Submission status: Accepted

Solution code:
n = int(input())
names = []
for i in range(n):
  names.append(input())
names = [i[0] for i in names]
nm = ["M","A","R","C","H"]
ks = [names.count(nm[i]) for i in range(5)]
ans = 0
for i in range(3):
  for j in range(i+1,4):
    for k in range(j+1,5):
      ans += ks[i] * ks[j] * ks[k]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = [input() for i in range(n)]
march = {'M': [], 'A': [], 'R': [], 'C': [], 'H': []}

s = list(set(s))

a = b = 0
for i in s:
    if i[0] == 'M':
        march['M'].append(i)
    elif i[0] == 'A':
        march['A'].append(i)
    elif i[0] == 'R':
        march['R'].append(i)
    elif i[0] == 'C':
        march['C'].append(i)
    elif i[0] == 'H':
        march['H'].append(i)

nums = []
for i in march.values():
    if not len(i) == 0:
        nums.append(len(i))

count = 0
length = len(nums)
if length < 3:
    print(0)
else:
    for i in range(length):
        if length < 3:
            break
        v = nums[i]
        nums.pop(i)
        length = len(nums)
        for j in range(length):
            count += v * nums[j] * (sum(nums[j+1:]))
    print(count)

Submission status: Accepted

Solution code:
import collections
N = int(input())
a = ['']*N
for i in range(N):
    a[i] = list(input())[0]
c_list = [0]*5
MARCH = ['M','A','R','C','H']
c_list = [a.count(i) for i in MARCH]
summation = 0
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            summation += c_list[i]*c_list[j]*c_list[k]
print(summation)

Submission status: Accepted

Solution code:
n = int(input())
l = ['M','A','R','C','H']
m = []
a = []
r = []
c = []
h = []
for i in range(n):
    s = input()
    if not s[0] in l: continue
    if s[0] == 'M':
        m.append(s)
    elif s[0] == 'A':
        a.append(s)
    elif s[0] == 'R':
        r.append(s)
    elif s[0] == 'C':
        c.append(s)
    else:
        h.append(s)

n = sum([len(i) for i in [m,a,r,c,h]])
all = n * (n - 1) * (n - 2) // 6
for t in [m,a,r,c,h]:
    i = len(t)
    if i >= 3:
        k = i * (i - 1) * (i - 2) // 6
        all -= k
    if i >= 2:
        k = i * (i - 1) // 2
        all -= k * (n - i)
print(all)

Submission status: Accepted

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

name = [0 for i in range(5)]
for i in range(n):
    if s[i][0] == "M":
        name[0] +=1
    elif s[i][0] == "A":
        name[1] +=1
    elif s[i][0] == "R":
        name[2] +=1
    elif s[i][0] == "C":
        name[3] +=1
    elif s[i][0] == "H":
        name[4] +=1
count = 0
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            #print("({},{},{})".format(i,j,k))
            count += name[i]*name[j]*name[k]
print(count)

Submission status: Accepted

Solution code:
import itertools as itr

n = int(input())

march = [0,0,0,0,0]
tops = list(range(5))

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

total = 0

for kumiawase in itr.combinations(tops,3):
    total += march[kumiawase[0]]*march[kumiawase[1]]*march[kumiawase[2]]

print(total)

Submission status: Accepted

Solution code:
N = int(input())
s = [input()[0] for _ in range(N)]
t = []
ans = 0
for k in 'MARCH':
    t.append(s.count(k))
for i in range(32):
    u = []
    for j in range(5):
        if i&(1<<j):
            u.append(t[j])
    if len(u) == 3:
        ans += u[0]*u[1]*u[2]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
m = a = r = c = h = 0

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

Submission status: Accepted

Solution code:
from collections import deque

N = int(input())

S = deque()

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

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

conbi = 0
count = deque()

for alp in name.values():
    count.append(alp)
    
for i in range(3):
    for l in range(i+1, 5):
        for n in range(l+1, 5):
            if count[i] != 0 and count[l] != 0 and count[n] != 0:
                conbi += count[i] * count[l] * count[n]
print(conbi)

Submission status: Accepted

Solution code:
N=int(input())
s=[]
t=[]
ans=0
for j in range(N):
    a=list(input())
    s+=a[0]
for k in "MARCH":
    t.append(s.count(k))
for ii in range(32):
    u=[]
    for jj in range(5):
        if ii&(1<<jj):
            u.append(t[jj])
    if len(u)==3:
        ans+=u[0]*u[1]*u[2]
print(ans)

Submission status: Accepted

Solution code:
import re
import sys
import itertools

if __name__ == '__main__':
    N = input()
    S = list()
    c = 0
    d = {'M':0,'A':0,'R':0,'C':0,'H':0}
    for i in xrange(N):
        a = raw_input()[0]
        if a in d.keys():
            d[a] += 1
    if d['M'] > 0 and d['A'] > 0 and d['R'] > 0:
        c += d['M']*d['A']*d['R']
    if d['M'] > 0 and d['A'] > 0 and d['C'] > 0:
        c += d['M']*d['A']*d['C']
    if d['M'] > 0 and d['A'] > 0 and d['H'] > 0:
        c += d['M']*d['A']*d['H']
    if d['M'] > 0 and d['R'] > 0 and d['C'] > 0:
        c += d['M']*d['R']*d['C']
    if d['M'] > 0 and d['R'] > 0 and d['H'] > 0:
        c += d['M']*d['R']*d['H']
    if d['M'] > 0 and d['C'] > 0 and d['H'] > 0:
        c += d['M']*d['C']*d['H']
    if d['A'] > 0 and d['R'] > 0 and d['C'] > 0:
        c += d['A']*d['R']*d['C']
    if d['A'] > 0 and d['R'] > 0 and d['H'] > 0:
        c += d['A']*d['R']*d['H']
    if d['A'] > 0 and d['C'] > 0 and d['H'] > 0:
        c += d['A']*d['C']*d['H']
    if d['R'] > 0 and d['C'] > 0 and d['H'] > 0:
        c += d['R']*d['C']*d['H']
    print c

Submission status: Accepted

Solution code:
import itertools

n = int(input())
a = [0] * 26
for _ in range(n):
   a[ord(input()[0]) - ord('A')] += 1
c = []
for x in 'MARCH':
    c.append(a[ord(x) - ord('A')])
s = 0
for x in itertools.combinations(c, 3):
    k = 1
    for i in x: k *= i
    s += k
print(s)

Submission status: Accepted

Solution code:
m, a, r, c, h = [0] * 5

N = int(input())

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

    if s == 'M':
        m += 1
    elif s == 'A':
        a += 1
    elif s == 'R':
        r += 1
    elif s == 'C':
        c += 1
    elif s == '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:
import itertools

N = int(input())
MARCH = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
for i in range(N):
    temp = input()
    if temp[0] in MARCH.keys():
        MARCH[temp[0]] += 1
ans = 0
for comb in list(itertools.combinations(MARCH.values(), 3)):
    temp2 = 1
    for i in comb:
        temp2 *= i
    ans += temp2
    
print(ans)

Submission status: Accepted

Solution code:
a=int(input())
list=[0,0,0,0,0]
for x in range(a):
	b=input()[:1]
	if 'M'==b:
		list[0]+=1
	elif 'A'==b:
		list[1]+=1
	elif 'R'==b:
		list[2]+=1
	elif 'C'==b:
		list[3]+=1
	elif 'H'==b:
		list[4]+=1
	a-=1
f=0
for c in range(5):
	for d in range(4):
		for e in range(3):
			if c<=d or c<=e or d<=e:
				break
			f+=list[c]*list[d]*list[e]
print(f)

Submission status: Accepted

Solution code:
n=int(input())
a=[input()for i in range(n)]
import itertools
c_0=c_1=c_2=c_3=c_4=0
for i in a:
    if i[0]=="M":
        c_0+=1
    elif i[0]=="A":
        c_1+=1
    elif i[0]=="R":
        c_2+=1
    elif i[0]=="C":
        c_3+=1
    elif i[0]=="H":
        c_4+=1
total=list(itertools.combinations((c_0,c_1,c_2,c_3,c_4),3))
ans=0
for i in range(10):
    ans+=(total[i][0]*total[i][1]*total[i][2])
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

Submission status: Accepted

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

import numpy as np
s=np.zeros(5)

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

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

Submission status: Accepted

Solution code:
N = int(input())

user_name = []

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

M_group = [x for x in user_name if x[0] == 'M']
A_group = [x for x in user_name if x[0] == 'A']
R_group = [x for x in user_name if x[0] == 'R']
C_group = [x for x in user_name if x[0] == 'C']
H_group = [x for x in user_name if x[0] == 'H']

choice_cnt = 0
choice_list = []

for i in range(2):
    choice_cnt += i
    for j in range(2):
        choice_cnt += i
        for k in range(2):
            choice_cnt += i
            for l in range(2):
                choice_cnt += i
                for m in range(2):
                    choice_cnt += i

                    if i+j+k+l+m == 3:
                        choice_list.append([i,j,k,l,m])

sums = 0
march = [len(M_group), len(A_group), len(R_group), len(C_group), len(H_group)]

prod = 0
choice_num = []

for x in choice_list:
    choice_num.append([march[i] for i in range(len(x)) if x[i] > 0])

prod_sum = 0

for y in choice_num:
    prod = 1

    for k in range(len(y)):
        prod = prod * y[k]
    prod_sum += prod

print(prod_sum)

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()
    n=name[0]
    if n=="M":
        m+=1
    if n=="A":
        a+=1
    if n=="R":
        r+=1
    if n=="C":
        c+=1
    if n=="H":
        h+=1
lst=[m,a,r,c,h]
ans=0
for i in range(5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            ans+=lst[i]*lst[j]*lst[k]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

for i in range(n):
    si = input()
    if si[0] in march.keys():
        march[si[0]] += 1
#print(march)

sum = 0
sum += (march['M'] * march['A'] * march['R'])
sum += (march['M'] * march['A'] * march['C'])
sum += (march['M'] * march['A'] * march['H'])
sum += (march['A'] * march['R'] * march['C'])
sum += (march['A'] * march['R'] * march['H'])
sum += (march['R'] * march['M'] * march['C'])
sum += (march['R'] * march['M'] * march['H'])
sum += (march['R'] * march['C'] * march['H'])
sum += (march['C'] * march['M'] * march['H'])
sum += (march['C'] * march['A'] * march['H'])
print(sum)

Submission status: Accepted

Solution code:
import itertools
                                                                                                                           
n = int(input())
index = [0, 1, 2, 3, 4]
count = [0, 0, 0, 0, 0]
result = 0
for i in range(n):
  x = input()[0]
  if x == 'M':
    count[0] += 1
  elif x == 'A':
    count[1] += 1
  elif x == 'R':
    count[2] += 1
  elif x == 'C':
    count[3] += 1
  elif x == 'H':
    count[4] += 1
  else:
    pass
        
for cs in list(itertools.combinations(index, 3)):
  result += count[cs[0]]*count[cs[1]]*count[cs[2]]

print(result)

Submission status: Accepted

Solution code:
import itertools
import time
n = int(input())
names = []
ans = 0
ini = ["M", "A", "R", "C", "H"]
count = {"M":0, "A":0, "R":0, "C":0, "H":0}
for i in range(n):
  name = input()
  if name[0] in ini:
    count[name[0]] += 1

combo = list(itertools.combinations(ini, 3))

for a, b, c in combo:
  ans += count[a]*count[b]*count[c]

print(ans)

Submission status: Accepted

Solution code:
import itertools

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

for i in range(N):
    member = input()
    for key in march:
        if member[0] == key:
            march[key] += 1
            break

combi_list = list(itertools.combinations((list(march.values())), 3))
count = sum([i[0] * i[1] * i[2] for i in combi_list])
print(count)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    M = A = R = C = H = 0
    for i in range(N):
        name = input()
        if name[0] == "M":
            M = M + 1
        elif name[0] == "A":
            A = A + 1
        elif name[0] == "R":
            R = R + 1
        elif name[0] == "C":
            C = C + 1
        elif name[0] == "H":
            H = H + 1

    ans = M*A*R
    ans = ans + M*A*C
    ans = ans + M*A*H
    ans = ans + M*R*C
    ans = ans + M*R*H
    ans = ans + M*C*H
    ans = ans + A*R*C
    ans = ans + A*R*H
    ans = ans + A*C*H
    ans = ans + R*C*H
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict as ddict
from itertools import combinations as comb

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

dd = ddict(int)
for name in s:
    for i in ['M', 'A', 'R', 'C', 'H']:
        if name.startswith(i):
            dd[i] += 1

ans = sum(dd[i1] * dd[i2] * dd[i3] for i1, i2, i3 in comb(dd.keys(), 3))

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import sys
import itertools

n = int(input())
s = [0, 0, 0, 0, 0]

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

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

l = len(k)
if l < 3:
    print(0)
    sys.exit()

a = 0
c = list(itertools.combinations(range(l), 3))
for i in c:
    a += k[i[0]] * k[i[1]] * k[i[2]]

print(a)

Submission status: Accepted

Solution code:
from collections import Counter
from itertools import combinations
N = int(input())
S = Counter()
for _ in range(N):
    s = input()
    S.update(s[0])

ss = "MARCH"
coms = combinations(ss, 3)
ans = 0
for com in coms:
    ans += S.get(com[0], 0) * S.get(com[1], 0) * S.get(com[2], 0)
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
m_count=0
a_count=0
r_count=0
c_count=0
h_count=0

for i in range(N):
    name=input()
    if name[0]=='M':
        m_count+=1
    if name[0]=='A':
        a_count+=1
    if name[0]=='R':
        r_count+=1
    if name[0]=='C':
        c_count+=1
    if name[0]=='H':
        h_count+=1

x=[]
x.append(m_count)
x.append(a_count)
x.append(r_count)
x.append(c_count)
x.append(h_count)
c=0
for i in range(len(x)):
    for j in range(i+1,len(x)):
        for k in range(j+1,len(x)):
            c+=x[i]*x[j]*x[k]
print(c)

Submission status: Accepted

Solution code:
n = int(input(""))
s = ["0"]*n
dict = {}
sum = [0,0,0,0,0,0,0,0,0,0]
ans = 0
for i in range(n):
    s[i] = input("")
    if s[i][0] in "MARCH":
        if s[i][0] in dict:
            dict[s[i][0]] += 1
        else:
            dict[s[i][0]] = 1
if "M" in dict:
    if "A" in dict:
        if "R" in dict:
              sum[0] = dict["M"]*dict["A"]*dict["R"]
        if "C" in dict:
              sum[1] = dict["M"]*dict["A"]*dict["C"]
        if "H" in dict:
              sum[2] = dict["M"]*dict["A"]*dict["H"]
    if "R" in dict:
        if "C" in dict:
              sum[3] = dict["M"]*dict["R"]*dict["C"]
        if "H" in dict:
              sum[4] = dict["M"]*dict["R"]*dict["H"]
    if "C" in dict:
        if "H" in dict:
              sum[5] = dict["M"]*dict["C"]*dict["H"]
if "A" in dict:
    if "R" in dict:
        if "C" in dict:
              sum[6] = dict["A"]*dict["R"]*dict["C"]
        if "H" in dict:
              sum[7] = dict["A"]*dict["R"]*dict["H"]
    if "C" in dict:
        if "H" in dict:
              sum[8] = dict["A"]*dict["C"]*dict["H"]
if "R" in dict and "C" in dict and "H" in dict:
    sum[9] = dict["R"]*dict["C"]*dict["H"]
for i in range(10):
    ans += sum[i]
print(ans)

Submission status: Accepted

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

# AtCoder Beginner Contest
# Problem C


def count_initial_name(people_count: int) -> dict:
    matching_strings_count = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}

    for person in range(people_count):
        initial_name = input()[0]

        if initial_name in matching_strings_count.keys():
            matching_strings_count[initial_name] += 1

    return matching_strings_count


def count_patterns(matching_strings_count):
    import itertools

    patterns = itertools.combinations(matching_strings_count.keys(), 3)
    pattern_count = 0

    for a_pattern in patterns:
        pattern_count += matching_strings_count[a_pattern[0]] * \
            matching_strings_count[a_pattern[1]] * \
            matching_strings_count[a_pattern[2]]
    return pattern_count


if __name__ == '__main__':
    matching_strings_count = count_initial_name(people_count=int(input()))

    if sum(matching_strings_count.values()) >= 3:
        print(count_patterns(matching_strings_count))
    else:
        print(0)

Submission status: Accepted

Solution code:
n = int(input())
s = [input() for i in range(n)]
st = [0,0,0,0,0]
p = [0,0,0,0,0,0,1,1,1,2]
q = [1,1,1,2,2,3,2,2,3,3]
r = [2,3,4,3,4,4,3,4,4,4]
ans = 0

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

for i in range(10):
    ans += st[p[i]]*st[q[i]]*st[r[i]]

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
dic = {}
for _ in range(N):
    S = input()
    if S[0] not in "MARCH":
        continue
    if S[0] not in dic:
        dic[S[0]] = 0
    dic[S[0]]+=1
ans = 0

for a in dic:
    for b in dic:
        for c in dic:
            if a == b or b == c or c == a:
                continue
            ans += dic[a] * dic[b] * dic[c]
print(ans // 6)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


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

m = sum([name[0] == 'M' for name in S])
a = sum([name[0] == 'A' for name in S])
r = sum([name[0] == 'R' for name in S])
c = sum([name[0] == 'C' for name in S])
h = sum([name[0] == 'H' for name in S])

print(m * (a * (r + c + h) + r * (c + h) + c * h) + a * (r * (c + h) + c * h) + r * c * h)

Submission status: Accepted

Solution code:
import itertools
n = int(input())
x = [input() for i in range(n)] 
num,march,answer = [0,0,0,0,0],["M","A","R","C","H"],0
for j in x:
 if j[0] in march: num[march.index(j[0])] += 1
while 0 in num: num.remove(0)
for k in list(itertools.combinations(num,3)): 
 answer += k[0]*k[1]*k[2]
print(answer)

Submission status: Accepted

Solution code:
x = int(input())
count = [0 for i in range(5)]
for i in range(x):
    name = input()
    if name[0] == 'M':
        count[0] += 1
    elif name[0] == 'A':
        count[1] += 1
    elif name[0] == 'R':
        count[2] += 1
    elif name[0] == 'C':
        count[3] += 1
    elif name[0] == 'H':
        count[4] += 1

p = [0, 0, 0, 0, 0, 0, 1, 1, 1, 2]
q = [1, 1, 1, 2, 2, 3, 2, 2, 3, 3]
r = [2, 3, 4, 3, 4, 4, 3, 4, 4, 4]
res = 0
for i in range(10):
    res += count[p[i]]*count[q[i]]*count[r[i]]

print(res)

Submission status: Accepted

Solution code:
N = int(input())
_M = [] 
_A = [] 
_R = [] 
_C = [] 
_H = [] 

for i in range(N):
    x = input()
    if x[0] == 'M':
        _M.append(x)
    elif x[0] == 'A':
        _A.append(x)
    elif x[0] == 'R':
        _R.append(x)
    elif x[0] == 'C':
        _C.append(x)
    elif x[0] == 'H':
        _H.append(x)

m = len(_M)
a = len(_A)
r = len(_R)
c = len(_C)
h = len(_H)

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

Submission status: Accepted

Solution code:
import itertools
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
l = itertools.combinations([m,a,r,c,h],3)
ans = 0
for i in l:
    k = 1
    for i2 in i:
        k*=i2
    ans+=k
print(ans)

Submission status: Accepted

Solution code:
import itertools
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

l=itertools.combinations([m,a,r,c,h],3)
c=0
for i in l:
    k=1
    for i2 in i:
        k*=i2
    c+=k
print(c)

Submission status: Accepted

Solution code:
import collections
import itertools

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

cnt = collections.Counter()
for s in S:
    cnt[s[0]] += 1

ans = 0
for x, y, z in itertools.combinations("MARCH", 3):
    ans += cnt[x] * cnt[y] * cnt[z]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

march = "MARCH"
arr = [0 for i in range(5)]
for i in range(n):
    s = input()
    for j in range(len(march)):
        if s[0] == march[j]:
            arr[j] += 1

ans = 0

ans2 = [arr[x]*arr[y]*arr[z] for x in range(len(march)) for y in range(x+1, len(march)) for z in range(y+1, len(march))]
for i in ans2:
    ans += i

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
march = "MARCH"
count = [0 for i in range(5)]
for i in range(N):
    S = input()
    for j in range(5):
        if S[0] == "MARCH"[j]:
            count[j] += 1
def f(m):
    result = 0
    for i in range(5):
        result += count[i] ** m
    return result
print((f(1) ** 3 + 2 * f(3) - 3 * f(1) * f(2)) // 6)

Submission status: Accepted

Solution code:
import itertools
N = int(input())
S = []
x = 0
y = 1
for i in range(N):
    Z = input()
    S.append(Z[0])

T = []

for j in "MARCH":
    T.append(S.count(j))

P = list(itertools.combinations(T,3))

for k in P:
    for l in range(3):
        y *= int(k[l])
    x += y
    y = 1

print(x)

Submission status: Accepted

Solution code:
import collections
import itertools

n = int(input())
s = collections.defaultdict(int)
for i in range(n):
    s[input()[0]] += 1

seq = list(itertools.combinations(['M', 'A', 'R', 'C', 'H'], 3))
ans = 0
for l in seq:
    ans += s[l[0]] * s[l[1]] * s[l[2]]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
m = 0
a = 0
r = 0
c = 0
h = 0
for _ in range(N):
    p = input()
    if p[0] == "M":
        m += 1
    elif p[0] == "A":
        a += 1
    elif p[0] == "R":
        r += 1
    elif p[0] == "C":
        c += 1
    elif p[0] == "H":
        h += 1
ans = 0
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)

Submission status: Accepted

Solution code:
#coding=utf-8
from itertools import combinations
from collections import Counter

def solve(n, gc):
    #filtered_ss = list(filter(lambda x: x in "MARCH", ss))

    #gc = Counter(filtered_ss)
    if len(gc) < 3:
        return 0

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

    return ans

def main():
    n = int(input())
    gc = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
    for _ in range(n):
        x = input()[0]
        if x in "MARCH":
            gc[x] += 1
    print(solve(n, gc))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
count = [0, 0, 0, 0, 0]
pattern = [[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 range(N):
    s = input()
    if (s[0] == 'M'):
        count[0] += 1
    if (s[0] == 'A'):
        count[1] += 1
    if (s[0] == 'R'):
        count[2] += 1
    if (s[0] == 'C'):
        count[3] += 1
    if (s[0] == 'H'):
        count[4] += 1

s = 0
for pat in pattern:
    temp = count[pat[0]] * count[pat[1]] * count[pat[2]]
    s += temp
print(s)

Submission status: Accepted

Solution code:
import itertools

N = int(input())

mem = list(set() for i in range(5))

for _ in range(N):
    S = input()
    first_name = "MARCH".find(S[0])
    if first_name != -1:
        mem[first_name].add(S)

ans = 0
for t in list(itertools.combinations(range(5), 3)):
    ans += len(mem[t[0]]) * len(mem[t[1]]) * len(mem[t[2]])
    
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
d = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
for i in range(N):
    inp = input()
    if inp[0] in d:
        d[inp[0]] += 1
import itertools
cnt = 0
for c in itertools.combinations(d.keys(), 3):
    cnt += d[c[0]] * d[c[1]] * d[c[2]]
print(cnt)

Submission status: Accepted

Solution code:
import itertools

n = int(input())
names = {}
for x in 'MARCH':
    names[x] = 0

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

ans = 0
for (x,y,z) in itertools.combinations('MARCH',3) :
    ans += names[x]*names[y]*names[z]

print(ans)

Submission status: Accepted

Solution code:
import itertools

n = int(input())
names = {}
for x in 'MARCH':
    names[x] = 0

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

ans = 0
for (x,y,z) in list(itertools.combinations('MARCH',3)) :
    ans += names[x]*names[y]*names[z]

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
names = {}
for x in 'MARCH':
    names[x] = 0

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

ans = 0
for x in 'MARCH' :
    for y in 'MARCH' :
        if x == y:
            continue
        for z in 'MARCH':
            if x == z or y == z :
                continue
            ans += names[x]*names[y]*names[z]

print(ans//6)

Submission status: Accepted

Solution code:
import pprint
import itertools

N = int(input())

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

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

for k in [name[0] for name in S]:
    if k in D:
        D[k] = D[k] + 1

C = 0
for x, y, z in itertools.combinations(D.keys(), 3):
    C += D[x] * D[y] * D[z]

print(C)

Submission status: Accepted

Solution code:
from collections import defaultdict
from itertools import combinations

d = defaultdict(int)

n = int(input())

for _ in range(n):
    initial = input()[0]
    if initial in 'MARCH':
        d[initial] += 1

a = list(d.values())

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
l = []
m=0
a=0
r=0
c=0
h=0
for i in range(N):
    l.append(input()) 

for i in l:
    if i.startswith('M'):
        m+=1
    if i.startswith('A'):
        a+=1
    if i.startswith('R'):
        r+=1
    if i.startswith('C'):
        c+=1
    if i.startswith('H'):
        h+=1

print(m*a*r+m*a*c+m*a*h+a*r*c+a*r*h+r*c*h+m*r*c+m*r*h+m*c*h+a*c*h)