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:
from functools import reduce
import math
import collections
import itertools
def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input())
    d = collections.defaultdict(int)
    for _ in range(N):
        S = input()
        d[S[0]] += 1
    seq = ('M','A','R','C','H')
    ans = 0
    for i in list(itertools.combinations(seq,3)):
        ans += d[i[0]] * d[i[1]] * d[i[2]]
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
name = [input() for i in range(N)]
dic = {"M":0,"A":0,"R":0,"C":0,"H":0}
for i in name :
    if i[0] in dic.keys():
        dic[i[0]] += 1
    else : pass
ans = 0

head_name = ["M","A","R","C","H"]
for i in head_name:
    for j in head_name:
        for k in head_name:
            if i != j and j!= k and i != k :
                ans += dic[i]*dic[j]*dic[k]

print("{}".format(ans//(3*2*1)))

Submission status: Accepted

Solution code:
n=int(input())
m,a,r,c,h=0,0,0,0,0
for i in range(n):
  name=input()
  init=name[0]
  if init =="M":
    m+=1
  elif init =="A":
    a+=1
  elif init =="R":
    r+=1
  elif init =="C":
    c+=1
  elif init =="H":
    h+=1
print(m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h)

Submission status: Accepted

Solution code:
from itertools import combinations

N = int(input())
cnt_dict = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
for _ in range(N):
    tmp = input()
    if tmp[0] in cnt_dict:
        cnt_dict[tmp[0]] += 1

res = 0
for value in combinations(cnt_dict.values(), 3):
    res += (value[0]*value[1]*value[2])

print(res)

Submission status: Accepted

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

S = [0] * N

S_dic = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
for i in range(N):
    S[i] = str(input())
    if S[i][0] in S_dic.keys():
        S_dic[S[i][0]] += 1

zero_count = 0
for value in S_dic.values():
    if value == 0:
        zero_count += 1
if zero_count >= 3:
    print(0)
    sys.exit()

total = 0
for item in list(combinations(S_dic.keys(), 3)):
    total += (S_dic[item[0]] * S_dic[item[1]] * S_dic[item[2]])
print(total)

Submission status: Accepted

Solution code:
m = 0
a = 0
r = 0
c = 0
h = 0

N = int(input())

for _ 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

if m == 0 and a == 0 and r == 0 and c == 0 and h == 0:
    print(0)
    exit()

ans = 0
l = [m, a, r, c, h]
for i in range(len(l)):
    for j in range(i+1, len(l)):
        for k in range(j+1, len(l)):
            ans += (l[i] * l[j] * l[k])
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# ABC089
import sys
input = sys.stdin.readline

from itertools import combinations

n = int(input())
lst = [input().rstrip() for _ in range(n)]
cond = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for i in lst:
    if i[0] in "MARCH":
        cond[i[0]] += 1
ans = 0
for x, y, z in combinations("MARCH", 3):
    ans += cond[x] * cond[y] * cond[z]
print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import Counter as ct
import itertools
fastinput = sys.stdin.readline
N=int(input())
name=[fastinput() for i in range(N)]
MARCH=[sum([n.startswith(k) for n in name]) for k in ("MARCH")]
ans=0
for a,b,c in itertools.combinations([1,2,3,4,0],3):
    ans += MARCH[a]*MARCH[b]*MARCH[c]
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from collections import defaultdict


def solve(N: int, S: "List[str]"):
    ndic = defaultdict(int)

    for s in S:
        ndic[s[0]] += 1

    M = [m for m in "MARCH" if ndic[m] > 0]

    res = 0
    for i in range(len(M)-2):
        for j in range(i+1,len(M)-1):
            for k in range(j+1,len(M)):
                res += ndic[M[i]] * ndic[M[j]] * ndic[M[k]] 
    print(res)




# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = [ next(tokens) for _ in range(N) ]  # type: "List[str]"
    solve(N, S)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict
from itertools import combinations

N = int(input())
Ns = defaultdict(int)
for _ in range(N):
    n = input()
    if n[0] in 'MARCH':
        Ns[n[0]] += 1

if len(Ns.keys()) < 3:
    print(0)
    quit()

ans = 0
for c in combinations(Ns.keys(), 3):
    ans += Ns[c[0]] * Ns[c[1]] * Ns[c[2]]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
li = [0] * 5
for i in range(n):
    name = input()
    if name[0] == 'M':
        li[0] += 1
    if name[0] == 'A':
        li[1] += 1
    if name[0] == 'R':
        li[2] += 1
    if name[0] == 'C':
        li[3] += 1
    if name[0] == 'H':
        li[4] += 1
ans = 0
for i in range(3):
    for j in range(5-i-1):
        if 5-i-j-2 >= 1:
            for k in range(5-i-j-2):
                ans += li[i]*li[i+j+1]*li[i+j+k+2]
print(ans)

Submission status: Accepted

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

I = ["M", "A", "R", "C", "H"]
L = [0] * 5

for i in S:
  for j in range(5):
    if i[0] == I[j]:
      L[j] += 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: Accepted

Solution code:
import itertools
n = int(input())
m = []
a = []
r = []
c = []
h = []
for i in range(n):
    t = input()
    if t[0] == 'M':
        m.append(t)
    elif t[0] == 'A':
        a.append(t)
    elif t[0] == 'R':
        r.append(t)
    elif t[0] == 'C':
        c.append(t)
    elif t[0] == 'H':
        h.append(t)
seq = (len(m), len(a), len(r), len(c), len(h))
t3 = list(itertools.combinations(seq, 3))
out = 0
for j in t3:
    out += j[0]*j[1]*j[2]
print(out)

Submission status: Accepted

Solution code:
import itertools
combi = itertools.combinations([0,1,2,3,4], 3)
n = int(input())
num = [0,0,0,0,0]
count = 0

for _ in range(n):
    tmp = input()
    if tmp[0] =="M":
        num[0] +=1
    elif tmp[0] == "A":
        num[1] += 1
    elif tmp[0] == "R":
        num[2] += 1
    elif tmp[0] == "C":
        num[3] += 1
    elif tmp[0] == "H":
        num[4] += 1
    else:
        continue

for i in combi:
    count += num[list(i)[0]] * num[list(i)[1]] * num[list(i)[2]]
print(count)

Submission status: Accepted

Solution code:
import itertools

def marchcount(a):
	if a == "M":
		march_list[0] += 1
	elif a == "A":
		march_list[1] += 1
	elif a == "R":
		march_list[2] += 1
	elif a == "C":
		march_list[3] += 1
	elif a == "H":
		march_list[4] += 1
	return


n = int(input())
march_list = [0 for i in range(5)] 
for i in range(n):
	marchcount(input()[0])

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

Submission status: Accepted

Solution code:
from collections import Counter
from itertools import combinations

N = int(input())
S = [input()[0] for _ in range(N)]
counts = Counter([c for c in S if c in "MARCH"])
ans = 0
if counts:
    for c in combinations("MARCH", 3):
        ans += counts[c[0]] * counts[c[1]] * counts[c[2]]
print(ans)

Submission status: Accepted

Solution code:
import itertools as ite

n=int(input())
count=[0]*5
for i in range(n):
    tmp=input()
    if tmp[0]=="M":
        count[0]+=1
    elif tmp[0]=="A":
        count[1]+=1
    elif tmp[0]=="R":
        count[2]+=1
    elif tmp[0]=="C":
        count[3]+=1
    elif tmp[0]=="H":
        count[4]+=1

ans=0
for i in list(ite.combinations(range(5),3)):
    pattern=1
    for j in i:
        pattern*=count[j]
    ans+=pattern
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

s = "MARCH"
counter_arr = [0] * 5

for i in range(N):
    tmp = input()
    for j in range(len(s)):
        if tmp[0] == s[j]:
            counter_arr[j] += 1
            break

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

Submission status: Accepted

Solution code:
N = int(input())

m_arr = []
a_arr = []
r_arr = []
c_arr = []
h_arr = []

for i in range(N):
    tmp = input()
    if tmp[0] == 'M':
        m_arr.append(tmp)
    elif tmp[0] == 'A':
        a_arr.append(tmp)
    elif tmp[0] == 'R':
        r_arr.append(tmp)
    elif tmp[0] == 'C':
        c_arr.append(tmp)
    elif tmp[0] == 'H':
        h_arr.append(tmp)
ans = 0

ans += len(m_arr) * len(a_arr) * len(r_arr)
ans += len(m_arr) * len(a_arr) * len(c_arr)
ans += len(m_arr) * len(a_arr) * len(h_arr)
ans += len(m_arr) * len(r_arr) * len(c_arr)
ans += len(m_arr) * len(r_arr) * len(h_arr)
ans += len(m_arr) * len(c_arr) * len(h_arr)
ans += len(a_arr) * len(r_arr) * len(c_arr)
ans += len(a_arr) * len(r_arr) * len(h_arr)
ans += len(a_arr) * len(c_arr) * len(h_arr)
ans += len(r_arr) * len(c_arr) * len(h_arr)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
m = 0
a = 0
r = 0
c = 0
h = 0

for i in range(N):
    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

ans = m * a * (r+c+h) + m * r * (c+h) + m * c * h + a * r * (c + h) + a * c * h + r * c * h
print(ans)

Submission status: Accepted

Solution code:
marchlist = ['M', 'A', 'R', 'C', 'H']
N = int(input())
namelist = [[], [], [], [], []]
for i in range(0, N):
	s = input()
	for j in range(0, 5):
		if s[0] == marchlist[j]:
			namelist[j].append(s)
sum = 0
for i in range(0, 3):
	for j in range(i+1, 4):
		for k in range(j+1, 5):
			sum += len(namelist[i])*len(namelist[j])*len(namelist[k])
print(sum)

Submission status: Accepted

Solution code:
N = int(input())
m = 0
a = 0
r = 0
c = 0
h = 0

for i in range(N):
    S = list(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 = m * a * (r + c + h) + m * r * (c + h) + m * c * h + a * r * (c + h) + a * c * h + r * c * h

print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
from collections import Counter

n = int(input())
S = Counter()
for i in range(n):
  S[input()[0]] +=  1 # Counter == dictionary
  
print(sum([S[a]*S[b]*S[c] for a, b, c in combinations("MARCH", 3)]))

Submission status: Accepted

Solution code:
N = int(input())
lst = []
for _ in range(N):
    lst += str(input())[:1]

# M = lst.count('M')
# A = lst.count('A')
# R = lst.count('R')
# C = lst.count('C')
# H = lst.count('H')

lst2 = []
for i in 'MARCH':
    lst2 += [lst.count(i)]
# print (lst2)

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

print (ans)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  ml=[]
  al=[]
  rl=[]
  cl=[]
  hl=[]

  n=I()
  for _ in range(n):
    s=S()
    if s[0]=='M':
      ml.append(s)
    elif s[0]=='A':
      al.append(s)
    elif s[0]=='R':
      rl.append(s)
    elif s[0]=='C':
      cl.append(s)
    elif s[0]=='H':
      hl.append(s)

  l=[len(ml),len(al),len(rl),len(cl),len(hl)]
  sm=0

  for i in range(2):
    for j in range(2):
      for k in range(2):
        for m in range(2):
          for n in range(2):
            lx=[i,j,k,m,n]
            if lx.count(1)==3:
              _s=1
              for x in range(len(lx)):
                if lx[x]==1:
                  _s*=l[x]
              sm+=_s

  return sm

print(main())

Submission status: Accepted

Solution code:
from itertools import combinations

N = int(input())
d = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
for _ in range(N):
    s = input()[0]
    if s in 'MARCH':
        d[s] += 1
ans = 0
for a, b, c in combinations(d.values(), 3):
    ans += a * b * c
print(ans)

Submission status: Accepted

Solution code:
num = int(input())
m=0
a=0
r=0
c=0
h=0
for _ in range(num):
  w = input()
  if w[0] == "M":
    m = m+1  
  elif w[0] == "A":
    a = a+1    
  elif w[0] == "R":
    r = r+1
  elif w[0] == "C":
    c = c+1
  elif w[0] == "H":
    h = h+1
  else:
    None
k = m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h
print(k)

Submission status: Accepted

Solution code:
N=int(input())
from collections import defaultdict
data=defaultdict(int)
for i in range(N):
    s=input()
    data[s[0]]+=1
S="MARCH"
ans=0
for x in range(3):
    for y in range(x+1,4):
        for z in range(y+1,5):
            ans+=data[S[x]]*data[S[y]]*data[S[z]]
print(ans)

Submission status: Accepted

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

ans_list = [0 for i in range(5)]
carList = ['M', 'A', 'R', 'C', 'H']
for s in S:
    for i, c in enumerate(carList):
        if s[0] == c:
            ans_list[i] += 1

ans_list = [a for a in ans_list if a != 0]
ans = 1
for i, v in enumerate(ans_list):
    ans *= v

if len(ans_list) < 3:
    print(0)
elif len(ans_list) == 3:
    print(ans_list[0]*ans_list[1]*ans_list[2])
elif len(ans_list) == 4:
    tmp = 0
    for i, v in enumerate(ans_list):
        tmp += ans // v
    print(tmp)
else:
    tmp = 0
    for i in range(5):
        for j in range(5):
            if i != j:
                tmp += ans // (ans_list[i]*ans_list[j])
    print(tmp//2)

Submission status: Accepted

Solution code:
from math import factorial
import itertools
N = int(input())
ML = 0
AL = 0
RL = 0
CL = 0
HL = 0
for i in range(N):
  x = input()[0]
  if x == 'M':
    ML += 1
  elif x == 'A':
    AL += 1
  elif x == 'R':
    RL += 1
  elif x == 'C':
    CL += 1
  elif x == 'H':
    HL += 1

num = 0

for x in itertools.combinations([('M',ML),('A',AL),('R',RL),('C',CL),('H',HL)],3):
  X = x[0][1]
  Y = x[1][1]
  Z = x[2][1]
  num += X*Y*Z
print(num)

Submission status: Accepted

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

N = int(input())
L = [list(input().strip()) for _ in range(N)]

m = {}

for v in L:
    if m.get(v[0]) == None:
        m[v[0]] = 0
    m[v[0]] += 1
    
l = [v for v in m.items() if v[0] in list("MARCH")]
    
ans = 0
for v in itertools.combinations(l, 3):
    ans += v[0][1] * v[1][1] * v[2][1]
    
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
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
a=['M','A','R','C','H']
s=combinations(a,3)
cnt=0
for x in s:
     cnt+=d[x[0]]*d[x[1]]*d[x[2]]
print(cnt)

Submission status: Accepted

Solution code:
from itertools import combinations
 
n = int(input())
 
count = {x:0 for x in "MARCH"}
 
for _ in range(n):
  s = input()[0]
  if s in count:
    count[s] += 1
 
sum_count = 0
for a, b, c in combinations("MARCH", 3):
  sum_count += count[a] * count[b] * count[c]
 
print(sum_count)

Submission status: Accepted

Solution code:
import itertools
N = int(input())
# N=10^5
count={}
for i in range(N):
    c = input()[0]
    count[c] = count.get(c, 0)+1
s = 0
for a,b,c in itertools.combinations("MARCH", 3):
    s += count.get(a,0)*count.get(b,0)*count.get(c,0)
print(s)

Submission status: Accepted

Solution code:
N=int(input())
S=list(input()[0] for _ in range(N))
m=S.count('M')
a=S.count('A')
r=S.count('R')
c=S.count('C')
h=S.count('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
      +a*c*h
      +r*c*h)

Submission status: Accepted

Solution code:
#https://atcoder.jp/contests/abc089/tasks/abc089_c
import itertools
N = int(input())
S = [input() for _ in range(N)]
M,A,R,C,H = 0,0,0,0,0
ans = 0
for s in S:
    if s[0] == "M":
        M +=1
    if s[0] == "A":
        A +=1
    if s[0] == "R":
        R +=1
    if s[0] == "C":
        C +=1
    if s[0] == "H":
        H +=1

for i,j,k in itertools.combinations([M,A,R,C,H],3):
    ans += i*j*k
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
c=[0]*5
for i in range(N):
    S=input()
    a=S[0]
    if a=="M":
        c[0]+=1
    if a=="A":
        c[1]+=1
    if a=="R":
        c[2]+=1
    if a=="C":
        c[3]+=1
    if a=="H":
        c[4]+=1
ans=0

for i in range(5):
    for j in range(5):
        for k in range(5):
            if i<j<k:
                ans+=c[i]*c[j]*c[k]
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations

N = int(input())
S = [input() for _ in range(N)]
MARCH = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for s in S:
    for m in MARCH:
        if s[0] == m:
            MARCH[m] += 1
ans = 0
for i, j, k in combinations(MARCH, 3):
    ans += MARCH[i] * MARCH[j] * MARCH[k]
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, S: "List[str]"):
    count = [0] * 5
    for s in S:
        if s[0] in 'MARCH':
            idx = 'MARCH'.find(s[0])
            count[idx] += 1
    ret = 0
    for i1 in range(5):
        for i2 in range(i1 + 1, 5):
            for i3 in range(i2 + 1, 5):
                ret += count[i1] * count[i2] * count[i3]
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = [ next(tokens) for _ in range(N) ]  # type: "List[str]"
    solve(N, S)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

from collections import defaultdict
from math import factorial
import itertools



def main():
    num = int(input())
    data = defaultdict(int)
    for i in range(num):
        a = input()[0]
        if a in ['M', 'A', 'R', 'C', 'H']:
            data[a] += 1

    ans = 0
    if len(data) >= 3:
        for now_data in list(itertools.combinations(data.values(),3)):
            ans += now_data[0] * now_data[1] * now_data[2]
    print(ans)




if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import combinations
from collections import Counter

N = int(input())
cnt = Counter([input()[0] for _ in range(N)])
ans = sum(cnt[i] * cnt[j] * cnt[k] for i, j, k in combinations('MARCH', 3))
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations

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

cnt = [sum(v[0] == c for v in s) for c in 'MARCH']
ans = sum(cnt[i] * cnt[j] * cnt[k] for i, j, k in combinations(range(5), 3))
print(ans)

Submission status: Accepted

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

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

for s in S:
    if s[0] in initial_dict:
        initial_dict[s[0]] += 1

keys = list(initial_dict.keys())
ans = 0
for i in range(5):
    for j in range(i+1, 5):
        for k in range(j+1, 5):
            ans += initial_dict[keys[i]] * initial_dict[keys[j]] * initial_dict[keys[k]]

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

l = [input() for i in range(n)]

m = []
a = []
r = []
c = []
h = []

for i in l:
    if i[0] == 'M':
        m.append(i)
    if i[0] == 'A':
        a.append(i)
    if i[0] == 'R':
        r.append(i)
    if i[0] == 'C':
        c.append(i)
    if i[0] == 'H':
        h.append(i)
        
m = len(m)
a = len(a)
r = len(r)
c = len(c)
h = len(h)

cnt = 0

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

print(cnt)

Submission status: Accepted

Solution code:
N=int(input())
S=[input() for i in range(N)]
c=[0,0,0,0,0]
for i in S:
    if i[0]=='M':
        c[0]+=1
    elif i[0]=='A':
        c[1]+=1
    elif i[0]=='R':
        c[2]+=1
    elif i[0]=='C':
        c[3]+=1
    elif i[0]=='H':
        c[4]+=1
ans=0
ans+=c[0]*(c[1]*(c[2]+c[3]+c[4])+c[2]*(c[3]+c[4])+c[3]*c[4])
ans+=c[1]*(c[2]*(c[3]+c[4])+c[3]*c[4])
ans+=c[2]*c[3]*c[4]
print(ans)

Submission status: Accepted

Solution code:
import itertools
n=int(input())
dic={'M':0,'A':0,'R':0,'C':0,'H':0}
l=dic.keys()
for _ in range(n):
	s=input()
	if s[0] in l:dic[s[0]]+=1
l=[x for x in dic.values() if x>0]
if len(l)<3:print(0)
else:
	ans=0
	for t in itertools.combinations(range(len(l)),3):
		k=1
		for i in t:
			k*=l[i]
		ans+=k
	print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
from collections import Counter
N = int(input())
s = [input()[0] for i in range(N)]
cnt = {k:v for k,v in Counter(s).items()}
ans = 0
for x,y,z in [c for c in combinations('MARCH',3)]:
    try:
        ans += cnt[x]*cnt[y]*cnt[z]
    except:
        pass
print(ans)

Submission status: Accepted

Solution code:
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


class UnionFind:

    def __init__(self, n):
        self.parent = [i for i in range(n)]

    def root(self, i):
        if self.parent[i] == i:
            return i
        self.parent[i] = self.root(self.parent[i])
        return self.parent[i]

    def unite(self, i, j):
        rooti = self.root(i)
        rootj = self.root(j)
        if rooti == rootj:
            return
        if rooti < rootj:
            self.parent[rootj] = rooti
        else:
            self.parent[rooti] = rootj

    def same(self, i, j):
        return self.root(i) == self.root(j)


###############################################################################


def main():
    n = intin()
    slist = [input() for _ in range(n)]

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

    for s in slist:
        if s[0] in count:
            count[s[0]] += 1

    patterns = [
        ['M', 'A', 'R'],
        ['M', 'A', 'C'],
        ['M', 'A', 'H'],
        ['M', 'R', 'C'],
        ['M', 'R', 'H'],
        ['M', 'C', 'H'],
        ['A', 'R', 'C'],
        ['A', 'R', 'H'],
        ['A', 'C', 'H'],
        ['R', 'C', 'H'],
    ]

    ans = 0

    for p in patterns:
        ans += count[p[0]] * count[p[1]] * count[p[2]]

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())
S=[]
M=[]
A=[]
R=[]
C=[]
H=[]
for s in range(N):
    name = input()
    S.append(name)
for s in S:
    first=s[0]
    if first == "M":
        M.append(s)
    if first == "A":
        A.append(s)
    if first == "R":
        R.append(s)
    if first == "C":
        C.append(s)
    if first == "H":
        H.append(s)
m=len(M)
a=len(A)
r=len(R)
c=len(C)
h=len(H)
ans= m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
import sys
n = int(sys.stdin.readline().rstrip())
s = [sys.stdin.readline().rstrip()[0] for _  in range(n)]
sum = 0
for i,j,k in combinations([s.count(l) for l in "MARCH"],3):
    sum +=i * j * k
print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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
    if S[i][0] == 'A' : MARCH[1] += 1
    if S[i][0] == 'R' : MARCH[2] += 1
    if S[i][0] == 'C' : MARCH[3] += 1
    if S[i][0] == 'H' : MARCH[4] += 1
    
ans = 0
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            ans += MARCH[i] * MARCH[j] * MARCH[k]
            
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

march = list("MARCH")

c = defaultdict(int)
N = int(input())
for i in range(N):
    S = input()
    for a in march:
        if S[0] == a:
            c[a] += 1
            break
        else:
            continue

#print(c)

s = 0
a = [0]*3
for a[0] in march:
    for a[1] in march:
        for a[2] in march:
            if sum(map(lambda x:x in a,march)) != 3:
                continue
            s += c[a[0]] * c[a[1]] * c[a[2]]

print(s // 6)

Submission status: Accepted

Solution code:
from itertools import combinations

n = int(input())
m, a, r, c, h = 0, 0, 0, 0, 0
for _ in range(n):
    char = input()[0]
    if char == "M":
        m += 1
    if char == "A":
        a += 1
    if char == "R":
        r += 1
    if char == "C":
        c += 1
    if char == "H":
        h += 1

l = [m, a, r, c, h]
ans = 0
for i in combinations(l, 3):
    tmp = 1
    for j in i:
        tmp *= j
    ans += tmp
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = [input() for _ in range(N)]
L = [0] * 5
ans,tmp = 0,1

for char in S:
    if char[0] == "M":
        L[0] += 1
    if char[0] == "A":
        L[1] += 1
    if char[0] == "R":
        L[2] += 1
    if char[0] == "C":
        L[3] += 1
    if char[0] == "H":
        L[4] += 1

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

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
S = [input() for i in range(N)]
S = [s[0] for s in S if s[0] in 'MARCH']
counter = Counter(S)
if len(counter) < 3:
  print(0)
else:
  cnt = 0
  mar = 'MARCH'
  for a in range(0,3):
    if mar[a] not in counter:
      continue
    for b in range(a+1, min(a+1+3, 5-1)):
      if mar[b] not in counter:
        continue
      for c in range(b+1, min(b+1+3, 5)):
        if mar[c] not in counter:
          continue
        # print(mar[a], mar[b], mar[c])
        cnt += counter[mar[a]] * counter[mar[b]] * counter[mar[c]]
  print(cnt)