Problem:


Score : 300 points

Problem Statement

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

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

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

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

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

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

Constraints

1 \leq N \leq 10^5

S_i consists of uppercase English letters.

1 \leq |S_i| \leq 10

S_i \neq S_j (i \neq j)

Input

Input is given from Standard Input in the following format:

N
S_1
:
S_N

Output

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

Sample Input 1

5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI

Sample Output 1

2

We can choose three people with the following names:

MASHIKE, RUMOI, HABORO

MASHIKE, RUMOI, HOROKANAI

Thus, we have two ways.

Sample Input 2

4
ZZ
ZZZ
Z
ZZZZZZZZZZ

Sample Output 2

0

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

Sample Input 3

5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO

Sample Output 3

7



Sample input:
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI


Sample output:
2

Submission status: Accepted

Solution code:
import itertools
n = int(input())
s = [str(input()) for i in range(n)]
march = [0, 0, 0, 0, 0]
for i in range(n):
    if s[i].startswith("M"):
        march[0] += 1
    elif s[i].startswith("A"):
        march[1] += 1
    elif s[i].startswith("R"):
        march[2] += 1
    elif s[i].startswith("C"):
        march[3] += 1
    elif s[i].startswith("H"):
        march[4] += 1
match = list(itertools.combinations(march, 3))
ans = 0
for i in range(len(match)):
    ans += match[i][0] * match[i][1] * match[i][2]
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import itertools
n=int(input())
m,a,r,c,h=[],[],[],[],[]
for i in range(n):
    s=input()
    start=s[0]
    if start=="M":
        m.append(s)
    elif start=="A":
        a.append(s)
    elif start=="R":
        r.append(s)
    elif start=="C":
        c.append(s)
    elif start=="H":
        h.append(s)
s=[]
if len(m)!=0:
    s.append(len(list(itertools.combinations(m,1))))
if len(a)!=0:
    s.append(len(list(itertools.combinations(a,1))))
if len(r)!=0:
    s.append(len(list(itertools.combinations(r,1))))
if len(c)!=0:
    s.append(len(list(itertools.combinations(c,1))))
if len(h)!=0:
    s.append(len(list(itertools.combinations(h,1))))
hoge=list(itertools.combinations(s,3))
num=len(hoge)
ans=0
for i in range(num):
    ans+=hoge[i][0]*hoge[i][1]*hoge[i][2]
print(ans)

Submission status: Accepted

Solution code:
import itertools
N = int(input())
nums = {}
for _ in range(N):
  s = input()[0]
  if s in nums.keys():
    nums[s] += 1
  else:
    nums[s] = 1
ans = 0
for C in itertools.combinations(list("MARCH"),3):
  tmp = 1
  for c in C:
    if c in nums.keys():
      tmp *= nums[c]
    else:
      tmp = 0
  ans += tmp
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
M,A,R,C,H = ([] for i in range(5))
for i in range(N):
    s = input()
    if s[0] == "M":
        M.append(s)
    if s[0] == "A":
        A.append(s)
    if s[0] == "R":
        R.append(s)
    if s[0] == "C":
        C.append(s)
    if s[0] == "H":
        H.append(s)
x = [len(M),len(A),len(R),len(C),len(H)]
ans = 0
for i in range(5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            ans += x[i]*x[j]*x[k]
print(ans)

Submission status: Accepted

Solution code:
import itertools


def main():
    N = int(input())
    caps = {x: 0 for x in "MARCH"}
    for _ in range(N):
        S = input()
        if S[0] in caps:
            caps[S[0]] += 1
    ans = 0
    for comb in itertools.combinations("MARCH", 3):
        tmp = 1
        for c in comb:
            tmp *= caps[c]
        ans += tmp
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
from itertools import combinations as comb

def main():
    input = sys.stdin.readline
    N = int(input())
    A = [0] * 5
    for _ in range(N):
        S = str(input().strip())
        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

    ans = 0
    C = list(comb(A, 3))
    for c in C:
        ans += c[0] * c[1] * c[2]

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

aa = [0,0,0,0,0]

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

su = 0

for i in range(3):
    for j in range(1+i,4):
        for k in range(1+j,5):
            su += aa[i] * aa[j] * aa[k]



print(su)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
init = [0, 0, 0, 0, 0]
for i in range(n):
    name = input()
    first = name[0]
    if first == "M":
        init[0] += 1
    elif first == "A":
        init[1] += 1
    elif first == "R":
        init[2] += 1
    elif first == "C":
        init[3] += 1
    elif first == "H":
        init[4] += 1

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

Submission status: Accepted

Solution code:
import itertools
n=int(input())
D={'M':0,'A':0,'R':0,'C':0,'H':0}
for i in range(n):
    x=input()
    if x[0]=='M':
        D['M']+=1
    elif x[0]=='A':
        D['A']+=1
    elif x[0]=='R':
        D['R']+=1
    elif x[0]=='C':
        D['C']+=1
    elif x[0]=='H':
        D['H']+=1

X=D.values()
Y=list(itertools.combinations(X,3))
cnt=0
for i in range(10):
    cnt+=Y[i][0]*Y[i][1]*Y[i][2]

print(cnt)

Submission status: Accepted

Solution code:
from collections import Counter
from itertools import combinations
N = int(input())
S = [input()[0] for _ in range(N)]
S = Counter([s for s in S if s in ("M", "A", "R", "C", "H")])
trio = combinations(S.keys(), 3)
num = 0
for a, b, c in trio:
    num += S[a] * S[b] * S[c]
print(num)

Submission status: Accepted

Solution code:
# C
import itertools

n = int(input())
# M:0 A:1 R:2 C:3 H:4
march = ['M', 'A', 'R', 'C', 'H']
l = [0] * 5
ans = 0
for i in range(n):
    s = str(input())
    for index, c in enumerate(march):
        if s[0] == c:
            l[index] += 1
for (a,b,c) in itertools.combinations(range(5), 3):
    ans += l[a] * l[b] * l[c]

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
M=0;A=0;R=0;C=0;H=0
for i in range(N):
  a=input()
  if a[0]=='M':
    M+=1
  elif a[0]=='A':
    A+=1
  elif a[0]=='R':
    R+=1
  elif a[0]=='C':
    C+=1
  elif a[0]=='H':
    H+=1
L=[M,A,R,C,H]
a=0
for i in range(3):
  for j in range(i+1,4):
    for k in range(j+1,5):
      a=a+L[i]*L[j]*L[k]
print(a)

Submission status: Accepted

Solution code:
from itertools import*
n = int(input())
s = [input() for i in range(n)]
s = [s[i][0] for i in range(n)]
d=[0]*128
for t in s:
    d[ord(t[0])]+=1
print(sum(p*q*r for p,q,r in combinations([d[ord(t)] for t in'MARCH'],3)))

Submission status: Accepted

Solution code:
from itertools import combinations
from collections import Counter
n = int(input())
S = Counter()
for i in range(n):
    S[input()[0]]+=1
print(sum(S[a]*S[b]*S[c] for a,b,c in combinations("MARCH",3)))

Submission status: Accepted

Solution code:
from itertools import combinations
n = int(input())
s = [input() for _ in range(n)]
s = [name for name in s if name[0] in "MARCH"]
s = set(s)
sd = {c:0 for c in "MARCH"}
for c in s:
    sd[c[0]] += 1
res = 0
for l in combinations(sd.values(), 3):
    res += l[0] * l[1] * l[2]
print(res)

Submission status: Accepted

Solution code:
n = int(input())
nlist = [input()[0] for _ in range(n)]
c = [0] * 5
c[0] = nlist.count('M')
c[1] = nlist.count('A')
c[2] = nlist.count('R')
c[3] = nlist.count('C')
c[4] = nlist.count('H')
ret = 0
for i in range(5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            ret += c[i]*c[j]*c[k]
print(ret)

Submission status: Accepted

Solution code:
import itertools

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

comb = list(itertools.combinations(range(5), 3))
ans = 0
for c in comb:
    ans += l[c[0]] * l[c[1]] * l[c[2]]
print(ans)

Submission status: Accepted

Solution code:
from itertools import*;print(sum(p*q*r for p,q,r in combinations(map(list(zip(*open(0).readlines()))[0].count,'MARCH'),3)))

Submission status: Accepted

Solution code:
from itertools import*;s,*_=zip(*open(0).readlines());print(sum(p*q*r for p,q,r in combinations([s.count(t)for t in"MARCH"],3)))

Submission status: Accepted

Solution code:
from itertools import*;s,*_=zip(*open(0).readlines());print(sum(p*q*r for p,q,r in combinations(map(s.count,'MARCH'),3)))

Submission status: Accepted

Solution code:
from itertools import*;s,*_=zip(*open(0).readlines());c=s.count;print(sum(c(p)*c(q)*c(r)for p,q,r in combinations('MARCH',3)))

Submission status: Accepted

Solution code:
from itertools import*;x=[s[0]for s in open(0).readlines()];print(sum(p*q*r for p,q,r in combinations([x.count(s)for s in"MARCH"],3)))

Submission status: Accepted

Solution code:
from itertools import*;c=list(zip(*open(0).readlines()))[0].count;print(sum(c(p)*c(q)*c(r)for p,q,r in combinations('MARCH',3)))

Submission status: Accepted

Solution code:
import sys
import itertools
N = int(input())
S = [sys.stdin.readline() for _ in range(N)]
caps = ['M', 'A', 'R', 'C', 'H']
a = [0] * 5
ans = 0
for s in S:
    if s[0] in caps:
        a[caps.index(s[0])] += 1
c = list(itertools.combinations((0, 1, 2, 3, 4), 3))
for i in range(len(c)):
    ans += a[c[i][0]] * a[c[i][1]] * a[c[i][2]]
print(ans)

Submission status: Accepted

Solution code:
import itertools
N = int(input())
S = [input() for _ in range(N)]
caps = ['M', 'A', 'R', 'C', 'H']
a = [0] * 5
ans = 0
for s in S:
    if s[0] in caps:
        a[caps.index(s[0])] += 1
c = list(itertools.combinations((0, 1, 2, 3, 4), 3))
for i in range(len(c)):
    ans += a[c[i][0]] * a[c[i][1]] * a[c[i][2]]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
S = [input() for i in range(n)]
A = [0, 0, 0, 0, 0]
B = ["M", "A", "R", "C", "H"]

for i in range(n) :
    for j in range(5) :
        if S[i][0] == B[j] :
            A[j] += 1

#print(A)

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

print(ans)

Submission status: Accepted

Solution code:
from itertools import*;print(sum(p*q*r for p,q,r in list(combinations([len(list(v))for k,v in groupby(sorted(s[0]for s in open(0).readlines()[1:]))if k in"MARCH"],3))))

Submission status: Accepted

Solution code:
from itertools import*
x=sorted(s[0]for s in open(0).readlines()[1:])
#print(list(x))
c=[len(list(v))for k,v in groupby(x)if k in"MARCH"]
#print(c)
y=combinations(c,3)
#print(list(y))
print(sum(p*q*r for p,q,r in list(y)))

Submission status: Accepted

Solution code:

n = int(input())

march = 'MARCH'
bucket = [0]*5



for _ in range(n):
    s = input()

    pos = march.find(s[0])
    if pos < 0:
        continue

    bucket[pos] += 1


ans = 0
for i in range(5):
    for j in range(1,5):
        if i >= j:
            continue
        for k in  range(2,5):
            if j >= k:
                continue
            
            # print((i,j,k))
            ans += bucket[i]*bucket[j]*bucket[k]


print(ans)

Submission status: Accepted

Solution code:
#ABC089C
import numpy as np
N=int(input())
M=['M','A','R','C','H']
C=[0,0,0,0,0]
for _ in range(N):
	x=input()
	for i in range(5):
		if x[0]==M[i]:
			C[i]+=1
ans=0
for a in range(3):
	for b in range(a+1,4):
		for c in range(b+1,5):
			ans+=C[a]*C[b]*C[c]
print(ans)

Submission status: Accepted

Solution code:
from itertools import*;d=[0]*91
for s in open(0).readlines():d[ord(s[0])]+=1
print(sum(d[p]*d[q]*d[r]for p,q,r in combinations(map(ord,'MARCH'),3)))

Submission status: Accepted

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

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

lastcnt = 0

for i in range(3):
    for j in range(i+1, 4):
        for k in range(j+1, 5):
            # print(cnt[i]*cnt[j]*cnt[k])
            lastcnt += cnt[i]*cnt[j]*cnt[k]
print(lastcnt)

Submission status: Accepted

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

initial = ['M', 'A', 'R', 'C', 'H']
sum_initials = [0]*5
for Si in S:
    for i in range(5):
        if Si[0] == initial[i]:
            sum_initials[i] += 1

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

Submission status: Accepted

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

initial = ['M', 'A', 'R', 'C', 'H']
sum_initials = [0]*5
for Si in S:
    for i in range(5):
        if Si[0] == initial[i]:
            sum_initials[i] += 1

sum_short = []
for i in range(5):
    if sum_initials[i] != 0: sum_short.append(sum_initials[i] )

ans = 0
if len( sum_short ) == 3:
    ans = sum_short[0]*sum_short[1]*sum_short[2]
elif len( sum_short ) == 4:
    for i in range(4):
        ans += sum_short[i]*sum_short[i-1]*sum_short[i-2]
elif len( sum_short ) == 5:
    for i in range(5):
        for j in range(i+1,5):
            for k in range(j+1,5):
                ans += sum_short[i]*sum_short[j]*sum_short[k]
print( ans )

Submission status: Accepted

Solution code:
from itertools import*;d,o=[0]*91,ord
for _ in[0]*int(input()):d[o(input()[0])]+=1
print(sum(d[p]*d[q]*d[r]for p,q,r in combinations(map(o,'MARCH'),3)))

Submission status: Accepted

Solution code:
import itertools as i,collections as c;print(sum(p*q*r for p,q,r in i.combinations(c.Counter(s[0]for s in open(0).readlines()[1:]if s[0]in"MARCH").values(),3)))

Submission status: Accepted

Solution code:
import itertools as i,collections as c;print(sum(p*q*r for p,q,r in i.combinations(c.Counter(s[0]for s in open(0).readlines()[1:]if s[0]in"MARCH").values(),3)))

Submission status: Accepted

Solution code:
import itertools as i,collections as c;print(sum(p*q*r for p,q,r in i.combinations(c.Counter(s[0]for s in open(0).readlines()[1:] if s[0]in"MARCH").values(),3)))

Submission status: Accepted

Solution code:
import itertools as i,collections as c
b=c.Counter(s[0]for s in open(0).readlines()[1:] if s[0]in"MARCH")
print(sum(p*q*r for p,q,r in i.combinations(b.values(),3)))

Submission status: Accepted

Solution code:
import itertools as i,collections as c;n,*a=open(0).read().split()
print(sum(p*q*r for p,q,r in i.combinations(c.Counter(s[0]for s in a if s[0]in"MARCH").values(),3)))

Submission status: Accepted

Solution code:
import itertools as i,collections as c
n,*a=open(0).read().split()
b=c.Counter(s[0]for s in a if s[0]in"MARCH")
print(sum(p*q*r for p,q,r in i.combinations(b.values(),3)))

Submission status: Accepted

Solution code:
import itertools as i;d=[0]*91
for _ in[0]*int(input()):d[ord(input()[0])]+=1
print(sum(d[p]*d[q]*d[r]for p,q,r in i.combinations(map(ord,'MARCH'),3)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict
import itertools
N = int(input())
name_dict = defaultdict(list)
for _ in range(N):
    name = input()
    f_n = list(name)[0]
    name_dict[f_n].append(name)
count = 0
start_name = ['M', 'A', 'R', 'C', 'H']
del_list = []
comb_name = list(itertools.combinations(start_name, 3))
for k in name_dict.keys():
    if k not in start_name:
        del_list.append(k)
for k in del_list:
    del name_dict[k]
for name in start_name:
    if name not in name_dict:
        name_dict[name] = []
for comb in comb_name:
    a, b, c = comb
    count += len(name_dict[a]) * len(name_dict[b]) * len(name_dict[c])
print(count)

Submission status: Accepted

Solution code:
n = int(input())
s = []
for i in range(n):
    s.append(str(input()))
    
m = []
a = []
r = []
c = []
h = []
for i in s:
    if i[0] == 'M':
        m.append(i)
    if i[0] == 'A':
        a.append(i)
    if i[0] == 'R':
        r.append(i)
    if i[0] == 'C':
        c.append(i)
    if i[0] == 'H':
        h.append(i)
        
check = [0 for i in range(5)]
check[0] = len(list(set(m)))
check[1] = len(list(set(a)))
check[2] = len(list(set(r)))
check[3] = len(list(set(c)))
check[4] = len(list(set(h)))


import itertools
ans = 0
for i in itertools.combinations(check, 3):
    ans += i[0]*i[1]*i[2]
    
print(ans)

Submission status: Accepted

Solution code:
d1 = [0, 0, 0, 0, 0, 0, 1, 1, 1, 2]
d2 = [1, 1, 1, 2, 2, 3, 2, 2, 3, 3]
d3 = [2, 3, 4, 3, 4, 4, 3, 4, 4, 4]
n = int(input())
m = "MARCH"
s = [input() for i in range(n)]
d = {"M":0, "A":0, "R":0, "C":0, "H":0}
for i in range(n):
    if s[i][0] in d:
        d[s[i][0]] += 1
tot = 0
for j in range(10):
    tot += d[m[d1[j]]]*d[m[d2[j]]]*d[m[d3[j]]]
print(tot)

Submission status: Accepted

Solution code:
n=int(input())
march=[0]*5
for _ in range(n):
    str=input()
    if str[0]=='M':
        march[0]+=1
        continue
    if str[0]=='A':
        march[1]+=1
        continue
    if str[0]=='R':
        march[2]+=1
        continue
    if str[0]=='C':
        march[3]+=1
        continue
    if str[0]=='H':
        march[4]+=1
        continue

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

Submission status: Accepted

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

head = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
march = "MARCH"
for s in S:
  if(s[0] in head):
    head[s[0]] += 1
ans = 0
for i in range(3):
  for j in range(i+1,4):
    for k in range(j+1,5):
      ans += head[march[i]] * head[march[j]] * head[march[k]]
print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def is_tasai(S):
    appare_set = set([])
    for s in S:
        if s in appare_set:
            return False
        appare_set.add(s)
    return True

table = {}
def comb(n, r):
    a = 1L
    b = 1L
    for i in range(r):
        a *= n - i
        b *= r - i
    return a/b

##    if (n, r) in table:
##        return table[(n, r)]
##    if n == r:
##        table[(n, r)] = 1L
##        return 1L
##    if r == 0:
##        table[(n, r)] = 1L
##        return 1L
##    if n == 0:
##        return 0L
##    table[(n, r)] = comb(n-1, r-1)+ comb(n-1, r)
##    return table[(n, r)]


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    initial_dict = {}
    initial_dict["M"] = 0
    initial_dict["A"] = 0
    initial_dict["R"] = 0
    initial_dict["C"] = 0
    initial_dict["H"] = 0

    for i in range(N):
        input_raw = read_func().strip().split()
        if input_raw[0][0] in initial_dict:
            initial_dict[input_raw[0][0]] += 1
    M = 0
    for s in initial_dict:
        M += initial_dict[s]
    remove_num = 0L
    for s in initial_dict:
        remove_num += comb(initial_dict[s], 2) * (M - initial_dict[s])
        remove_num += comb(initial_dict[s], 3)
    print comb(M, 3) - remove_num


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools
N = int(input())
SL = [input()[0] for i in range(N)]

M = SL.count("M")
A = SL.count("A")
R = SL.count("R")
C = SL.count("C")
H = SL.count("H")

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

Submission status: Accepted

Solution code:
import numpy as np

def input_numbers():
    temp = list(map(int, input().split()))
    return temp

def GCD(a, b):
    if(a < b):
        temp = a
        a = b
        b = temp
    a = a % b
    if(a == 0):
        return b
    else:
        return GCD(a, b)

class point:
    def __init__(self, x ,y):
        self.x = x
        self.y = y

n = int(input())
names = []

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

march = 'MARCH'
count = []
for i in range(5):
    count += [0]

for i in range(n):
    for j in range(5):
        if(names[i][0] == march[j]):
            count[j] += 1

ans = 0
for i in range(5):
    for j in range(5):
        for k in range(5):
            if(i < j and j < k):
                ans += (count[i] * count[j] * count[k])

print(ans)

Submission status: Accepted

Solution code:
from itertools import*;d=[0]*91
for _ in[0]*int(input()):d[ord(input()[0])]+=1
print(sum(d[p]*d[q]*d[r]for p,q,r in combinations(map(ord,'MARCH'),3)))

Submission status: Accepted

Solution code:
from itertools import*;d=[0]*91
for _ in[0]*int(input()):d[ord(input()[0])]+=1
print(sum(p*q*r for p,q,r in combinations([d[t]for t in[77,65,82,67,72]],3)))

Submission status: Accepted

Solution code:
from itertools import*;d={};g=d.get
for t in open(0).read().split():d[t[0]]=g(t[0],0)+1
print(sum(p*q*r for p,q,r in combinations([g(t,0)for t in'MARCH'],3)))

Submission status: Accepted

Solution code:
from itertools import*;d={}
for t in open(0).read().split():d[t[0]]=d.get(t[0],0)+1
print(sum(p*q*r for p,q,r in combinations([d.get(t,0)for t in'MARCH'],3)))

Submission status: Accepted

Solution code:
from itertools import*;d=[0]*91
for _ in[0]*int(input()):d[ord(input()[0])]+=1
print(sum(p*q*r for p,q,r in combinations([d[ord(t)]for t in'MARCH'],3)))

Submission status: Accepted

Solution code:
from itertools import*;d=[0]*128
for _ in[0]*int(input()):d[ord(input()[0])]+=1
print(sum(p*q*r for p,q,r in combinations([d[ord(t)]for t in'MARCH'],3)))

Submission status: Accepted

Solution code:
from itertools import*;d=[0]*128
for t in open(0).read().split():d[ord(t[0])]+=1
print(sum(p*q*r for p,q,r in combinations([d[ord(t)]for t in'MARCH'],3)))

Submission status: Accepted

Solution code:
from itertools import*;d={};g=d.get
for t in open(0).read().split():d[t[0]]=g(t[0],0)+1
print(sum(g(p,0)*g(q,0)*g(r,0)for p,q,r in combinations('MARCH',3)))

Submission status: Accepted

Solution code:
o=ord;d=[0]*128
for t in open(0).read().split():d[o(t[0])]+=1
print(sum(d[o(p)]*d[o(q)]*d[o(r)]for p,q,r in __import__('itertools').combinations('MARCH',3)))

Submission status: Accepted

Solution code:
from itertools import*;o=ord;d=[0]*128
for t in open(0).read().split():d[o(t[0])]+=1
print(sum(d[o(p)]*d[o(q)]*d[o(r)]for p,q,r in combinations('MARCH',3)))

Submission status: Accepted

Solution code:
d={t:0for t in'MARCH'};a=0
for t in open(0).read().split():
 if t[0]in d:d[t[0]]+=1
for i in range(32):
 c=t=1
 for j,l in enumerate(d.values()):
  if i>>j&1:t*=l;c+=1
 a+=t*(c==4)
print(a)

Submission status: Accepted

Solution code:
n = int(input())
s = []
for i in range(n):
    s.append(str(input()))
    
count = [0] * 5
for i in s:
    if i[0] == "M":
        count[0] += 1
    if i[0] == "A":
        count[1] += 1
    if i[0] == "R":
        count[2] += 1
    if i[0] == "C":
        count[3] += 1
    if i[0] == "H":
        count[4] += 1
        
import itertools
ans = 0
for i in itertools.combinations(count, 3):
    ans += i[0] * i[1] * i[2]
print(ans)

Submission status: Accepted

Solution code:
import itertools
N = int(input())
S = [input() for _ in range(N)]
s = [e[0] for e in S]
d = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
for e in s:
    if e in d.keys():
        d[e] += 1
res = 0
for e1, e2, e3 in itertools.combinations(d.keys(), 3):
    res += d[e1]*d[e2]*d[e3]
print(res)

Submission status: Accepted

Solution code:
import itertools
n=int(input())
S=list(map(str,[input() for i in range(n)]))
d={}
A=['M','A','R','C','H']
for i in A:
    d[i]=0
for i in range(n):
    tmp=S[i][0]
    if tmp=='M' or tmp=='A' or tmp=='R' or tmp=='C' or tmp=='H':
        d[tmp]+=1
c=0
B=[]
for i in A:
    if d[i]!=0:
        B.append(i)
if len(B)<3:
    print(0)
else:
    ans=0
    for i in itertools.combinations(B,3):
        tmp=1
        for j in range(3):
            tmp*=d[i[j]]
        ans+=tmp
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
name = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
march = "MARCH"
for _ in range(N):
  S = input()
  if(S[0] in name):
    name[S[0]] += 1
ans = 0
for i in range(3):
  for j in range(i+1,4):
    for k in range(j+1,5):
      ans += name[march[i]] * name[march[j]] * name[march[k]]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
s = 'MARCH'
count = [0 for _ in range(len(s))]
for _ in range(N):
    t = input()[0]
    for i,c in enumerate(s):
        if c==t:
            count[i] += 1
            break

ans = 0
for i in range(len(s)):
    for j in range(i+1,len(s)):
        for k in range(j+1,len(s)):
            ans += count[i]*count[j]*count[k]

print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
from collections import Counter

n = int(input())
c = Counter([input()[:1] for _ in range(n)])

Chr = ['M', 'A', 'R', 'C', 'H']
ans = 0

for X, Y, Z in combinations(Chr, 3):
    ans += c.setdefault(X, 0)*c.setdefault(Y, 0)*c.setdefault(Z, 0)

print(ans)

Submission status: Accepted

Solution code:
#!/mnt/c/Users/moiki/bash/env/bin/python
N = int(input())
# S = [input() for _ in range(N)]
from collections import defaultdict, Counter

d = defaultdict(int)

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

# print(d)

ans = 0
charlist = list("MARCH")
for i in range(1<<5):
    if not Counter( list ( "{0:05b}".format(i)) )["1"] == 3:
        continue
    
    s = 1
    for e,i in enumerate(list("{0:05b}".format(i))):
        if i == "1":
            s *= d[ charlist[e] ]

    ans += s
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
Dic = {}
for i in range(N):   
    Name = input()
    Dic[Name[0]] = Dic.get(Name[0],0) + 1
    
tmp = [Dic.get("M",0),Dic.get("A",0),Dic.get("R",0),Dic.get("C",0),Dic.get("H",0)]

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

Submission status: Accepted

Solution code:
p=list("MARCH")
d=[0]*5
n=int(input())
for i in range(n):
    r=input()
    q=r[0]
    if r[0] in p:
        d[p.index(r[0])]+=1
c=0
for i in range(3):
    for j in range(i+1,4):
        for s in range(j+1,5):
            c+=d[i]*d[j]*d[s]
print(c)

Submission status: Accepted

Solution code:
# ABC 089
def getInt(): return int(input())
def zeros(n): return [0]*n
def db(x): 
    global debug
    if debug: print(x)
debug = False
def genCombi(n, k): # nからk個を選ぶの0/1のリストを生成　[0]から変化
    bits = zeros(n)
    for i in range(2**n):
        cnt = 0
        for j in range(n):
            bits[j] = i%2
            if bits[j]==1: cnt+=1
            i //= 2
        if cnt==k: yield bits
            
N = getInt()
S = []
march = ['M','A','R','C','H']
dc = {'M':0,'A':0,'R':0,'C':0,'H':0,}
for i in range(N): 
    S.append(input())
    if S[i][0] in march:   dc[S[i][0]]+=1
db(S);db(dc)
cnt = 0
for c in genCombi(5,3):
    prod = 1
    for i in range(5): 
        if c[i]==1: prod *= c[i]*list(dc.values())[i]
    db(prod)
    cnt += prod
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
table = list("MARCH")
L = [input() for _ in range(N)]
cnt = [0 for _ in range(5)]
L = list(map(lambda x:x[0],L))
L = list(filter(lambda x:x[0] in table,L))
for x in L:
    if x=='M':
        cnt[0] += 1
    elif x=='A':
        cnt[1] += 1
    elif x=='R':
        cnt[2] += 1
    elif x=='C':
        cnt[3] += 1
    elif x=='H':
        cnt[4] += 1
#print(cnt)
ans = 0
import itertools as it
table  = list(it.combinations(range(5),3))
for x in table:
    ans += cnt[x[0]]*cnt[x[1]]*cnt[x[2]]
print(ans)

Submission status: Accepted

Solution code:
import itertools
import math

n = int(input())
names = []

for _ in range(n):
    names.append(input())

#名前にmarchが入っている人をカウント
march = {"M":0,"A":0,"R":0,"C":0,"H":0}

for name in names:
    if name[0] in march:
        march[name[0]]+=1
march_num = 0
for count in march.values():
    if count > 0:
        march_num += 1

if march_num >= 3:
    ans = 0
    for cap_1,cap_2,cap_3 in itertools.combinations(march,3):
        cap_1_num = march[cap_1]
        cap_2_num = march[cap_2]
        cap_3_num = march[cap_3]
        ans += cap_1_num*cap_2_num*cap_3_num

else:
    ans = 0

print(ans)

Submission status: Accepted

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

from collections import defaultdict
cnt = defaultdict(int)
for name in li:
    cnt[name[0]] += 1

ans = 0
from itertools import combinations
for a, b, c in combinations('MARCH', 3):
    ans += cnt[a] * cnt[b] * cnt[c]


print(ans)

Submission status: Accepted

Solution code:
#encoding:utf-8

import math
import itertools

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

chosen_names = {"m":0,"a":0,"r":0,"c":0,"h":0}

for name in s:
    if name[0] == "M":
        chosen_names["m"] += 1
    elif name[0] == "A":
        chosen_names["a"] += 1
    elif name[0] == "R":
        chosen_names["r"] += 1
    elif name[0] == "C":
        chosen_names["c"] += 1
    elif name[0] == "H":
        chosen_names["h"] += 1

answer = 0
capitals = list("march")
capital_set = itertools.combinations(capitals,3)
for capital in capital_set:
    answer += chosen_names[capital[0]] * chosen_names[capital[1]] * chosen_names[capital[2]]


print(answer)



# def combinations_count(n,r):
#     return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))