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: Wrong Answer

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(5):
            for k in range(5):
                if i != j and i != k:
                    ans += sum_short[i]*sum_short[j]*sum_short[k]
print( ans )

Submission status: Wrong Answer

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]*(s[0]in"MARCH")for s in open(0).readlines()[1:]).values(),3)))

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[0]*5
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=l[0]*l[1]*l[2]
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
name = {}
for i in range(N):
  S = input()
  if(S[0] in ['M', 'A', 'R', 'C', 'H']):
    if(S[0] not in name):
      name[S[0]] = 1
    else:
      name[S[0]] += 1
ans = 1
cnt = 0
for k, v in name.items():
  k,v
  if(v >= 2):
    ans *= v
  else:
    cnt += 1
print(ans*cnt+cnt//3)

Submission status: Wrong Answer

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 = math.factorial(march_num)//(math.factorial(march_num-3)*math.factorial(3))
    for capital , cnt in march.items():
        if cnt > 1:
            ans += math.factorial(march_num-1)//(math.factorial(march_num-3)*math.factorial(2))*(cnt-1)
else:
    ans = 0


print(ans)

Submission status: Wrong Answer

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
ans = 0
if march_num >= 3:
    ans += math.factorial(march_num)//(math.factorial(march_num-3)*math.factorial(3))
    for capital , cnt in march.items():
        if cnt > 1:
            ans += math.factorial(march_num-1)//(math.factorial(march_num-3)*math.factorial(2))
else:
    ans = 0


print(ans)

Submission status: Wrong Answer

Solution code:
import sys,itertools
input = sys.stdin.readline


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

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

# print(set_elements_num)

comb = m*a*r + m*a*c + m*a*h
comb += m*r*c + m*r*h
comb += a*r*c + a*r*h + a*c*h
comb += r*c*h

print(comb)

Submission status: Wrong Answer

Solution code:
import sys,itertools
input = sys.stdin.readline


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

m = len({cand for cand in S if ((cand[0] == 'M')) })
a = len({cand for cand in S if ((cand[0] == 'A')) })
r = len({cand for cand in S if ((cand[0] == 'R')) })
c = len({cand for cand in S if ((cand[0] == 'C')) })
h = len({cand for cand in S if ((cand[0] == 'H')) })

# print(set_elements_num)

comb = m*a*r + m*a*c + m*a*h
comb += m*r*c + m*r*h
comb += a*r*c + a*r*h + a*c*h
comb += r*c*h

print(comb)

Submission status: Wrong Answer

Solution code:
n = int(input())

A = []
B = ['M', 'A', 'R', 'C', 'H']
C = []
for i in range(n):
    S = input()
    if(S[0] in B):
        A.append(S)
        C.append(S[0])

a = int(len(C) * (len(C) - 1) * (len(C) - 2) / 3 / 2)
for j in B:
    ans = C.count(j)
    if(ans == 2):
        a  = a - (len(C) - ans)
    elif(ans >= 3):
        a = a - int(ans*(ans - 1) / 2)

if(n < 3 or len(C) == 0):
    print(0)
else:
    print(a)

Submission status: Wrong Answer

Solution code:
import itertools
N=int(input())
S=[input() for _ in range(N)]
M=0
A=0
R=0
C=0
H=0
alives=0
march=['M','A','R','C','H']
for i in S:
    if i.startswith('M'):
        M+=1
    elif i.startswith('A'):
        A+=1
    elif i.startswith('R'):
        R+=1
    elif i.startswith('C'):
        C+=1
    elif i.startswith('H'):
        H+=1

if M==0:
    march.pop(march.index('M'))
if A==0:
    march.pop(march.index('A'))
if R==0:
    march.pop(march.index('R'))
if C==0:
    march.pop(march.index('C'))
if H==0:
    march.pop(march.index('H'))

if len(march)<3:
    print(0)

seq=list(itertools.combinations(march,3))

ans=0
for i in seq:
    temp=1
    for ch in i:
        if ch=='M':
            temp*=M
        if ch=='A':
            temp*=A
        if ch=='R':
            temp*=R
        if ch=='C':
            temp*=C
        if ch=='H':
            temp*=H
    ans+=temp

print(ans)

Submission status: Wrong Answer

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

for i in range(N):
    if S[i][0] == "M":
        march[0] += 1
    if S[i][0] == "A":
        march[1] += 1
    if S[i][0] == "R":
        march[2] += 1
    if S[i][0] == "C":
        march[3] += 1
    if S[i][0] == "H":
        march[4] += 1
ans = 0
print(march)
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: Wrong Answer

Solution code:
import itertools

n=int(input())
list1=[]
ss=['M', 'A', 'R', 'C', 'H']

for j in range(n):
  s=input()
  for k in range(5):
    if s[0]==ss[k]:
      list1.append(s[0])

#list1.sort()

list2=list(itertools.combinations(list1, 3))

cnt=0
#for j in range(len(list2)):
#  if len(list2[j])==len(set(list2[j])):
#    cnt+=1

print(cnt)

Submission status: Wrong Answer

Solution code:
import itertools

n=int(input())
list1=[]
ss=['M', 'A', 'R', 'C', 'H']

for j in range(n):
  s=input()
  for k in range(5):
    if s[0]==ss[k]:
      list1.append(s[0])

#list1.sort()

#list2=list(itertools.combinations(list1, 3))

cnt=0
#for j in range(len(list2)):
#  if len(list2[j])==len(set(list2[j])):
#    cnt+=1

print(cnt)

Submission status: Wrong Answer

Solution code:
import itertools

n=int(input())
list1=[]
for j 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':
    list1.append(s[0])

list1.sort()

list2=list(itertools.combinations(list1, 3))

cnt=0
#for j in range(len(list2)):
#  if len(list2[j])==len(set(list2[j])):
#    cnt+=1

print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
l_ = [["M", 0], ["A", 0], ["R", 0], ["C", 0], ["H", 0]]
l = []

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

    for j in l_:
        if s[0] == j[0]:
            j[1] += 1
            break

for i in l_:
    if i[1] != 0:
        l.append(i[1])

k = len(l)
r = 0

if k < 3:
    r = 0
elif k == 3:
    r = l[0] * l[1] * l[2]
elif k == 4:
    for i in range(1,5):
        r += l[i%4] * l[i%3] * l[i%2]
elif k == 5:
    r = 1
    for i in range(5):
        r *= l[i]
    for i in range(5):
        for j in range(5):
            r /= l[i] + l[j]

print(r)

Submission status: Wrong Answer

Solution code:
# n = int(input())
# arr = []
# for i in range(n):
#     arr += [list(input())]
n = 5
arr = [['Z','H'],['Z','N'],['Z','A'],['Z','O'],['Z','I']]

MARCH = [0] * 5    
    
for j in range(n):
    if arr[j][0] == 'M':
        MARCH[0] += 1
    elif arr[j][0] == 'A':
        MARCH[1] += 1
    elif arr[j][0] == 'R':
        MARCH[2] += 1
    elif arr[j][0] == 'C':
        MARCH[3] += 1
    elif arr[j][0] == 'H':
        MARCH[4] += 1

def C(a,b):
    aa = 1
    bb = 1
    for k in range(a-b+1, a+1):
        aa *= k
    for l in range(1, b+1):
        bb *= l
    return int(aa/bb)
        
ans = C(sum(MARCH), 3)

for m in range(5):
    if MARCH[m] == 2:
        ans -= C(sum(MARCH)-MARCH[m],1)
    elif MARCH[m] >= 3:
        ans -= C(MARCH[m],2) * C(sum(MARCH)-MARCH[m],1)
        ans -= C(MARCH[m],3)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = []
m = ['M', 'A', 'R', 'C', 'H']
M, A, R, C, H = 0, 0, 0, 0, 0
ans = 0

if N <= 2:
    print(0)
else:
    for i in range(N):
        na = input()
        if na[0] in m:
            S.append(na)
    S =set(S)
    for i in S:
        fa = i[0]
        if fa == 'M':
            M += 1
        elif fa == 'A':
            A += 1
        elif fa == 'R':
            R += 1
        elif fa =='C':
            C += 1
        else:
            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 + R*C*H)

Submission status: Wrong Answer

Solution code:
N = int(input())
Sdic = {}
L = ["M","A","R","C","H"]
for i in L:
    Sdic[i] = []

tN = N
for i in range(N):
    s = input()
    if s[0] in L:
        Sdic[s[0]].append(s)
    else:
        tN -= 1

cnt = 0
for val in Sdic.values():
    if len(val) == 0:
        cnt += 1
if cnt >=3:
    print(0)
    exit()

zen = tN*(tN-1)*(tN-2) / 6

one = 0
for i in ["M","A","R","C","H"]:
    c = len(Sdic[i])
    if c >= 3:
        one += c * (c-1) * (c-2)  / 6


lis = []
for i in range(len(L)):
    for j in range(len(L)):
        if i < j:
            lis.append(len(Sdic[L[i]]) + len(Sdic[L[j]]))

two = 0
for c in lis:
    if c >= 3:
        two += c * (c-1) * (c-2)  / 6
print(int(zen - one - two))

Submission status: Wrong Answer

Solution code:
N = int(input())
Sdic = {}
L = ["M","A","R","C","H"]
for i in L:
    Sdic[i] = []

tN = N
for i in range(N):
    s = input()
    if s[0] in L:
        Sdic[s[0]].append(s)
    else:
        tN -= 1

cnt = 0
for val in Sdic.values():
    if len(val) == 0:
        cnt += 1
if cnt >=3:
    print(0)
    exit()

zen = tN*(tN-1)*(tN-2) / 6

one = 0
for i in ["M","A","R","C","H"]:
    c = len(Sdic[i])
    if c >= 3:
        one += c * (c-1) * (c-2)  / 6


lis = []
for i in range(len(L)):
    for j in range(len(L)):
        if i < j:
            lis.append(len(Sdic[L[i]]) + len(Sdic[L[j]]))

two = 0
for c in lis:
    if c >= 3:
        two += c * (c-1) * (c-2)  / 6
print(zen , one , two)
print(int(zen - one - two))

Submission status: Wrong Answer

Solution code:
N = int(input())
Sdic = {}
L = ["M","A","R","C","H"]
for i in L:
    Sdic[i] = []

tN = N
for i in range(N):
    s = input()
    if s[0] in L:
        Sdic[s[0]].append(s)
    else:
        tN -= 1


zen = tN*(tN-1)*(tN-2) / 6

one = 0
for i in ["M","A","R","C","H"]:
    c = len(Sdic[i])
    if c >= 3:
        one += c * (c-1) * (c-2)  / 6


lis = []
for i in range(len(L)):
    for j in range(len(L)):
        if i < j:
            lis.append(len(Sdic[L[i]]) + len(Sdic[L[j]]))

two = 0
for c in lis:
    if c >= 3:
        two += c * (c-1) * (c-2)  / 6

print(int(zen - one - two))

Submission status: Wrong Answer

Solution code:
n=int(input())
m,a,r,c,h=0,0,0,0,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
x=[m,a,r,c,h]
cnt=x.count(0)
for i in range(cnt):
    x.remove(0)

l=len(x)
if l<3:
    print(0)
elif l==3:
    print(x[0]*x[1]*x[2])
elif l==4:
    a,b,c,d=x[0],x[1],x[2],x[3]
    print(a*b*c+a*b*d+a*c*d+b*c*d)
else:
    a,b,c,d,e=x[0],x[1],x[2],x[3],x[4]
    print(5)

Submission status: Wrong Answer

Solution code:
n=int(input())
m,a,r,c,h=0,0,0,0,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
x=[m,a,r,c,h]
cnt=x.count(0)
for i in range(cnt):
    x.remove(0)

l=len(x)
if l<3:
    print(0)
elif l==3:
    print(x[0]*x[1]*x[2])
elif l==4:
    print(4)
else:
    print(5)

Submission status: Wrong Answer

Solution code:
n=int(input())
m,a,r,c,h=0,0,0,0,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
print(max(1,m)*max(1,a)*max(1,r)*max(1,c)*max(1,h))

Submission status: Wrong Answer

Solution code:
import re
from itertools import groupby
from itertools import groupby, combinations
import functools
import operator

pattern = r"^(M|A|R|C|H).*"
checker = re.compile(pattern)

N = int(input())
names = []
for i in range(N):
    name = input()
    if checker.match(name):
        names.append(name)

counts = []
for group, item in groupby(names, lambda x:x[0]):
    counts.append(len(list(item)))
comb = functools.reduce(operator.mul, counts) if len(counts) >= 3 else 0
print(comb)

Submission status: Wrong Answer

Solution code:
import re
from itertools import groupby

def nCr(n, r):
    """
    Calculate the number of combination (nCr = nPr/r!).
    The parameters need to meet the condition of n >= r >= 0.
    It returns 1 if r == 0, which means there is one pattern
    to choice 0 items out of the number of n.
    """

    # 10C7 = 10C3
    r = min(r, n-r)

    # Calculate the numerator.
    numerator = 1
    for i in range(n, n-r, -1):
        numerator *= i

    # Calculate the denominator. Should use math.factorial?
    denominator = 1
    for i in range(r, 1, -1):
        denominator *= i

    return numerator // denominator

pattern = r"^(M|A|R|C|H).*"
checker = re.compile(pattern)

N = int(input())
names = [None]*N
hasMarch = [None]*N
for i in range(N):
    name = input()
    if checker.match(name):
        names[i] = name
        
groups = [n for n in groupby(names, lambda x:x[0] if x is not None else 0)]
n_groups = len(groups) - 1
comb = nCr(n_groups, 3) if n_groups >=3 else 0
print(comb)

Submission status: Wrong Answer

Solution code:
# abc89c

N = int(input())

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

T.sort()
S = [T[0]]
for i in range(1,N):
    if T[i]!=T[i-1]: S.append(T[i])
cnt_lst = [0,0,0,0,0]
for i in range(len(S)):
    if S[i][0]=="M":
        cnt_lst[0] += 1
    elif S[i][0]=="A":
        cnt_lst[1] += 1
    elif S[i][0]=="R":
        cnt_lst[2] += 1
    elif S[i][0]=="C":
        cnt_lst[3] += 1
    elif S[i][0]=="H":
        cnt_lst[4] += 1

cnt = 0
for num in cnt_lst:
    if num!=0: cnt += 1
if cnt<=2: print(0)
elif cnt==3:
    ans = cnt_lst[0]*cnt_lst[1]*cnt_lst[2] + cnt_lst[0]*cnt_lst[1]*cnt_lst[3] + cnt_lst[0]*cnt_lst[1]*cnt_lst[4]\
        + cnt_lst[0]*cnt_lst[2]*cnt_lst[3] + cnt_lst[0]*cnt_lst[2]*cnt_lst[4] + cnt_lst[0]*cnt_lst[3]*cnt_lst[4]\
        + cnt_lst[1]*cnt_lst[2]*cnt_lst[3] + cnt_lst[1]*cnt_lst[2]*cnt_lst[4] + cnt_lst[1]*cnt_lst[3]*cnt_lst[4]\
        + cnt_lst[2]*cnt_lst[3]*cnt_lst[4]
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
M = []
A = []
R = []
C = []
H = []
for i in range(N):
    name = input()
    if name[0] == "M":
        M.append(name)
    if name[0] == "A":
        A.append(name)
    if name[0] == "R":
        R.append(name)
    if name[0] == "C":
        C.append(name)
    if name[0] == "H":
        H.append(name)

total = len(M)*len(A)*len(H)+ len(M)*len(R)*len(H) + len(M)*len(A)*len(R) + len(M)*len(R)*len(C) + len(M)*len(C)*len(H) + len(A)*len(R)*len(C) +len(A)*len(R)*len(H) + len(A)*len(C)*len(H)
print(total)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = []
for i in range(N):
    s.append(input())
m = 0
a = 0
r = 0
c = 0
h = 0
for person in s:
  if person[0]=='M':
    m += 1
  elif person[0]=='A':
    a += 1
  elif person[0]=='R':
    r += 1
  elif person[0]=='C':
    c += 1
  elif person[0]=='H':
    h += 1
    
ans = m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h*r*c*h
print(int(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
s = []
for i in range(N):
    s.append(input())
m = 0
a = 0
r = 0
c = 0
h = 0
for person in s:
  if person[0]=='M':
    m += 1
  elif person[0]=='A':
    a += 1
  elif person[0]=='R':
    r += 1
  elif person[0]=='C':
    c += 1
  elif person[0]=='H':
    h += 1
    
ans = m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h*r*c*h
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = [input() for i in range(N)]
U = []
n = [0,0,0,0,0]
result = 0

for i in range(N):
    if S[i][0] == 'M' or S[i][0] == 'A' or S[i][0] == 'R' or S[i][0] == 'C' or S[i][0] == 'H':
        U.append(S[i][0])
    
    if S[i][0] == 'M':
        n[0] += 1
    if S[i][0] == 'A':
        n[1] += 1
    if S[i][0] == 'R':
        n[2] += 1
    if S[i][0] == 'C':
        n[3] += 1
    if S[i][0] == 'H':
        n[4] += 1
        
un = len(set(U))

if un == 3:
    result = 1
    for i in range(5):
        if n[i] != 0:
            result = result + (n[i] - 1)
    
if un == 4:
    result = 4
    for i in range(5):
        if n[i] != 0:
            result = result + 3*(n[i] - 1)
            
if un == 5:
    result = 10
    for i in range(5):
        if n[i] != 0:
            result = result + 4* (n[i] - 1)

print(result)

Submission status: Wrong Answer

Solution code:
def m():
    n = int(input())
    S = [str(input()) for _ in range(n)]
    m = 0
    a = 0
    r = 0
    c = 0
    h = 0
    x = [0, 0, 0, 0, 0, 0, 1, 1, 1, 2]
    y = [1, 1, 1, 2, 2, 3, 2, 2, 3, 3]
    z = [2, 3, 4, 3, 4, 4, 4, 4, 4, 4]
    for i in range(n):
        if S[i][0] == "M":
            m += 1
        elif S[i][0] == "A":
            a += 1
        elif S[i][0] == "R":
            r += 1
        elif S[i][0] == "C":
            c += 1
        elif S[i][0] == "H":
            h += 1
    ans = 0
    d = [m, a, r, c, h]
    for j in range(10):
        ans += d[x[j]] * d[y[j]] * d[z[j]]
    return ans
print(m())

Submission status: Wrong Answer

Solution code:
def m():
    n = int(input())
    S = [str(input()) for _ in range(n)]
    m = 0
    a = 0
    r = 0
    c = 0
    h = 0
    x = [0, 0, 0, 0, 0, 0, 1, 1, 1, 2]
    y = [1, 1, 1, 2, 2, 3, 2, 2, 3, 3]
    z = [2, 3, 4, 3, 4, 3, 4, 4, 4, 4]
    for i in range(n):
        if S[i][0] == "M":
            m += 1
        elif S[i][0] == "A":
            a += 1
        elif S[i][0] == "R":
            r += 1
        elif S[i][0] == "C":
            c += 1
        elif S[i][0] == "H":
            h += 1
    ans = 0
    d = [m, a, r, c, h]
    for j in range(10):
        ans += d[x[j]] * d[y[j]] * d[z[j]]
    return ans
print(m())

Submission status: Wrong Answer

Solution code:
#!C:\Users\daichi\Anaconda3/python.exe
# -*- coding: utf-8 -*-
import math
import itertools
#def combinations_count(n, r):
 #   return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


N = int(input())
a = []
T = [0,0,0,0,0]

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

i=0
for i in range(N):
    if( a[i].startswith('M') ):
        T[0] = T[0]+1
    if( a[i].startswith('A') ):
        T[1] = T[1]+1
    if( a[i].startswith('R') ):
        T[2] = T[2]+1
    if( a[i].startswith('C') ):
        T[3] = T[3]+1
    if( a[i].startswith('H') ):
        T[4] = T[4]+1
        
n = T[0]+T[1]+T[2]+T[3]+T[4]
#print(n)
#print(combinations_count(SUM, 3) )
r=3
#com = math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
i=0
com=1
for i in range(r):
    com = com * (n-i)
#print(com)
com = com / math.factorial(r)

print(com)

Submission status: Wrong Answer

Solution code:
N = int(input())
M = []
A = []
R = []
C = []
H = []

for i in range(N):
    temp = input()
    init_temp = list(temp)
    if 'M' == init_temp[0]:
        M.append(temp)
    elif 'A' == init_temp[0]:
        A.append(temp)
    elif 'R' == init_temp[0]:
        R.append(temp)
    elif 'C' == init_temp[0]:
        C.append(temp)
    elif 'H' == init_temp[0]:
        H.append(temp)
    else:
        pass

M = len(list(set(M)))
A = len(list(set(A)))
R = len(list(set(R)))
C = len(list(set(C)))
H = len(list(set(H)))

D = [M, A, R, C, H]
#10通り書き出す
A = [0, 0, 0, 0, 0, 0, 1, 1, 1, 2]
B = [1, 1, 1, 2, 2, 3, 2, 2, 3, 3]
C = [2, 3, 4, 3, 4, 4, 3, 4, 4, 4]

ans = 0.0

for i in range(10):
    ans += D[A[i]] * D[B[i]] * D[C[i]]

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
sd = {}
hl = ["M","A","R","C","H"]
for i in range(n):
    s = input()
    head = s[0]
    
    if not head in hl:
        continue
        
    if head in sd:
        sd[head] += 1
    else:
        sd[head] = 1
        
values = list(sd.values())
#print(values)
length = len(values)
counts = 0
if length < 3:
    print(0)
else:
    for i in range(length-2):
        for j in range(i+1,length-1):
            for k in range(j+1,length):
#                print(i,j,k)
                counts += values[i]*values[j]*values[k]

print(counts)

Submission status: Wrong Answer

Solution code:
n = int(input())

d = {"M":0,"R":0,"A":0,"C":0,"H":0}
S = []
num = 0

for i in range(n):
    S.append(input())


for s in S:
    #キーの中にs[0]の文字があるときのみ
    if s[0] in list(d.keys()):
        d[s[0]] += 1



for al1 in list(d.keys()):
    for al2 in list(d.keys()):
        for al3 in list(d.keys()):
            if al1 != al2 and al1 != al3 and al2 != al3:
                print(al1,al2,al3)
                num += d[al1]*d[al2]*d[al3]

print(int(num/6))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
for i in range(N):
    A.append(input())
k = 0
c = [ 0,0,0,0,0]
for i in A:
  if i[0] == 'M':
    c[0] += 1
  if i[0] == 'A':
    c[1] += 1
  if i[0] == 'R':
    c[2] += 1
  if i[0] == 'C':
    c[3] += 1
  if i[0] == 'H':
    c[4] += 1

print(c)
if not c.count(0) >= 3:
  k += c[0] * c[1] * c[2] + c[0] * c[1] * c[3] + c[0] * c[1] * c[4] + c[0] * c[2] * c[3] + c[0] * c[2] * c[4] + c[0] * c[3] * c[4] + c[1] * c[2] * c[3] + c[1] * c[2] * c[4] + c[1] * c[3] * c[4] + c[2] * c[3] * c[4] 

print(k)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
for i in range(N):
    A.append(input())
k = 0
c = [ 0,0,0,0,0]
for i in A:
  if i[0] == 'm':
    c[0] += 1
  if i[0] == 'a':
    c[1] += 1
  if i[0] == 'r':
    c[2] += 1
  if i[0] == 'c':
    c[3] += 1
  if i[0] == 'h':
    c[4] += 1

print(c)
if not c.count(0) >= 3:
  k += c[0] * c[1] * c[2] + c[0] * c[1] * c[3] + c[0] * c[1] * c[4] + c[0] * c[2] * c[3] + c[0] * c[2] * c[4] + c[0] * c[3] * c[4] + c[1] * c[2] * c[3] + c[1] * c[2] * c[4] + c[1] * c[3] * c[4] + c[2] * c[3] * c[4] 

print(k)

Submission status: Wrong Answer

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[2]
result+=march[1]*march[2]*march[3]
result+=march[1]*march[3]*march[4]
result+=march[2]*march[3]*march[4]
print(result)

Submission status: Wrong Answer

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 += i*j*k
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
a = ['']*N
for i in range(N):
    a[i] = list(input())[0]
print(a)
c_list = [0]*5
MARCH = ['M','A','R','C','H']
c_list = [a.count(i) for i in MARCH]
print(c_list)
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: Wrong Answer

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 - 2)       
print(max(all,0))

Submission status: Wrong Answer

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 >= 2:
        k = i * (i -1) // 2
        all -= k*(n-2)
    if i >= 3:
        k = i * (i - 1) * (i - 2) // 6
        all -= k
print(all)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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 >= 2:
        k = i * (i -1) // 2
        all -= k*(n-2)
    elif i >= 3:
        k = i * (i - 1) * (i - 2) // 6
        all -= k*1
print(all)

Submission status: Wrong Answer

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 >= 2:
        k = i * (i -1) // 2
        all -= k*(n-2)
    elif i >= 3:
        k = i * (i - 1) * (i - 2) // 6
        all -= 1
print(all)

Submission status: Wrong Answer

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):
        u.append(t[j])
    if len(u) == 3:
        ans += u[0]*u[1]*u[2]
print(ans)

Submission status: Wrong Answer

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['R'] > 0 and d['H'] > 0:
        c += d['A']*d['R']*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: Wrong Answer

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 + r * c * h)