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: Runtime Error

Solution code:
n = int(input())
list_N = [input() for _ in range(n)]
list_N = list(set(list_N))
cnt = [0 for _ in range(5)]

for i in range(len(list_N)):
    l = list(list_N[i])
    if l[0] in "M":
        cnt[0] += 1
    elif l[0] in "A":
        cnt[1] += 1
    elif l[0] in "R":
        cnt[2] += 1
    elif l[0] in "C":
        cnt[3] += 1
    elif l[0] in "H":
        cnt[4] += 1

ans = 0
l  = []
if cnt.count(0) == 2:
    for num in cnt:
        if num != 0:
            l.append(num)
    ans += l[0]*l[1]*l[2]
if cnt.count(0) == 1:
    for num in cnt:
        if num != 0:
            l.append(num)
    ans += l[0] * l[1] * l[2]
    ans += l[0] * l[1] * l[3]
    ans += l[0] * l[2] * l[3]
    ans += l[2] * l[1] * l[3]
if cnt.count(0) == 0:
    ans += l[0] * l[1] * l[2]
    ans += l[0] * l[1] * l[3]
    ans += l[0] * l[1] * l[4]
    ans += l[0] * l[2] * l[3]
    ans += l[0] * l[2] * l[4]
    ans += l[0] * l[3] * l[4]
    ans += l[1] * l[2] * l[3]
    ans += l[1] * l[2] * l[4]
    ans += l[1] * l[3] * l[4]
    ans += l[2] * l[3] * l[4]

if cnt.count(0) > 2:
    print(0)
else:
    print(ans)

Submission status: Runtime Error

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import Counter
from scipy.special import comb

n = int(readline())
s = [input()[0] for i in range(n)]
memo = list(Counter(s).items())
check = ['M', 'A', 'R', 'C', 'H']
cnt = 0
ans = 0
for x, y in memo:
    if x in check:
        ans += y
        if y > 1:
            cnt += n - y
print(comb(ans, 3, exact=True) - cnt)

Submission status: Runtime Error

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

cnt =  [i for i in march_l if i != 0]
len_cnt = len(cnt)

if len_cnt > 3:
    for i in range(2**len_cnt):
        tmp = 1
        if str(bin(i)).count('1') == 3:
            for j in range(len_cnt):
                if ((i>>j) & 1):
                    tmp *= cnt[j]
            ans += tmp
elif len_cnt == 3:
    ans = 1
    for i in cnt:
        ans *= i
else:
    ans = 0

print(ans)

Submission status: Runtime Error

Solution code:
m=0
a=0
r=0
c=0
h=0
n=int(input())
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
  else:pass

li=[m,a,r,c,h]
ans=0
for ai in range(n):
  for bi in range(n):
    for ci in range(n):
      if ci>bi>ai:
        ans+=li[ai]*li[bi]*li[ci]
print(ans)

Submission status: Runtime Error

Solution code:
import itertools
N = int(input())
SK = {"M":0,"A":1,"R":2,"C":3,"H":4}
SD = [0]*5
del_list = []
A = ["M","A","R","C","H"]
for x in range(N):
    tmp = str(input())
    if tmp[0] in A:
        SD[SK[tmp[0]]] +=1
C = 0
for x in range(5)
    if SD[x] == 0 :
        del_list.append(x)
        C +=1
del_list.reverse()
for x in del_list:
    SD.pop(x)
    
if C >2:
    print(0)
else:
    Z = 5-C
    k = itertools.combinations(range(Z), 3)
    ans = 0
    for x in k:
        ans += SD[x[0]]*SD[x[1]]*SD[x[2]]
    print(ans)

Submission status: Runtime Error

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

march = ["M","A","R","C","H"]
march_num = [0,0,0,0,0]

for i in range(n):
    if s[i] in march:
        march_num[march.index(s[i])] += 1
ans = 0
for i in range(len(s)-2):
    for j in range(i+1,len(s)-1):
        for k in range(j+1,len(s)):
            ans += (march_num[i]*march_num[j]*march_num[k])
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
s = ["" for _ in range(n)]
for i in range(n):
    s[i] = str(input())
march = ["M","A","R","C","H"]
march_num = [0,0,0,0,0]
for i in range(n):
    if s[i][0] in march:
        march_num[march.index(s[i][0])] += 1
ans = 0
for i in range(len(s)-2):
    for j in range(i+1,len(s)-1):
        for k in range(j+1,len(s)):
            ans += (march_num[i]*march_num[j]*march_num[k])
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
s = []
for i in range(n):
    s.append(str(input()))
march = ["M","A","R","C","H"]
march_num = [0,0,0,0,0]
for i in range(n):
    if s[i][0] in march:
        march_num[march.index(s[i][0])] += 1
ans = 0
for i in range(len(s)-2):
    for j in range(i+1,len(s)-1):
        for k in range(j+1,len(s)):
            ans += (march_num[i]*march_num[j]*march_num[k])
print(ans)

Submission status: Runtime Error

Solution code:
from itertools import combinations
import collections

N = int(input()) 

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

AA = set(A)
C = collections.Counter(A)
print(sum(C[a]*C[b]*C[c] for a, b, c combinations(AA, 3)))

Submission status: Runtime Error

Solution code:
n=int(input())
d={'M':0,'A':0,'R':0,'C':0,'H':0}
for _ in range(n): d[input()[0]]+=1
import itertools as it
print(sum(d[s]*d[t]*d[r] for s,t,r in it.combinations('MARCH',3)))

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from itertools import combinations
n=int(input())
s=[input() for i in range(n)]
cnt=defaultdict(lambda :0)
cnt['M']=0
for i in range(n):
    if s[i][0] in 'MARCH':
        cnt[s[i][0]]+=1

if len(cnt)<=2:print(0)
else:
    num=len(cnt)
    ans=0
    for x,y,z in combinations(list(cnt.values()), 3):
        ans+=x*y*z
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
s=[input() for i in range(n)]
cnt=[0]*5
for t in s:
  if t[0]=='M':
    cnt[0]+=1
  elif t[0]=='A':
    cnt[1]+=1
  elif t[0]=='R':
    cnt[2]+=1
  elif t[0]=='C':
    cnt[3]+=1
  elif t[0]=='H':
    cnt[4]+=1
ans=0
for v in itertools.combinations([0,1,2,3,4],3):
  ans+=cnt[v[0]]*cnt[v[1]]*cnt[v[2]]
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
s=['M','A','R','C','H']
for i in range(n):
    i=input()
    s.append(i[0])

import collections
c = collections.Counter(s)
d=['M','A','R','C','H']
ans=0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            ans+=(c[d[i]]-1)*(c[d[j]]-1)*(c[d[k]]-1)
print(ans)

Submission status: Runtime Error

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

import collections
c = collections.Counter(s)
d=['M','A','R','C','H']
ans=0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            ans+=c[d[i]]*c[d[j]]*c[d[k]]
print(ans)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from scipy.special import comb
#ID
b = defaultdict(lambda: len(b))
n = int(input())
hed = ["M","A","R","C","H"]
for i in hed:
    b[i] 
li = [0]*5
for _ in range(n):
    a = input()
    if a[0] in hed:
        li[b[a[0]]] += 1

c = [i for i in li if i != 0]
print(int(comb(len(c),3))*2 -int(comb(len(c)-1,3)))

Submission status: Runtime Error

Solution code:
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

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

march = ['M','A','R','C','H']
d = dict(zip(march, [0]*5))

nn = 0

for s in ss:
    if s[0] in march:
        d[s[0]] += 1
        nn += 1

ans = cmb(nn, 3)
for i in d.values():
    if i >= 2:
        if i > 3:
            ans -= cmb(i, 3)
        ans -= cmb(i,2)*(nn-i)

print(int(ans))

Submission status: Runtime Error

Solution code:
from scipy.special import comb
def cmb(n,r):
    return comb(n, r)

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

march = ['M','A','R','C','H']
d = dict(zip(march, [0]*5))

nn = 0

for s in ss:
    if s[0] in march:
        d[s[0]] += 1
        nn += 1

ans = comb(nn, 3)
for i in d.values():
    if i >= 2:
        if i > 3:
            ans -= comb(i, 3)
        ans -= comb(i,2)*(nn-i)

print(int(ans))

Submission status: Runtime Error

Solution code:
n = int(input())
march = ['M','A','R','C','H']
counter = [0]*5
for i in range(n):
	s = input()
	if s[0] in march:
		counter[march.index(s[0])] += 1

ans = 0

while 0 in counter:
	counter.pop(counter.index(0))

if len(counter) <= 2:
	ans = 0
elif len(counter) == 3:
	ans = counter[0]*counter[1]*counter[2]
elif len(counter) == 4:
	ans = counter[0]*counter[1]*counter[2] + counter[0]*counter[1]*counter[3] + counter[0]*counter[2]*counter[3] + counter[1]*counter[2]*counter[3]
elif len(counter) == 5:
	ans = counter[0]*counter[1]*counter[2] + counter[0]*counter[1]*counter[3] + counter[0]*counter[1]*counter[4] + counter[0]*counter[2]*counter[3] + counter[0]*counter[2]*counter[4] + counter[0]*counter[3]*counter[4] + counter[1]*counter[2]*counter[3] + counter[1]*counter[2]*counter[4] + counter[1]*counter[3]*counter[4] + counter[3]*counter[4]*counter[5]

print(ans)

Submission status: Runtime Error

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

S_first = [S[i][0] for i in range(N)]
march = ['M','A','R','C','H']
march_number = [0]*5

for i in range(N):
    march_number[i] = S_first.count(march[i])

import itertools

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

Submission status: Runtime Error

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

S_first = [S[i][0] for i in range(N)]
march = ['M','A','R','C','H']
march_number = [0]*5

for i in range(N):
    march_number[i] = S_first.count(march[i])

import itertools
ptr = list(itertools.combinations(march_number,3))

ans = 0
seki = 1

for i in range(len(ptr)):
    for j in range(3):
        seki *= ptr[i][j]
    ans += seki
    seki = 1

print(ans)

Submission status: Runtime Error

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

S_first = [S[i][0] for i in range(N)]
march = ['M','A','R','C','H']
march_number = [0]*5

for i in range(N):
    march_number[i] = S.count(march[i])

import itertools
ptr = list(itertools.combinations(march_number,3))

ans = 0
seki = 1

for i in range(len(ptr)):
    for j in range(3):
        seki *= ptr[i][j]
    ans += seki
    seki = 1

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
count = [0]*5
d = {'M': 0, 'A': 1, 'R': 2, 'C':3, 'H': 4}

for i in range(n):
  s = input()
  if s[0] in 'MARCH':
    count[d[s[0]]] += 1

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

Submission status: Runtime Error

Solution code:
n = int(input())
cnt = [0,0,0,0,0]
comp = 'MARCH'
ans = 0

for i in range(N):
    word = input()
    for j in range(len(comp)):
        if word[0] == comp[j]:
            cnt[j] += 1

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

Submission status: Runtime Error

Solution code:
import math

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

d={'M':0,'A':0,'R':0,'C':0,'H':0}
n=int(input())
for i in range(n):
  word=input()
  if word[0] in d: d[word[0]]+=1

m = sum(d.values())
max = combinations_count(m,3)

if m<3:
  print(0)
  exit()

sub = 0
for i in d.values():
  if i>=3: sub += combinations_count(i, 3)
  if i>=2: sub += combinations_count(i, 2) * (m-2)

print(max - sub)

Submission status: Runtime Error

Solution code:
import math

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

d={'M':0,'A':0,'R':0,'C':0,'H':0}
n=int(input())
for i in range(n):
  word=input()
  if word[0] in d:d[word[0]]+=1

m = sum(d.values())
max = combinations_count(m,3) if m!=0 else 0
sub = 0
for i in d.values():
  if i>2: sub += combinations_count(i, 3)
  elif i>1: sub += combinations_count(i, 2) * (m-2)

print(max - sub)

Submission status: Runtime Error

Solution code:
N = int(input())
s = [0] * N
d = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for i in range(N):
    s[i] = input()
    if s[i][0] == "M":
        d['M'] += 1
    elif s[i][0] == "A":
        d['A'] += 1
    elif s[i][0] == "R":
        d['R'] += 1
    elif s[i][0] == "C":
        d['C'] += 1
    elif s[i][0] == "H":
        d['H'] += 1

total = 1
count = 0
del_keys = []
for k, v in d.items():
    if v == 0:
        del_keys.append(k)
    else:
        total *= v
        count += 1

for key in del_keys:
    del d[key]

if count < 3:
    print(0)
    exit()
elif count == 3:
    print(total)
    exit()
elif count == 4:
    ans = 0
    for k, v in d.items():
        ans += total / v
    print(int(ans))
    exit()
elif count == 5:
    ans = 0
    d_lst = list(d)
    for i in range(4):
        for j in range(i+1, 5):
            ans += total / (d_lst[i] * d_lst[j])
    print(int(ans))

Submission status: Runtime Error

Solution code:
N = int(input())
s = [0] * N
d = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for i in range(N):
    s[i] = input()
    if s[i][0] == "M":
        d['M'] += 1
    elif s[i][0] == "A":
        d['A'] += 1
    elif s[i][0] == "R":
        d['R'] += 1
    elif s[i][0] == "C":
        d['C'] += 1
    elif s[i][0] == "H":
        d['H'] += 1

total = 1
count = 0
del_keys = []
for k, v in d.items():
    if v == 0:
        del_keys.append(k)
    else:
        total *= v
        count += 1

print(d)
for key in del_keys:
    del d[key]

if count < 3:
    print(0)
    exit()
elif count == 3:
    print(total)
    exit()
elif count == 4:
    ans = 0
    for k, v in d.items():
        ans += total / v
    print(int(ans))
    exit()
elif count == 5:
    ans = 0
    d_lst = list(d)
    for i in range(4):
        for j in range(i+1, 5):
            ans += total / (d_lst[i] * d_lst[j])
    print(int(ans))

Submission status: Runtime Error

Solution code:
N = int(input())
s = [0] * N
d = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for i in range(N):
    s[i] = input()
    if s[i][0] == "M":
        d['M'] += 1
    elif s[i][0] == "A":
        d['A'] += 1
    elif s[i][0] == "R":
        d['R'] += 1
    elif s[i][0] == "C":
        d['C'] += 1
    elif s[i][0] == "H":
        d['H'] += 1

total = 1
count = 0
del_keys = []
for k, v in d.items():
    if v == 0:
        del_keys.append(k)
    else:
        total *= v
        count += 1

for key in del_keys:
    del d[key]

if count < 3:
    print(0)
    exit()
elif count == 3:
    print(total)
    exit()
elif count == 4:
    ans = 0
    for k, v in d.items():
        ans += total / v
    print(ans)
    exit()
elif count == 5:
    ans = 0
    d_lst = list(d)
    for i in range(4):
        for j in range(i+1, 5):
            ans += total / (d_lst[i] * d_lst[j])
    print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
march = "MARCH"
n = int(input())
initial = Counter([input()[0] for _ in range(n)])
ans = []
for i, num in initial.items():
    if i in march:
        ans.append(num)

x = len(ans)
if x < 3:
    print(0)
elif x >= 3:
    y = 0
    for i in range(1, x-1):
        for j in range(i+1, x):
            for k in range(j+1, x+1):
                y += ans[i] * ans[j] * ans[k]
    print(y)

Submission status: Runtime Error

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: Runtime Error

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

Submission status: Runtime Error

Solution code:
from collections import Counter
import itertools
n = int(input()) 
l = [input()[0] for _ in range(n)]
l = [i for i in l if i in {'M','A','R','C','H'}]

if len(l) < 3:
    print(0)
else:
    c = Counter(l)
    cl = list(itertools.combinations(c,3))
    ans = 0
    for i in cl:
        ans += c[i[0]] * c[i[1]] * c[i[2]]

print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
M=['M','A','R','C','H']
S = {'M':0,'A':0,'R':0,'C':0,'H':0}
for _ in range(n):
  a = input()
  if a[0] in S:
  	S[a[0]] +=1
ANS=0
for i in range(n):
  for j in range(i+1,n):
    for k in range(j+1,n):
      ANS += (S[M[i]] * S[M[j]]* S[M[k]])
print(ANS)

Submission status: Runtime Error

Solution code:
N = int(input())
inis = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for i in range(N):
    s = list(input())
    if s[0] == "M" or s[0] == "A" or s[0] == "R" or s[0] == "C" or s[0] == "H":
        inis[s[0]] += 1

ans = 0
march = ["M","A","R","C","H"]
for i in range(N):
    for j in range(i, N):
        for k in range(j, N):
            if march[i] != march[j] and march[i] != march[k] and march[j] != march[k]:
                ans += inis[march[i]] * inis[march[j]] * inis[march[k]]

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())

w = "MARCH"
count = {key: 0 for key in w}

for i in range(N):
    S = input()
    c = S[0]
    if c in w:
        count[c] += 1

ans = 0

for i in range(N):
    for j in range(i + 1, N):
        for k in range(j + 1, N):
            ans += count[w[i]] * count[w[j]] * count[w[k]]

print(ans)

Submission status: Runtime Error

Solution code:
import itertools

from math import factorial

def combi(x: int, y: int):
    if x == 0:
        return 1
    else:
        return int(factorial(x) / factorial(y) / factorial(x - y))

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

numbers = [0, 0, 0, 0, 0]
bit = [0, 0, 0, 0, 0]

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

tmp = 1
for i in numbers:
    tmp *= combi(i, 1)

print(int(combi(sum(numbers), sum(bit)) / tmp))

Submission status: Runtime Error

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

f = [a for a in s if s.startswith('M')]
g = [b for b in s if s.startswith('A')]
h = [c for c in s if s.startswith('R')]
i = [d for d in s if s.startswith('C')]
j = [e for e in s if s.startswith('H')]

k = len(f)*len(g)*len(h)
l = len(f)*len(g)*len(i)
m = len(f)*len(g)*len(j)
n = len(f)*len(h)*len(i)
o = len(f)*len(h)*len(j)
p = len(f)*len(i)*len(j)
q = len(g)*len(h)*len(i)
r = len(g)*len(h)*len(j)
s = len(g)*len(i)*len(j)
t = len(h)*len(i)*len(j)

sum = k+l+m+n+o+p+q+r+s+t
print(sum)

Submission status: Runtime Error

Solution code:
s = [input() for _ in range(n)]
prefix = ['M', 'A', 'R', 'C', 'H']
cnt = [0] * 5
ans = 0
for i in range(n):
    for j in range(5):
        if s[i][0] == prefix[j]:
            cnt[j] += 1
for i in range(2 ** 5):
    flag = [False] * 5
    for j in range(5):
        if (i >> j) & 1:
            flag[j] = True
    if flag.count(True) == 3:
        tmp = 1
        for k in range(5):
            if flag[k]:
                tmp *= cnt[k]
        ans += tmp
print(ans)

Submission status: Runtime Error

Solution code:
import sys
from operator import mul
from functools import reduce

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

MARCH = 'MARCH'
def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

N = INT()
S = [input().rstrip() for _ in range(N)]

S = [s for s in S if s[0] in MARCH]

A = [0]*N
for s in S:
	A[MARCH.index(s[0])] += 1

#print(A)

if sum(A) <= 3:
	print(0)
	sys.exit()

ans = cmb(sum(A), 3)
#print(ans)

for a in A:
	if a<=1:continue
	if a>=3:
		ans -= cmb(a, 3)
	ans -= cmb(a, 2) * (sum(A)-a)

print(ans)

Submission status: Runtime Error

Solution code:
N = input()

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

for i in range(N):
    s = input()
    if s[0] in 'MARCH':
        d[s[0]]+=1

v = list(d.values())
ans = 0

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

print(ans)

Submission status: Runtime Error

Solution code:
from intertools 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: Runtime Error

Solution code:
import math

N = int(input())
name = [input() for i in range(N)]
nameList = [0 for i in range(5)]

for n in name:
  if n[0] == 'M':
    nameList[0] += 1
  elif n[0] == 'A':
    nameList[1] += 1
  elif n[0] == 'R':
    nameList[2] += 1
  elif n[0] == 'C':
    nameList[3] += 1
  elif n[0] == 'H':
    nameList[4] += 1

ans = [i for i in nameList if i != 0]
n = len(ans)
r = 3
a = 0
if len(ans) > 0:
	a = math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

for i in ans:
  a *= i
print(a)

Submission status: Runtime Error

Solution code:
from sys import stdin
from itertools import combinations
from math import factorial

n = int(stdin.readline().rstrip())
li = [stdin.readline().rstrip() for _ in range(n)]

lin = [0]*n

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

from itertools import combinations
lis = list(combinations(lin, 3))


point = 0
for i in lis:
    point += i[0]*i[1]*i[2]

print(point)

Submission status: Runtime Error

Solution code:
import sys

readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def main():
    N = int(readline())
    S = list(map(lambda x: x.decode("UTF-8"), readlines()))
    S = list(map(lambda x: x.rstrip('\n'), S))
    march = list("MARCH")

    cnt = [0] * 5
    for i in range(N):
        for j in range(5):
            if S[i][0] == march[j]:
                cnt[j] += 1

    ans = 0

    if N < 3:
        print(0)
    else:
        for i in range(N-2):
            for j in range(i+1, N-1):
                for k in range(j+1, N):
                    ans += cnt[i] * cnt[j] * cnt[k]

        print(ans)


main()

Submission status: Runtime Error

Solution code:
import sys

readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def main():
    N = int(readline())
    S = list(map(lambda x: x.decode("UTF-8"), readlines()))
    S = list(map(lambda x: x.rstrip('\n'), S))
    march = list("MARCH")

    cnt = [0] * 5
    for i in range(N):
        for j in range(5):
            if S[i][0] == march[j]:
                cnt[j] += 1

    ans = 0
    for i in range(N-2):
        for j in range(i+1, N-1):
            for k in range(j+1, N):
                ans += cnt[i] * cnt[j] * cnt[k]

    print(ans)


main()

Submission status: Runtime Error

Solution code:
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO

Submission status: Runtime Error

Solution code:
m=0
a=0 
r=0
c=0
h=0
for j in range(n):
  if s[j][0]=="M":
    m+=1
  elif s[j][0]=="A":
    a+=1
  elif s[j][0]=="R":
    r+=1
  elif s[j][0]=="C":
    c+=1
  elif s[j][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*c*h+a*r*h+r*c*h

print(ans)

Submission status: Runtime Error

Solution code:
import itertools

N = int(input())

# 頭文字Mグループ、頭文字Aグループ、のように分割する
# どの3つのグループから1人選ぶかを考える

n_initial_MARCH = [0]*5
match_initial = ["M", "A", "R", "C", "H"]
for _ in range(N):
    s = input()
    for idx in range(5):
        if s[0] == match_initial[idx]:
            n_initial_MARCH[idx] += 1

taken_indices = list(itertools.combinations([idx for idx in range(N) if n_initial_MARCH[idx] > 0], 3))

ans = 0

for groups in taken_indices:
    ans += n_initial_MARCH[groups[0]] * n_initial_MARCH[groups[1]] * n_initial_MARCH[groups[2]]

print(ans)

Submission status: Runtime Error

Solution code:
import itertools

N = int(input())

# 頭文字Mグループ、頭文字Aグループ、のように分割する
# どの3つのグループから1人選ぶかを考える

n_initial_MARCH = [0]*5
match_initial = ["M", "A", "R", "C", "H"]
for _ in range(N):
    s = input()
    for idx in range(N):
        if s[0] == match_initial[idx]:
            n_initial_MARCH[idx] += 1

taken_indices = list(itertools.combinations([idx for idx in range(N) if n_initial_MARCH[idx] > 0], 3))

ans = 0

for groups in taken_indices:
    ans += n_initial_MARCH[groups[0]] * n_initial_MARCH[groups[1]] * n_initial_MARCH[groups[2]]

print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
l=[0]*5
m='MARCH'
for i in range(n):
  s=input()
  f=s[0]
  for i in range(5):
    if f==m[i]:
      l[i]+=1
      break
x=0
for i in range(3):
  for j in range(i+1,4):
    for k in range(j+1,5):
      x+=a[i]*a[j]*a[k]
print(x)

Submission status: Runtime Error

Solution code:
n=int(input())
name={}
name["M"]=0
name["A"]=0
name["R"]=0
name["C"]=0
name["H"]=0
for _ in range(n):
    s=list(input())
    if s[0] not in name:
        name[s[0]]=1
    else:
        name[s[0]]+=1
cnt=[name["M"],name["A"],name["R"],name["C"],name["H"]]
ans=0
for i in range(n-2):
    for j in range(n-i-2):
        j+=i+1
        for k in range(n-j-1):
            k+=j+1
            ans+=cnt[i]*cnt[j]*cnt[k]
print(ans)

Submission status: Runtime Error

Solution code:
import sys
from functools import reduce
import copy
import math
from pprint import pprint


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    persons = inputs
    N = 5
    kinds = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0, }
    for n in persons:
        if n[0] in kinds:
            kinds[n[0]] += 1
    kinds_list = list(kinds.keys())

    if len(persons) < 3:
        return 0

    pattern = 0
    for i in range(N-2):
        for j in range(i+1, N-1):
            for k in range(j+1, N):
                p1 = kinds_list[i]
                p2 = kinds_list[j]
                p3 = kinds_list[k]
                pattern += kinds[p1] * kinds[p2] * kinds[p3]
    return pattern


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    N = int(input())
    ret = solve(inputs(5))
    print(ret)

Submission status: Runtime Error

Solution code:
# ABC089C - March
from itertools import combinations as comb


def main():
    N, *S = open(0).read().split()
    cnt = [sum(s.startswith(i) for S) for i in "MARCH"]
    ans = sum(x * y * z for x, y, z in comb(cnt, 3))
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
from operator import mul
from functools import reduce

N = int(input())
M = []
A = []
R = []
C = []
H = []
def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

for _ in range(N):
  tmp = input()[0]
  if tmp == "M":
    M.append(tmp)
  elif tmp == "A":
    A.append(tmp)
  elif tmp == "R":
    R.append(tmp)
  elif tmp == "C":
    C.append(tmp)
  elif tmp == "H":
    H.append(tmp)
X = [len(M),len(A),len(R),len(C),len(H)]
Y = sum(X)
if Y == 0:
  print(0)
  exit()
Sum = cmb(X[0]+X[1]+X[2]+X[3]+X[4],3)

count_A = 0
for x in X:
  if x >= 3:
    count += 1

count_B = 0
for i in X:
  if i >= 2:
    count_B += cmb(i,2) * (Y - i)

print(Sum - count_A - count_B)

Submission status: Runtime Error

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

ans = 0
cntM = 0
cntA = 0
cntR = 0
cntC = 0
cntH = 0
for i in range(N):
    cntM += (1 if S[i][0] == 'M' else 0)
    cntA += (1 if S[i][0] == 'A' else 0)
    cntR += (1 if S[i][0] == 'R' else 0)
    cntC += (1 if S[i][0] == 'C' else 0)
    cntH += (1 if S[i][0] == 'H' else 0)
cntlst = [cntM, cntA, cntR, cntC, cntH]

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        for k in range(j + 1, N):
            ans += cntlst[i] * cntlst[j] * cntlst[k]
print(ans)

Submission status: Runtime Error

Solution code:
import math


def combi(a, b):
    ans = math.factorial(a) / (math.factorial(a - b) * math.factorial(b))
    return ans

N=int(input())
S=[0]*5

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

c=0
N=0
for i in range(5):
    N+=S[i]
    if S[i]!=0:
        c+=1

if c<=2:
    print(0)

else:

    for i in range(5):
        if S[i]>=3:
            NG=combi(S[i],3)+combi(S[i],2)*(N-S[i])
        elif S[i]==2:
            NG=combi(S[i],2)*(N-S[i])
    print(int(combi(N,3)-NG))

Submission status: Runtime Error

Solution code:
n=int(input())
s=list(input() for i in range(n))
m=[]
a=[]
r=[]
c=[]
h=[]
ans=1
for i in range(n):
    if s[i][0] == "M" and not s[i] in m:
        m.append(s[i])
    elif s[i][0] == "A" and not s[i] in a:
        a.append(s[i])
    elif s[i][0] == "R" and not s[i] in r:
        r.append(s[i])
    elif s[i][0] == "C" and not s[i] in c:
        c.append(s[i])
    elif s[i][0] == "H" and not s[i] in h:
        h.append(s[i])
num=len(m)+len(a)+len(r)+len(c)+len(h)
if num == 0:
    print(0)
else:
    lis = list(len(m),len(a),len(r),len(c),len(h))
    for i in range(5):
        if lis[i]>0:
            ans = ans*lis[i] 
    print(ans)

Submission status: Runtime Error

Solution code:
m=[]
a=[]
r=[]
c=[]
h=[]
ans=1
for i in range(n):
    if s[i][0] == "M" and not s[i] in m:
        m.append(s[i])
    elif s[i][0] == "A" and not s[i] in a:
        a.append(s[i])
    elif s[i][0] == "R" and not s[i] in r:
        r.append(s[i])
    elif s[i][0] == "C" and not s[i] in c:
        c.append(s[i])
    elif s[i][0] == "H" and not s[i] in h:
        h.append(s[i])
num=len(m)+len(a)+len(r)+len(c)+len(h)
if num == 0:
    print(0)
else:
    lis = list(len(m),len(a),len(r),len(c),len(h))
    for i in range(5):
        ans = ans*lis[i] 
    print(ans)