Problem:


Score : 300 points

Problem Statement

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

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

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

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

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

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

Constraints

1 \leq N \leq 10^5

S_i consists of uppercase English letters.

1 \leq |S_i| \leq 10

S_i \neq S_j (i \neq j)

Input

Input is given from Standard Input in the following format:

N
S_1
:
S_N

Output

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

Sample Input 1

5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI

Sample Output 1

2

We can choose three people with the following names:

MASHIKE, RUMOI, HABORO

MASHIKE, RUMOI, HOROKANAI

Thus, we have two ways.

Sample Input 2

4
ZZ
ZZZ
Z
ZZZZZZZZZZ

Sample Output 2

0

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

Sample Input 3

5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO

Sample Output 3

7



Sample input:
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI


Sample output:
2

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import fractions
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

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

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

Submission status: Accepted

Solution code:
import collections
import itertools
n = int(input())
s = list(input()[0] for _ in range(n))
s = [i for i in s if i == "M" or i == "A" or i == "R" or i == "C" or i == "H"]

d = dict(collections.Counter(s))
c = list(itertools.combinations(d.values(), 3))

ans = 0
for i, j, k in c:
    ans += i * j * k

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
from itertools import combinations


def main():
    N = int(input())
    d = defaultdict(int)
    for _ in range(N):
        S = input()
        d[S[0]] += 1
    ans = 0
    for chars in combinations('MARCH', 3):
        ans += d[chars[0]] * d[chars[1]] * d[chars[2]]
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
d = {'M': 0,'A': 0, 'R': 0, 'C': 0, 'H': 0}
for _ in range(n):
    s = str(input())
    if s[0] in d:
        d[s[0]] += 1
L = list(d.values())
cnt = 0
for i in range(3):
    for j in range(i + 1, 5):
        for k in range(j + 1, 5):
            cnt += L[i] * L[j] * L[k]
print(cnt)

Submission status: Accepted

Solution code:
# coding: utf-8
# hello worldと表示する
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
m,a,r,c,h=0,0,0,0,0
for i in range(n):
    s=SI()
    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
lis=[]
lis.append(m)
lis.append(a)
lis.append(r)
lis.append(c)
lis.append(h)
u=[0,1,2,3,4]
ans=0
for i in combinations(u,3):
    pro=1
    for j in range(3):
        pro*=lis[i[j]]
    ans+=pro
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
from collections import defaultdict

n = int(input())
d = defaultdict(int)

for _ in range(n):
    tmp = input()
    if tmp[0] in ["M", "A", "R", "C", "H"]:
        d[tmp[0]] += 1

li = list(combinations(d.keys(), 3))

ans = 0
for a, b, c in li:
    ans += d[a] * d[b] * d[c]

print(ans)

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n = n//a
    count += 1
  if a**count == n:
    return count
  else:
    return count+1

#############
# Main Code #
#############

N = I()
d = DD(int)
for _ in range(N):
  s = S()
  d[s[0]] += 1
  
ini = ["M","A","R","C","H"]
ans = 0
for i in range(5):
  for j in range(i+1,5):
    for k in range(j+1,5):
      ans += d[ini[i]]*d[ini[j]]*d[ini[k]]
P(ans)

Submission status: Accepted

Solution code:
from collections import Counter
from itertools import combinations
 
n = int(input())
l = [input()[0] for _ in range(n)]
lc = Counter(l)
con = []
for c in 'MARCH':
    if c in lc:
        con.append(lc[c])
 
ans = 0
for a, b, c in combinations(con, 3):
    ans += a * b * c
 
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
import numpy as np
def main():
  N = int(input())
  ch = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
  for i in range(N):
    s = str(input())
    if s[0] in ch:
      ch[s[0]] += 1
  ch =  ch.values()
  ans = 0
  for i in itertools.combinations(ch, 3):
    ans += np.prod(i)
  print(ans)

if __name__ ==  "__main__":
  main()

Submission status: Accepted

Solution code:
from itertools import combinations

N = int(input())
MARCH = [0] * 5
for i in range(N):
    S = input()
    if S[0] == 'M':
        MARCH[0] += 1
    if S[0] == 'A':
        MARCH[1] += 1
    if S[0] == 'R':
        MARCH[2] += 1
    if S[0] == 'C':
        MARCH[3] += 1
    if S[0] == 'H':
        MARCH[4] += 1
ans = 0
for x in combinations(MARCH,3):
    ans += x[0]*x[1]*x[2]
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
n = int(input())
set_3m = set()
cnt = {}
for i in range(n):
    s = input()
    try:
        if s[0] in {'M', 'A', 'R', 'C', 'H'}:
            set_3m.add(s[0])
            cnt[s[0]] += 1
    except KeyError:
        cnt[s[0]] = 1
sum_cnt = 0
for c in combinations(set_3m, 3):
    sum_cnt += cnt[c[0]] * cnt[c[1]] * cnt[c[2]]
print(sum_cnt)

Submission status: Accepted

Solution code:
n=int(input())
s=[input()[0] for i in range(n)]
from collections import Counter

sc=Counter(s)
ans=0
from itertools import combinations
for a,b,c in combinations("MARCH",3):
    ans+=sc[a]*sc[b]*sc[c]
print(ans)

Submission status: Accepted

Solution code:
import itertools
n = int(input())
d = {x: 0 for x in ["M","A","R","C","H"]}
s = []
for _ in range(n):
    st = input()
    if st[0] in d.keys():
        d[st[0]] += 1

nonzero = sum([1 for x in d.values() if x > 0])
if nonzero == 5:
    cases = 10
elif nonzero == 4:
    cases = 4
elif nonzero == 3:
    cases = 1
else:
    cases = 0

if cases == 0:
    print(0)
elif cases == 1:
    ans = cases
    for x in d.values():
        if x == 0 or x == 1:
            pass
        else:
            ans *= x
    print(ans)
elif cases > 3:
    ans = 0
    for i in ["M","A","R","C","H"]:
        if d[i] == 0:
            del d[i]
    for v in itertools.combinations(d.values(),3):
        tmp = 1
        for x in v:
            tmp *= x
        ans += tmp
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())
sl = [input() for nesya in range(n)]
d = {"M":0,"A":0,"R":0,"C":0,"H":0}
for s in sl:
  if s[0] in d:
    d[s[0]] += 1
ans1 = d['M']*d['A']*(d['R']+d['C']+d['H'])
ans2 = (d['C']+d['H'])*d['R']*(d['M']+d['A'])
ans3 = (d['M']+d['A']+d['R'])*d['C']*d['H']
print(ans1+ans2+ans3)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
s_input = [input()[0] for i in range(n)]

s_c = [v for k,v in Counter(s_input).items() if k in 'MARCH']
n_c = len(s_c)
if n_c<3:
    print(0);exit()
ans = 0
for i in range(n_c):
    for j in range(i+1,n_c):
        for k in range(j+1,n_c):
            ans+=s_c[i]*s_c[j]*s_c[k]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
hito = {c:0 for c in "MARCH"}
for _ in range(N):
    S = input()
    if S[0] in "MARCH":
        hito[S[0]] += 1
from itertools import combinations
ans = 0
for comb in combinations("MARCH", 3):
    temp = 1
    for head in comb:
        temp *= hito[head]
    ans += temp
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
hito = {c:0 for c in "MARCH"}
N = int(input())
for _ in range(N):
    S = input()
    if S[0] in "MARCH":
        hito[S[0]] += 1

ans = 0
values = list(hito.values())
indexes = [0, 1, 2, 3, 4]
for comb in combinations(indexes, 3):
    # print(comb)
    res = 1
    for initial in comb:
        res *= values[initial]
    ans += res
print(ans)

Submission status: Accepted

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

Mx,Ax,Rx,Cx,Hx=0,0,0,0,0

for n in range(N):
  if   s[n][0] =="M":
    Mx += 1
  elif s[n][0] =="A":
    Ax += 1
  elif s[n][0] =="R":
    Rx += 1
  elif s[n][0] =="C":
    Cx += 1
  elif s[n][0] =="H":
    Hx += 1

MAR = Mx * Ax * Rx
MAC = Mx * Ax * Cx
MAH = Mx * Ax * Hx
MRC = Mx * Rx * Cx
MRH = Mx * Rx * Hx
MCH = Mx * Cx * Hx

ARC = Ax * Rx * Cx
ARH = Ax * Rx * Hx
ACH = Ax * Cx * Hx

RCH = Rx * Cx * Hx

print(MAR+MAC+MAH+MRC+MRH+MCH+ARC+ARH+ACH+RCH)

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())
base = ["M","A","R","C","H"]
base_1 = np.zeros(5)

for i in range(n):
	s = input()
	for j in range(5):
		if s[0] == base[j]:
			base_1[j] += 1
			break
            
ans = 0
for i in range(2,5):
  for j in range(1,i):
    for l in range(0,j):
      ans += base_1[i]*base_1[j]*base_1[l]
      


print(int(ans))

Submission status: Accepted

Solution code:
from collections import defaultdict
from itertools import combinations

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

ans = 0
for a, b, c in combinations(['M', 'A', 'R', 'C', 'H'], 3):
    ans += d[a] * d[b] * d[c]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
d = {'M':0,'A':0,'R':0,'C':0,'H':0}
for _ in range(n):
  s= input()
  if s[0] in d:
    d[s[0]] += 1
march = list('MARCH')
from itertools import combinations

ans = 0
for a,b,c in combinations(march,3):
  ans += d[a]*d[b]*d[c]
print(ans)

Submission status: Accepted

Solution code:
NAME = [0]*5

N = int(input())
S = []

for _ in range(N):
    s = input()
    if s[0]=="M":
        NAME[0] = NAME[0] + 1
    if s[0]=="A":
        NAME[1] = NAME[1] + 1
    if s[0]=="R":
        NAME[2] = NAME[2] + 1
    if s[0]=="C":
        NAME[3] = NAME[3] + 1
    if s[0]=="H":
        NAME[4] = NAME[4] + 1
ans = 0

for i in range(5-3+1):
    for j in range(i+1, 5-2+1):
        for k in range(j+1, 5):
            ans = ans + NAME[i]*NAME[j]*NAME[k]

print(ans)

Submission status: Accepted

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)
m = set(m)
a = set(a)
r = set(r)
c = set(c)
h = set(h)
li = [len(m), len(a), len(r), len(c), len(h)]
ans = 0
for i in range(5):
    for j in range(i+1, 5):
        for k in range(j+1, 5):
            ans += li[i]*li[j]*li[k]
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri May 15 13:57:43 2020

@author: shinba
"""
from itertools import combinations

n = int(input())

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

data = {}

for s in march:
    data[s] = 0

for i in range(n):
    name = input()
    if name[0] in march:
        data[name[0]] += 1

ans = 0

for i,j,k in combinations(data.values(),3):
    ans += i*j*k

print(ans)

Submission status: Accepted

Solution code:
import itertools
n = int(input())
s = [input() for _ in range(n)]

march = [0] * 5

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

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

Submission status: Accepted

Solution code:
import itertools
n = int(input())
c = [0] * 5
for i 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 t in itertools.combinations(range(5), 3):
  ans += c[t[0]] * c[t[1]] * c[t[2]]
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
from itertools import combinations

N = int(input())
initials = [input()[0] for _ in range(N)]
initials = [initial for initial in initials if initial in {'M', 'A', 'R', 'C', 'H'}]
counter = Counter(initials)
joined = ''.join(set(initials))

print(sum([counter[c1] * counter[c2] * counter[c3] for c1, c2, c3 in combinations(joined, r=3)]))

Submission status: Accepted

Solution code:
import numpy as np
from itertools import combinations
from functools import reduce
from collections import defaultdict

N = int(input())
d = defaultdict(int)
for i in range(N):
    c = input()
    if c[0] in ('M', 'A', 'R', 'C', 'H'):
        d[c[0]] += 1

l = len(d)
if l < 3:
    print(0)
else:
    ans = 0
    for l in list(combinations(d.values(), 3)):
        ans += reduce(np.multiply, l)
    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
n,*s=open(0).read().split()
d={'M':0,'A':0,'R':0,'C':0,'H':0}
for i in s:
    k=i[0]
    if k in d:
        d[k]+=1
p=0
for i,j,k in itertools.combinations(d.values(),3):
    p+=i*j*k
print(p)

Submission status: Accepted

Solution code:
from collections import Counter
from itertools import combinations

N = int(input())
Name = []
Group = []
March = ['M', 'A', 'R', 'C', 'H']

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

Group_C = Counter(Group)
ans = 0
for I in combinations(March, 3):
    ansi = 1
    for i in I:
        ansi *= Group_C[i]
    ans += ansi

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
MARCH = [[],[],[],[],[]]
ans = 0

for _ in range(N):
    Si = input()
    if Si[0] == "M":
        MARCH[0].append(Si)
    if Si[0] == "A":
        MARCH[1].append(Si)
    if Si[0] == "R":
        MARCH[2].append(Si)
    if Si[0] == "C":
        MARCH[3].append(Si)
    if Si[0] == "H":
        MARCH[4].append(Si)

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

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
N = int(input())
dict = defaultdict(int)
for i in range(N):
    s = input()
    if s[0] in ['M', 'A', 'R', 'C', 'H']:
        dict[s[0]] += 1
a = []
for v in dict.values():
    if v > 0:
        a.append(v)
ans = 0
for i in range(len(a)):
    for j in range(i + 1, len(a)):
        for k in range(j + 1, len(a)):
            ans += a[i] * a[j] * a[k]
print(ans)

Submission status: Accepted

Solution code:
import sys
import itertools

n = int(input())
l = {}
for i in sys.stdin.readlines():
    i = i.rstrip()
    if i[0] in ['M','A','R','C','H']:
        l.setdefault(i[0], []).append(i)

s = list(itertools.combinations(l.keys(), 3))
ans = 0
for v in s:
    tmp = 1
    for k in v:
        tmp *= len(l[k])
    ans += tmp
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
from collections import Counter

def resolve():
	n = int(input())
	seq = []
	for _ in range(n):
		v = input()[0]
		if v in ['M', 'A', 'R', 'C', 'H']:
			seq.append(v)
	c = Counter(seq)
	ans = 0
	for comb in combinations(c.values(), 3):
		tmp = 1
		for i in comb:
			tmp *= i
		ans += tmp
	print(ans)
resolve()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict
from itertools import combinations
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    d=defaultdict(int)
    for _ in range(N):
        S=input()
        if S[0]=='M' or S[0]=='M' or S[0]=='A' or S[0]=='R' or S[0]=='C' or S[0]=='H':
            d[S[0]]+=1
    ans=0
    for t in combinations(d.keys(),3):
        ans+=d[t[0]]*d[t[1]]*d[t[2]]
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
table={}
for i in range(n):
    tmp=list(input())
    if tmp[0]=="M" or tmp[0]=="A" or tmp[0]=="R" or tmp[0]=="C" or tmp[0]=="H":
        if tmp[0] in table:
            table[tmp[0]]+=1
        else:
            table[tmp[0]]=1
    else:
        continue
ans=0
for i in table:
    for j in table:
        for k in table:
            if i==j or j==k or k==i:
                continue
            ans+=table[i]*table[j]*table[k]
print(ans//6)

Submission status: Accepted

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

one =   ["M", "M", "M", "M", "M", "M", "A", "A", "A", "R"]
two =   ["A", "A", "A", "R", "R", "C", "R", "R", "C", "C"]
three = ["R", "C", "H", "C", "H", "H", "C", "H", "H", "H"]

ans = 0
for i in range(10):
  ans += cnt[one[i]] * cnt[two[i]] * cnt[three[i]]
  
print(ans)

Submission status: Accepted

Solution code:
def process():
    l = {}
    N = int(input().rstrip())
    for i in range(N):
        s =  input().rstrip()
        k = s[0]
        if not k in 'MARCH':
            continue

        if k in l:
            l[k] = l[k] + 1
        else:
            l[k] = 1

    if len(l) < 3:
        return 0

    num = 0
    march = ''.join(l.keys())
    for i1 in range(0, len(march)):
        k = march[i1]
        i1_num = l[k]
        for i2 in range(i1 + 1, len(march)):
            k = march[i2]
            i2_num = l[k]

            for i3 in range(i2 + 1, len(march)):
                k = march[i3]
                i3_num = l[k]
                num = num + i1_num * i2_num * i3_num

    return num

result = process()
print(result)

Submission status: Accepted

Solution code:
import itertools
def myAnswer(N:int,S:list) -> int:
   ans = 0
   dic = {"M":0,"A":0,"R":0,"C":0,"H":0}
   for s in S:
      if(s[0] in dic.keys()):
         dic[s[0]] += 1
   for c in itertools.combinations(dic.values(),3):
      ans += c[0]*c[1]*c[2]
   return ans

def modelAnswer():
   return
def main():
   N = int(input())
   S = [input() for _ in range(N)]
   print(myAnswer(N,S[:]))
if __name__ == '__main__':
   main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions

import copy

# import heapq
# from collections import deque
# import decimal

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

def main():
    n = ni()
    d = []
    for i in range(n):
        s = sys.stdin.readline()
        d.append(s[0])

    c = collections.Counter(d)

    initial = ["M", "A", "R", "C", "H"]
    pairs = itertools.combinations(initial, 3)
    ans = 0
    for x, y, z in pairs:
        ans += c[x] * c[y] * c[z]
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools
import collections

def main():
    n = int(input())
    S = [input()[0] for _ in range(n)]

    array = ['M','A','R','C','H']
    combs = itertools.combinations(array, 3)
    coll = collections.Counter(S)

    ans = 0
    for comb in combs:
        ans += coll[comb[0]]*coll[comb[1]]*coll[comb[2]]
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter
from itertools import combinations

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

c = Counter(s)
combi = combinations(c.values(), 3)

ans = 0
for a, b, c in combi:
    ans += a * b * c

print(ans)

Submission status: Accepted

Solution code:
import itertools
import collections

def main():
    n = int(input())
    S = [input()[0] for _ in range(n)]

    array = ['M','A','R','C','H']
    S_after = []
    for s in S:
        if s in array:
            S_after.append(s)
    if len(S_after) < 3:
        print(0)
        return
    S_after_set = set(S_after)
    combs = itertools.combinations(S_after_set, 3)
    coll = collections.Counter(S_after)

    ans = 0
    for comb in combs:
        if comb[0] != comb[1] != comb[2]:
            ans += coll[comb[0]]*coll[comb[1]]*coll[comb[2]]
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools 
n = int(input())
s = [input() for _ in range(n)]

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

for j in itertools.combinations(march,3):
    comb_multi = 1
    for k in range(3):
      comb_multi *= j[k]
    ans += comb_multi
print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
from itertools import combinations
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7



def main():
    N = int(readline())
    d = defaultdict(int)
    for _ in range(N):
        S = readline().decode('utf-8')
        if S.startswith('M'):
            d['M'] += 1
        elif S.startswith('A'):
            d['A'] += 1
        elif S.startswith('R'):
            d['R'] += 1
        elif S.startswith('C'):
            d['C'] += 1
        elif S.startswith('H'):
            d['H'] += 1
        else:
            continue
    if len(d)<3:
        print(0)
        sys.exit()
    ans = 0
    for cmb in combinations(d.keys(),3):
        tmp = 1
        for kye in cmb:
            tmp *= d[kye]
        ans += tmp
    print(ans)



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict
import itertools

n = int(input())
li = [input() for _ in range(n)]
check = ['M', 'A', 'R', 'C', 'H']
res = []

ans = 0
d = defaultdict(int)

for i in li:
    if i[0] in check:
        d[i[0]] += 1
        res.append(i[0])
res = list(set(res))

arr = itertools.combinations(res,3)
for s,t,u in arr:
    ans += d[s] * d[t] * d[u]

print(ans)

Submission status: Accepted

Solution code:
import itertools

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

C = [0, 0, 0, 0, 0]

for i in range(N):
    a = A[i]
    if a.startswith('M'):
        C[0] += 1
    elif a.startswith('A'):
        C[1] += 1
    elif a.startswith('R'):
        C[2] += 1
    elif a.startswith('C'):
        C[3] += 1
    elif a.startswith('H'):
        C[4] += 1

total = 0
for c in itertools.combinations(C, 3):
    total += c[0] * c[1] * c[2]

print(total)

Submission status: Accepted

Solution code:
import sys
import os
import math
import bisect
import collections
import itertools
import heapq

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    name = collections.Counter()
    for n in range(N):
        name[iss()[0]] += 1
    print(sum([name[a] * name[b] * name[c] for a, b, c in itertools.combinations(['M', 'A', 'R', 'C', 'H'], 3)]))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import os
import math
import bisect
import collections
import itertools
import heapq

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    name = {}
    for al in range(ord('A'), ord('Z') + 1):
        name[chr(al)] = 0
    for n in range(N):
        name[iss()[0]] += 1
    print(sum([name[a] * name[b] * name[c] for a, b, c in itertools.combinations(['M', 'A', 'R', 'C', 'H'], 3)]))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    from collections import Counter
    from itertools import combinations

    n, *s = map(lambda x: str(x)[0], open(0).read().split())
    c = Counter(s)

    m = [c.get(x) if c.get(x) != None else 0 for x in ["M", "A", "R", "C", "H"]]
    ans = sum(i * j * k for i, j, k in combinations(m, 3))
    print(ans)


if __name__ == '__main__':
    main()