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:
# -*- coding: utf-8 -*-


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

check = 0
check_m = 0
check_a = 0
check_r = 0
check_c = 0
check_h = 0

for i in name:
    if i[0] == "M":
        if check_m == 0:
            check += 1
        check_m += 1
    elif i[0] == "A":
        if check_a == 0:
            check += 1
        check_a += 1
    elif i[0] == "R":
        if check_r == 0:
            check += 1
        check_r += 1
    elif i[0] == "C":
        if check_c == 0:
            check += 1
        check_c += 1
    elif i[0] == "H":
        if check_h == 0:
            check += 1
        check_h += 1

if check < 2:
    print(0) 
elif check == 3:
    s = []
    if check_m != 0:
        s.append(check_m)
    if check_a != 0:
        s.append(check_a)
    if check_r != 0:
        s.append(check_r)
    if check_c != 0:
        s.append(check_c)
    if check_h != 0:
        s.append(check_h)
    se = 1
    for i in s:
        se = se*i
    print(int(se))
    
elif check == 4:
    s = []
    if 1 < check_m:
        s.append(check_m)
    if 1 < check_a:
        s.append(check_a)
    if 1 < check_r:
        s.append(check_r)
    if 1 < check_c:
        s.append(check_c)
    if 1 < check_h:
        s.append(check_h)
    n = (check*(check-1)*(check-2))/6
    if len(s) == 0:
        print(int(n))
    else:
        se = 1
        for i in s:
            se += i*(n-1)
        print(int(se))

elif check == 5:
    s = []
    if 1 < check_m:
        s.append(check_m)
    if 1 < check_a:
        s.append(check_a)
    if 1 < check_r:
        s.append(check_r)
    if 1 < check_c:
        s.append(check_c)
    if 1 < check_h:
        s.append(check_h)
    n = (check*(check-1)*(check-2))/6
    if len(s) == 0:
        print(int(n))
    else:
        se = 1
        for i in s:
            se += i*(n-1)
        print(int(se))

Submission status: Wrong Answer

Solution code:
import functools

N = int(input())
march = ["M","A","R","C","H"]
S = {}
for m in march:
    S[m] = 0

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

aS = []
for s in S.values():
    if s != 0:
        aS.append(s)

mul = 1
ans = 0
sum = 0
for s in aS:
    mul = mul * s
    sum += 1
if sum == 3:
    ans = mul
elif sum == 4:
    # ans = mul * 4
    for s in aS:
        ans = ans + mul / s
elif sum == 5:
    # ans = mul * 5
    for i in range(5):
        for j in range(i+1,5):
            print(ans)
            ans = ans + mul / aS[i] / aS[j]
print(int(ans))

Submission status: Wrong Answer

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


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

check = 0
check_m = 0
check_a = 0
check_r = 0
check_c = 0
check_h = 0

for i in name:
    if i[0] == "M":
        if check_m == 0:
            check += 1
        check_m += 1
    elif i[0] == "A":
        if check_a == 0:
            check += 1
        check_a += 1
    elif i[0] == "R":
        if check_r == 0:
            check += 1
        check_r += 1
    elif i[0] == "C":
        if check_c == 0:
            check += 1
        check_c += 1
    elif i[0] == "H":
        if check_h == 0:
            check += 1
        check_h += 1

if check < 2:
    print(0) 
elif check == 3:
    s = []
    if check_m != 0:
        s.append(check_m)
    if check_a != 0:
        s.append(check_a)
    if check_r != 0:
        s.append(check_r)
    if check_c != 0:
        s.append(check_c)
    if check_h != 0:
        s.append(check_h)
    se = 1
    for i in s:
        se = se*i
    print(se)
    
elif check == 4:
    s = []
    if 1 < check_m:
        s.append(check_m)
    if 1 < check_a:
        s.append(check_a)
    if 1 < check_r:
        s.append(check_r)
    if 1 < check_c:
        s.append(check_c)
    if 1 < check_h:
        s.append(check_h)
    n = (check*(check-1)*(check-2))/6
    if len(s) == 0:
        print(n)
    else:
        se = 1
        for i in s:
            se += i*(n-1)
        print(se)

elif check == 5:
    s = []
    if 1 < check_m:
        s.append(check_m)
    if 1 < check_a:
        s.append(check_a)
    if 1 < check_r:
        s.append(check_r)
    if 1 < check_c:
        s.append(check_c)
    if 1 < check_h:
        s.append(check_h)
    n = (check*(check-1)*(check-2))/6
    if len(s) == 0:
        print(n)
    else:
        se = 1
        for i in s:
            se += i*(n-1)
        print(int(se))

Submission status: Wrong Answer

Solution code:

n = int(input())
group = []
for i in range(n):
    group.append(input()[0])
work = set([x for x in group if x == "M" or x == "A" or x == "R" or x == "C" or x == "H"])

print((len(group)-len(work)))

Submission status: Wrong Answer

Solution code:
from math import factorial

def main():
    N = int(input())
    S = tuple(input() for _ in [0] * N)

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

    lst = [i for i in name.values() if i]
    n = len(lst)
    if n < 3:
        print(0)
        return

    comb = factorial(n) // (factorial(3) * factorial(n - 3))
    k = 0
    for l in lst:
        comb *= l
        if l > 1 and n > 3:
            k += n - 3
    print(comb - k)

main()

Submission status: Wrong Answer

Solution code:
import itertools
import math

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

count_M = 0
count_A = 0
count_R = 0
count_C = 0
count_H = 0

for l in S_list:
    if l.startswith('M'):
        count_M += 1
    elif l.startswith('A'):
        count_A += 1
    elif l.startswith('R'):
        count_R += 1
    elif l.startswith('C'):
        count_C += 1
    elif l.startswith('H'):
        count_H += 1

count = [count_M,count_A,count_R,count_C,count_H]
a = sum(count)

x = a*(a-1)*(a-2)/math.factorial(3)

for c in count:
    if c > 2:
        x -= c*(c-1)*(c-2)/math.factorial(3)
    elif c == 2:
        x -= (a-2)

print(int(x))

Submission status: Wrong Answer

Solution code:
import functools

N = int(input())
march = ["M","A","R","C","H"]
S = {}
for m in march:
    S[m] = 0

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

aS = []
for s in S.values():
    if s != 0:
        aS.append(s)

mul = 1
ans = 0
sum = 0
for s in aS:
    mul = mul * s
    sum += 1
if sum == 3:
    ans = mul
elif sum == 4:
    # ans = mul * 4
    for s in aS:
        ans = ans + mul / s
elif sum == 5:
    # ans = mul * 5
    for i in range(5):
        for j in range(i,5):
            ans = ans + mul / aS[i] / aS[j]
print(int(ans))

Submission status: Wrong Answer

Solution code:
import itertools

n = int(input())

array = []
dict = {}
dict["M"] = dict["A"] = dict["R"] = dict["C"] = dict["H"] = 0
for i in range(n):
    tmp = input()
    dict[tmp[0]] = dict.get(tmp[0], 0) + 1

if dict["M"] == 0 and dict["A"] == 0 and dict["R"] == 0 and dict["C"] == 0 and dict["H"] == 0:
    print(0)
else:
    tmp = []
    for i in [dict["M"], dict["A"], dict["R"], dict["C"], dict["H"]]:
        if i != 0:
            tmp.append(i)
    judge = 0
    for l in tmp:
        if l != 0 and l != 1:
            tmp2 = list(tmp)
            tmp2.remove(l)
            judge += (l - 1) * len(tmp2)
    tmp3 = sum(tmp)
    res = tmp3 * (tmp3 - 1) * (tmp3 - 2) // 6 - judge

    print(res if len(tmp) >= 3 else 0)

Submission status: Wrong Answer

Solution code:
import itertools

ans =  0
n = int(input())
group = []
for i in range(n):
    group.append(input()[0])

group = [x for x in group if x == "M" or x == "A" or x == "R" or x == "C" or x == "H"]
for j in itertools.combinations(group,3):
    ans += 1
    
print(ans-len(set(group))+1)

Submission status: Wrong Answer

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

def qwe(y):
    m = 0
    a = 0
    r = 0
    c = 0
    h = 0
    for i in y:
        if i == 'M':
            m += 1
        elif i == 'A':
            a += 1
        elif i == 'R':
            r += 1
        elif i == 'C':
            c += 1
        elif i == 'H':
            h += 1
        else:
            pass
    q = [m,a,r,c,h]
    return q

def qwer(arr):
    count = 0
    coun = 0
    for j in arr:
        if j == 0:
            count += 1
        else:
            coun += 1
    if count == 5:
        return 0
    else:
        if arr[0] == 0:
            arr[0] = 1
        if arr[1] == 0:
            arr[1] = 1
        if arr[2] == 0:
            arr[2] = 1
        if arr[3] == 0:
            arr[3] = 1
        if arr[4] == 0:
            arr[4] = 1
        if coun == 4:
            asd = arr[0]*arr[1]*arr[2]*arr[3]*arr[4]*4 - 1
            return asd
        if coun == 5:
            asd = arr[0]*arr[1]*arr[2]*arr[3]*arr[4]*10 - 4
            return asd
v = qwe(s)
print(qwer(v))

Submission status: Wrong Answer

Solution code:
import itertools

n = int(input())

array = []
dict = {}
dict["M"] = dict["A"] = dict["R"] = dict["C"] = dict["H"] = 0
for i in range(n):
    tmp = input()
    dict[tmp[0]] = dict.get(tmp[0], 0) + 1

if dict["M"] == 0 and dict["A"] == 0 and dict["R"] == 0 and dict["C"] == 0 and dict["H"] == 0:
    print(0)
else:
    tmp = []
    for i in [dict["M"], dict["A"], dict["R"], dict["C"], dict["H"]]:
        if i != 0:
            tmp.append(i)
    judge = 0
    for l in tmp:
        if l != 0 and l != 1:
            tmp2 = list(tmp)
            tmp2.remove(l)
            judge += (l-1)*len(tmp2)
    tmp3 = sum(tmp)
    res = tmp3*(tmp3-1)*(tmp3-2) // 6 -judge

    print(res)

Submission status: Wrong Answer

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

n = int(input().strip())
s = [input().strip() for _ in range(n)]
num_m = len([True for _s in s if _s[0] == "M"])
num_a = len([True for _s in s if _s[0] == "A"])
num_r = len([True for _s in s if _s[0] == "R"])
num_c = len([True for _s in s if _s[0] == "C"])
num_h = len([True for _s in s if _s[0] == "H"])
print(num_m * num_a * num_r + num_m * num_a * num_c + num_m * num_a * num_h + num_m * num_r * num_c
      + num_m * num_r * num_h + num_m * num_c * num_h + num_a * num_r * num_c +
      num_a * num_r * num_h + num_r * num_c * num_h)

Submission status: Wrong Answer

Solution code:
import itertools
import math

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

count_M = 0
count_A = 0
count_R = 0
count_C = 0
count_H = 0

for l in S_list:
    if l.startswith('M'):
        count_M += 1
    elif l.startswith('A'):
        count_A += 1
    elif l.startswith('R'):
        count_R += 1
    elif l.startswith('C'):
        count_C += 1
    elif l.startswith('H'):
        count_H += 1

count = [count_M,count_A,count_R,count_C,count_H]
a = 0
for c in count:
    if c > 0:
        a += c

x = a*(a-1)*(a-2)/math.factorial(3)

for c in count:
    if c == 3:
        x -= 1
    elif c == 2:
        x -= (a-2)

print(int(x))

Submission status: Wrong Answer

Solution code:
from collections import Counter
from math import factorial
N = int(input())
S = [input()[0:1:] for i in range(N)]

march = ["M","A","R","C","H"]
list = []
c = Counter(S)
for k,v in c.items():
    if k in march:
        list.append(v)

ans = 0
if len(list) >= 3:
    for i in range(len(list)):
        for j in range(len(list)-1):
            for k in range(len(list)-2):
                if (i != j+1) and (j+1 != k+2) and (k+2 != i) and (i<j+1) and (j<k+1):
                    ans += list[i] * list[j+1] * list[k+2]
                    print(ans,i,j+1,k+2)

print(ans)

Submission status: Wrong Answer

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

def _is_march(c):
    if (c == "M") or (c == "A") or (c == "R") or (c == "C") or (c == "H"):
        return True
    return False

if __name__ == "__main__":
    N = int(input())
    march = []
    for i in range(N):
        name = input()
        if _is_march(name[0]):
            march.append(name)
    n = len(march)

    bunsi = n * (n-1) * (n-2)
    bunbo = 3 * 2 * 1
    print(int(bunsi/bunbo))

Submission status: Wrong Answer

Solution code:
import numpy
import sys
import math

N=int(input())
a = []
for i in range(N):
  a.append(input())
dic = {}
for n in a:
  if n[0] in ['M','A','R','C','H']:
    if n[0] not in dic:
      dic[n[0]] = [n]
    else:
      dic[n[0]].append(n)
if len(dic)<3:
  print(0)
  exit()

basic = int(math.factorial(len(dic))/(math.factorial(3)*math.factorial(len(dic)-3)))
for i in dic:
  names = dic[i]  
  if len(names)>1:
    basic *= (2 * (len(names)-1))
basic -= (len(dic)-3)
print(basic)

Submission status: Wrong Answer

Solution code:
import math

N=int(input())
S=[]
m=a=r=c=h=0
for i in range(N):
    S.append(list(input()))
    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

t=0
if m>=1: t+=1
if a>=1: t+=1
if r>=1: t+=1
if c>=1: t+=1
if h>=1: t+=1

ans=math.factorial(t)//6

if m>1:
    ans*=m
    ans-=t-3
if a>1:
    ans*=a
    ans-=t-3
if r>1:
    ans*=r
    ans-=t-3
if c>1:
    ans*=c
    ans-=t-3
if h>1:
    ans*=h
    ans-=t-3

print(ans)

Submission status: Wrong Answer

Solution code:
def conb(a, b):
    ans = 1
    for i in range(b):
        ans *= (a - i)
        ans /= (i + 1)
    return ans
    
A = {"M":0, "A":0, "R":0, "C":0, "H":0}
N = int(input())
S = [input() for i in range(N)]
S = [c for c in S if c[0] in A]

for c in S:
    A[c[0]] += 1

N = len(S)    
if N >= 3:
    zen = conb(N , 3)
    for a in A:
        a = A[a]
        if a > 2:
            zen -= conb(a, 3) * (N - a)
        elif a > 1:
            zen -= (N - a)
    print(int(zen))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
N=int(input())
M=[]
A=[]
R=[]
C=[]
H=[]
for i in range(N):
  s=input()
  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)
  elif s[0]=='H':
    H.append(s)
cnt=[len(M),len(A),len(R),len(C),len(H)]
res=sum(cnt)
res=int(res*(res-1)*(res-2)/6)

def dif(n):
  if cnt[n]==0 or cnt[n]==1:
    return 0
  else:
    a=0
    for i in range(5):
      if i!=n:
        a+=cnt[i]
  if cnt[n]==2:
    return a
  else:
    b=cnt[n]*(cnt[n]-1)*(cnt[n]-2)/6
    return int(a+b)
for i in range(5):
  res-=dif(i)
c=0
for j in range(5):
  if cnt[j]==0:
    c+=1
if c>2:
  print(0)
else:
  print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())

nm = 0
na = 0
nr = 0
nc = 0
nh = 0

for i in range(n):
    a = input()
    for j in a:
        b = j
        break
    if b == "M":
        nm += 1
    elif b == "A":
        na += 1
    elif b == "R":
        nr += 1
    elif b == "C":
        nc += 1
    elif b == "H":
        nh += 1

count = 0
if nm == 0:
    count += 1
if na == 0:
    count += 1
if nr == 0:
    count += 1
if nc == 0:
    count += 1
if nh == 0:
    count += 1

count = 5-count

num = 0


if count <= 2 :
    print(0)
elif count == 3:
    num = 1
    if nm != 0:
        num = num * nm
    if na != 0:
        num = num * na
    if nr != 0:
        num = num * nr
    if nc != 0:
        num = num * nc
    if nh != 0:
        num = num * nh
    print(num)
elif count == 4:
    num = 4
    if nm != 0:
        num = num * nm
    if na != 0:
        num = num * na
    if nr != 0:
        num = num * nr
    if nc != 0:
        num = num * nc
    if nh != 0:
        num = num * nh
    print(num)
elif count == 5:
    num = 10
    if nm != 0:
        num = num * nm
    if na != 0:
        num = num * na
    if nr != 0:
        num = num * nr
    if nc != 0:
        num = num * nc
    if nh != 0:
        num = num * nh
    print(num)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = [input() for i in range(N)]
M,A,R,C,H = 0,0,0,0,0
Set = []

for i in range(N):
    if L[i][0] == 'M':
        M += 1
        Set.append('M')
    if L[i][0] == 'A':
        A += 1
        Set.append('A')
    if L[i][0] == 'R':
        R += 1
        Set.append('R')
    if L[i][0] == 'C':
        C += 1
        Set.append('C')
    if L[i][0] == 'H':
        H += 1
        Set.append('H')
        
Set = set(Set)
List = []
if 'M' in Set:
    List.append(M)
if 'A' in Set:
    List.append(A)
if 'R' in Set:
    List.append(R)
if 'C' in Set:
    List.append(C)
if 'H' in Set:
    List.append(H)

if len(Set) == 5:
   
    print(List[0]*List[1]*List[2] + List[0]*List[1]*List[3] + List[0]*List[1]*List[4]
          +List[0]*List[2]*List[3] + List[0]*List[3] + List[4] + List[0]*List[2]*List[4]
          + List[1]*List[2]*List[3] + List[1]*List[2]*List[4] + List[2]*List[3]*List[4]
          + List[1]*List[3]*List[4])
elif len(Set) == 4:
    
    print(List[0] * List[1] * List[2] + List[1] * List[2] * List[3]
          + List[0] * List[2] * List[3] + List[0] * List[1] * List[3])
elif len(Set) == 3:
    
    print (List[0] * List[1] * List[2])
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from math import factorial

def main():
    N = int(input())
    S = tuple(input() for _ in [0] * N)

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

    lst = [i for i in name.values() if i]
    n = len(lst)
    if n < 3:
        print(0)
        return

    x = factorial(n) // (factorial(3) * factorial(n - 3))
    for l in lst:
        if l > 1:
            x = (x * l) - (n - 3)
    print(x)

main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())

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


print(list_pop)

answer = 0
for i in range(3):
    for j in range(4)[i+1:]:
        for k in range(5)[j+1:]:
            answer += list_pop[i] * list_pop[j] * list_pop[k]
    
    
print(int(answer))

Submission status: Wrong Answer

Solution code:
import numpy as np
num=int(input())
#valid=["M","A","R","C","H"]
arr=np.zeros(5)
#print(arr)

for i in range(num):
    chara=list(input())[0]
    if chara == "M":
        arr[0]+=1
    if chara == "A":
        arr[1]+=1
    if chara == "R":
        arr[2]+=1
    if chara == "C":
        arr[3]+=1
    if chara == "H":
        arr[4]+=1

ans=0
for i in range(3):
    for k in range(3-i):
        for j in range(3-k-i):
            ans+=arr[i]*arr[1+i+k]*arr[2+i+k+j]
            print(arr[i]*arr[1+i+k]*arr[2+i+k+j])
print(int(ans))

Submission status: Wrong Answer

Solution code:
N=int(input())
M=[]
A=[]
R=[]
C=[]
H=[]
for i in range(N):
  s=input()
  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)
  elif s[0]=='H':
    H.append(s)
cnt=[len(M),len(A),len(R),len(C),len(H)]
res=sum(cnt)
res=int(res*(res-1)*(res-2)/6)

def dif(n):
  if cnt[n]==0 or cnt[n]==1:
    return 0
  else:
    a=0
    for i in range(5):
      if i!=n:
        a+=cnt[i]
  if cnt[n]==2:
    return a
  else:
    b=cnt[n]*(cnt[n]-1)*(cnt[n]-2)/6
    return int(a+b)
for i in range(5):
  res-=dif(i)
print(res)

Submission status: Wrong Answer

Solution code:
N=int(input())
i=0
L=[0,0,0,0,0]
while i < N:
    name=input()
    if name[0] == 'M':
        L[0] += 1
    elif name[0] == 'A':
        L[1] += 1
    elif name[0] == 'R':
        L[2] += 1
    elif name[0] == 'C':
        L[3] += 1
    elif name[0] == 'H':
        L[4] += 1
    i += 1

l=L[0]+L[1]+L[2]+L[3]+L[4]
if l < 3:
    print('0')
else:
    q = 0
    Q=[]
    j = 0
    while j < 5:
        if L[j] != 0:
            q += 1
            Q.append(L[j])
        j += 1
    if q < 3:
        p = 0
    elif q == 3:
        p = Q[0]*Q[1]*Q[2]
    elif q == 4:
        p = Q[0]*Q[1]*Q[2] + Q[0]*Q[2]*Q[3] + Q[0]*Q[1]*Q[3] + Q[1]*Q[2]*Q[3]
    else:
        p = Q[0]*Q[1]*Q[2]*Q[3] + Q[0]*Q[1]*Q[2]*Q[4] + Q[0]*Q[1]*Q[3]*Q[4] + Q[0]*Q[2]*Q[3]*Q[4] + Q[4]*Q[1]*Q[2]*Q[3]
    print(int(p))

Submission status: Wrong Answer

Solution code:
N=int(input())
i=0
L=[0,0,0,0,0]
while i < N:
    name=input()
    if name[0] == 'M':
        L[0] += 1
    elif name[0] == 'A':
        L[1] += 1
    elif name[0] == 'R':
        L[2] += 1
    elif name[0] == 'C':
        L[3] += 1
    elif name[0] == 'H':
        L[4] += 1
    i += 1

l=L[0]+L[1]+L[2]+L[3]+L[4]
if l < 3:
    print('0')
else:
    q = 0
    Q=[]
    j = 0
    while j < 5:
        if L[j] != 0:
            q += 1
            Q.append(L[j])
        j += 1
    if q < 3:
        p = 0
    elif q == 3:
        p = Q[0]*Q[1]*Q[2]
    elif q == 4:
        p = Q[0]*Q[1]*Q[2] + Q[0]*Q[2]*Q[3] + Q[0]*Q[1]*Q[3] + Q[1]*Q[2]*Q[3]
    else:
        p = Q[0]*Q[1]*Q[2]*Q[3] + Q[0]*Q[1]*Q[2]*Q[4] + Q[0]*Q[1]*Q[3]*Q[4] + Q[0]*Q[2]*Q[3]*Q[4] + Q[4]*Q[1]*Q[2]*Q[3]
    print(p)

Submission status: Wrong Answer

Solution code:

N = int(input())

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

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

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

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


    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from math import *
from itertools import combinations

n = int(input())
s = [input() for _ in range(n)]
s = list(map(lambda x: x[0], s))
s = list(filter(lambda x: x in 'MARCH', s))
t = {}
for x in range(len(s)):
  if s[x] in t: t[s[x]] += 1
  else: t[s[x]] = 1
t = list(t.values())
a = 0
for c in combinations(t, 3):
  m = 1
  for e in c:
    m *= factorial(e)
  a += m
print(a)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = {"M":0,"A":0,"R":0,"C":0,"H":0}
for i in range(N):
    s = input()
    try:
        S[s[0]] += 1
    except:
        pass

print(S["M"] * S["A"] * (S["R"]+S["C"]+S["H"]) + S["M"] * S["R"] * (S["C"] + S["H"]) + S["M"] * S["C"] * S["H"] + S["A"] * S["R"] * (S["C"] + S["H"]) + S["R"] * S["C"] * S["H"])

Submission status: Wrong Answer

Solution code:
n=int(input())
M=set();A=set();R=set();C=set();H=set()
for i in range(n):
    a=input()
    if a.startswith("M"):
        M.add(a)
    elif a.startswith("A"):
        A.add(a)
    elif a.startswith("R"):
        R.add(a)
    elif a.startswith("C"):
        C.add(a)
    elif a.startswith("H"):
        H.add(a)
m=len(M);a=len(A);r=len(R);c=len(C);h=len(H)
print(m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+r*c*h)

Submission status: Wrong Answer

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

for n in range(len(num)):
    if num[n] == 0:
        num[n] = 1
out = num[0] * num[1] *num[2] * num[3] * num[4]
print(out)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

words = [w for w in s if w[0] in "MARCH"]

cnt = 0
for i in combinations(words, 3):
    if i[0][0] != i[1][0] and i[1][0] != i[2][0] and  i[0][0] != i[2][0]:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

cnt=[]
ans=0
for i in range(N):
    if S[i][0]=='M':
        cnt.append('M')
    elif S[i][0]=='A':
        cnt.append('A')
    elif S[i][0]=='R':
        cnt.append('R')
    elif S[i][0]=='C':
        cnt.append('C')
    elif S[i][0]=='H':
        cnt.append('H')
        
import math
import itertools
c_list = list(itertools.combinations(cnt, 3))

for v in itertools.combinations(cnt, 3):
    if len(set(v))==3:
        ans+=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

N = int(input())
answer_list = set(['M', 'A', 'R', 'C', 'H'])
name_count = []

for i in range(N):
    name = input()

    if name[0] in answer_list:
        name_count.append(name[0])

result = list([1 for x in combinations(
    name_count, 3) if len(set(x)) == len(x)])
print(sum(result))

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
s = []
for i in range(n):
    name = input()
    if name[0] in ["M", "A", "R", "C", "H"]:
        s.append(name)
ptn = list(itertools.combinations(s, 3))
cnt = 0
for j in ptn:
    if j[0][0] != j[1][0] and j[1][0] != j[2][0] and j[2][0] != j[0][0]:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

N = int(input())
s_li = []
for _ in range(N):
    s = input()
    if s[0] in "MARCH":
        s_li.append(s)
s_set = set(s_li)
# print(len(list(combinations(s_set, 3))))
ans = 0
for c in combinations(s_set, 3):
    initial = []
    for name in c:
        if name[0] in initial:
            break
        initial.append(name[0])
    else:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

# check
MARCH = ["M", "A", "R", "C", "H"]
cnt = 0
for c in combinations(S, 3):
    tops = [s for s in c if s in MARCH]
    if len(tops) == 3 and len(tops) == len(set(tops)):
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

march = ("M","A","R","C","H")
d = []
for _ in range(n):
  pre = input()[0]
  if pre in march: d.append(pre)

if len(d) < 3:
  print(0)
  exit()

ans = 0
for i in combinations(d,3):
  if len(set(i)) == 3:
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
N = int(input())
name = []

for i in range(N):
    a = input()
    if a[0] == 'M' or a[0] == 'A' or a[0] == 'R' or a[0] == 'C' or a[0] == 'H':
        name += [a[0]]
count = 0

if len(name) < 3:
    print(0)
else:
    for i in combinations(name, 3):
        if i[0] != i[1] and i[1] != i[2] and i[2] != i[0]:
            count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
S = [input() for i in range(N)]
candi = []
for s in S:
    if s[0] == 'M' or s[0] == 'A' or s[0] == 'R' or s[0] == 'C' or s[0] == 'H':
        candi.append(s)
combi = list(itertools.combinations(candi,3))
counter  = 0
for i in combi:
    if i[0][0] != i[1][0] and  i[1][0] != i[2][0] and  i[0][0] != i[2][0]:
        counter += 1
print(counter)