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:
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
import itertools

n = int(readline())
s = [input()[0] for i in range(n)]
counter = Counter(s)
ans = 0
for i, j, k in itertools.combinations('MARCH', 3):
    ans += counter[i] * counter[j] * counter[k]
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations as c
n = int(input())
S = [input().replace("\n", "")[0] for _ in range(n)]
cnt = [S.count(i) for i in "MARCH"]
print(sum(i*j*k for i, j, k in c(cnt, 3)))

Submission status: Accepted

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)
ans = 0

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
        
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
def main():
    s = [i[0] for i in open(0).read().split()[1:]]
    c = [s.count(i) for i in "MARCH"]
    a = sum(x*y*z for x, y, z in combinations(c, 3))
    print(a)
main()

Submission status: Accepted

Solution code:
from itertools import combinations
def main():
    s = [i[0] for i in open(0).read().split()[1:]]
    c = (s.count("M"),s.count("A"),s.count("R"),s.count("C"),s.count("H"))
    a = sum(x*y*z for x, y, z in combinations(c, 3))
    print(a)
main()

Submission status: Accepted

Solution code:
def main():
    s = [i[0] for i in open(0).read().split()[1:]]
    c = (s.count("M"),s.count("A"),s.count("R"),s.count("C"),s.count("H"))
    a = 0
    for i in range(3):
        for j in range(3-i):
            for k in range(3-i-j):
                a += c[i]*c[i+j+1]*c[i+j+k+2]
    print(a)

main()

Submission status: Accepted

Solution code:
import sys
_,*s = sys.stdin.read().strip().split("\n")
s = [i[0] for i in s]
c = [s.count("M"),s.count("A"),s.count("R"),s.count("C"),s.count("H")]
a = 0
for i in range(3):
    for j in range(3-i):
        for k in range(3-i-j):
            a += c[i]*c[i+j+1]*c[i+j+k+2]
print(a)

Submission status: Accepted

Solution code:
from itertools import combinations
n = int(input())
dic = {i:0 for i in 'MARCH'}
for i in range(n):
    s = input()
    if s[0] in ('MARCH'):
        dic[s[0]] += 1
result = 0
for i, j, k in combinations('MARCH', 3):
    result += dic[i]*dic[j]*dic[k]
print(result)

Submission status: Accepted

Solution code:
from collections import Counter
N=int(input())
S=[0]*N
for i in range(N):
  S[i]=input()[0]
  
d=dict(Counter(S))
#print(d)
e=list()
for i in d:
  if i=="M" or i=="A" or i=="R" or i=="C" or i=="H":
    e.append(d[i])
#print(e)

n=len(e)
ans=0
for i in range(0,n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      #print(i,j,k,e[i]*e[j]*e[k])
      ans += e[i]*e[j]*e[k]
print(ans)

Submission status: Accepted

Solution code:
import itertools
n=int(input())
s=dict()
for i in ["M","A","R","C","H"]:
    s[i]=0
for i in range(n):
    _s=input()
    if _s[0] in ["M","A","R","C","H"]:
        s[_s[0]]+=1
s=list(s.items())
ans=0
for i in range(5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            ans+=(s[i][1]*s[j][1]*s[k][1])
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

n = int(input())
lst = [0,0,0,0,0]

for i in range(n):
    name = input()
    if name[0]=="M":
        lst[0]+=1
    elif name[0]=="A":
        lst[1]+=1
    elif name[0]=="R":
        lst[2]+=1
    elif name[0]=="C":
        lst[3]+=1
    elif name[0]=="H":
        lst[4]+=1
# print(lst)

P = [0,0,0,0,0,0,1,1,1,2]
Q = [1,1,1,2,2,3,2,2,3,3]
R = [2,3,4,3,4,4,3,4,4,4]

ans = 0
for i in range(10):
    ans += lst[P[i]]*lst[Q[i]]*lst[R[i]]
print(ans)

Submission status: Accepted

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(5):
  for bi in range(5):
    for ci in range(5):
      if ci>bi>ai:
        ans+=li[ai]*li[bi]*li[ci]
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
S=[]
for _ in range(N):
    S.append(input())
def cnt(c):
    temp=0
    for val in S:
        if val[0]==c:
            temp+=1
    return temp

lst=['M','A','R','C','H']
march=list(map(cnt, lst))

#print(march)

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

Submission status: Accepted

Solution code:
from sys import stdin
inp = stdin.readline

N = int(inp().rstrip())
S = [inp().rstrip() for _ in range(N)]

cnt = [0, 0, 0, 0, 0]

for s in S:
    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

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
cnt=0
from collections import Counter
cc=Counter()
for _ in range(n):
    s=input()
    if s[0]=='M' or s[0]=='A' or s[0]=='R' or s[0]=='C' or s[0]=='H':
        cc[s[0]]+=1
l=[]
for i in cc:
    l.append(cc[i])
#print(l)
for i in range(len(l)):
    for j in range(i+1,len(l)):
        for k in range(j+1,len(l)):
            cnt+=l[i]*l[j]*l[k]
print(cnt)
#print((cnt*(cnt-1)*(cnt-2))//6)

Submission status: Accepted

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

    n, *s = open(0).read().split()
    i = [x[0] for x in s]
    d = CNT(i)
    c = [d.get(i) if d.get(i) != None else 0 for i in 'MARCH']
    ans = sum(a * b * c for a, b, c in COM(c, 3))
    print(ans)

    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    from collections import Counter
    import itertools
    from math import factorial as f
    
    n, *s = open(0).read().split()
    i = [x[0] for x in s]
    d = Counter(i)
    c = [d.get(i) for i in 'MARCH' if d.get(i) != None]
    
    if len(c) < 3:
        ans = 0
    else:
        ans = 0
        for a,b,c in itertools.combinations(c,3):
          ans += a*b*c
    
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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: Accepted

Solution code:
import sys
input = sys.stdin.readline
from itertools import combinations
from collections import Counter
def main():
    N = int(input())
    s = Counter()
    for _ in range(N):
        s[input().rstrip("\r\n")[0]] += 1
    print(sum([s[a]*s[b]*s[c] for a,b,c in combinations("MARCH",3)]))
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    d = {"M":0,"A":0,"R":0,"C":0,"H":0}
    for _ in range(N):
        s = input().rstrip("\r\n")
        if s[0] in d.keys():
            d[s[0]] += 1
    dv = []
    for v in d.values():
        if v != 0:dv.append(v)
    ans = 0
    if len(dv) >= 3:
        for i in range(len(dv)-2):
            for j in range(i+1,len(dv)-1):
                for k in range(j+1,len(dv)):
                    ans += dv[i]*dv[j]*dv[k]
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
name = [str(input()) for _ in range(n)]
name_first = []
cnt = 0

for i in name:
    name_first.append(i[0])
name_dic = Counter(name_first)
# print(name_dic)

info = [name_dic["M"], name_dic["A"], name_dic["R"], name_dic["C"], name_dic["H"]]
# print(info)
for i in range(5):
    for j in range(5):
        for k in range(5):
            if i < j < k:
                cnt += info[i]*info[j]*info[k]

print(cnt)

Submission status: Accepted

Solution code:
from itertools import combinations
n=int(input())
s=[input()[0] for _ in range(n)]
a=[]
for i in ['M','A','R','C','H']:
  a+=[s.count(i)]
ans=0
for i in combinations(a,3):
  ans+=i[0]*i[1]*i[2]
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter # 重複個数のカウント: Counter(num_list)
import itertools

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

    str_count = Counter(str_list)

    ans = 0

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

    for l in list(itertools.combinations(seq,3)):
        ans += str_count[l[0]] * str_count[l[1]] * str_count[l[2]]

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# import bisect
from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():

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

    SS=Counter(S)
    for i in SS:
        if i in 'MARCH':
            cnt.append(SS[i])
    ans=0
    for a,b,c in combinations(cnt,3):
        ans+=a*b*c



    print(ans)


resolve()

Submission status: Accepted

Solution code:
# Author: cr4zjh0bp
# Created: Thu Mar 26 22:17:55 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from collections import defaultdict
from itertools import combinations

n = ni()
s = nsn(n)
d = defaultdict(int)
for i in range(n):
    d[s[i][0]] += 1

m = [0] * 5
for i, v in enumerate("MARCH"):
    m[i] = d[v]

ans = 0
for p in combinations(range(5), 3):
    i, j, k = p
    ans += m[i] * m[j] * m[k]

print(ans)

Submission status: Accepted

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(len(s)):
    if s[i] in march:
        march_num[march.index(s[i])] += 1
ans = 0
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            ans += (march_num[i]*march_num[j]*march_num[k])
print(ans)

Submission status: Accepted

Solution code:
import itertools
n = int(input())
dic = {"M":0, "A":0, "R":0, "C":0, "H":0, "Z":0}
for i in range(n):
    s = input()
    if s[0] not in dic:
        dic["Z"] += 1
    else:
        dic[s[0]] += 1
ans = 0
for i in itertools.combinations(["M", "A", "R", "C", "H"], 3):
    ans += dic[i[0]]*dic[i[1]]*dic[i[2]]
print(ans)

Submission status: Accepted

Solution code:
from itertools import (
    accumulate,  # 累積和のイテレータ
    groupby,  # 値をkey,同じ値の集まりをgroup
    permutations,  # 順列
    combinations,  # 組み合わせ
    product,  # 重複あり順列（直積）
)

n = int(input())
Sm, Sa, Sr, Sc, Sh = set(), set(), set(), set(), set()
for _ in range(n):
    s = input()
    if s[0]=='M':
        Sm.add(s)
    elif s[0]=='A':
        Sa.add(s)
    elif s[0]=='R':
        Sr.add(s)
    elif s[0]=='C':
        Sc.add(s)
    elif s[0]=='H':
        Sh.add(s)

ans = 0
S = [len(Sm), len(Sa), len(Sr), len(Sc), len(Sh)]

for v1, v2, v3 in combinations(S, 3):
    ans += v1*v2*v3

print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
n, *S = open(0).read().split()
n = int(n)
march = []
for c in 'MARCH':
    march.append(len([s for s in S if s[0] == c]))
ans = 0
for a, b, c in combinations(march, 3):
    ans += a*b*c
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
alp = list("MARCH")
data = [0]*5
for i in range(N):
    s = list(input())
    for i in range(5):
        if alp[i] == s[0]: data[i] += 1

flag = 0
for i in range(5):
    if data[i] != 0: flag += 1

if flag < 3:
    print(0)
else:
    ans = 0
    for a in range(3):
        for b in range(a+1,4):
            for c in range(b+1,5):
                ans += data[a]*data[b]*data[c]
    print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
import collections

N = int(input()) 

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

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

Submission status: Accepted

Solution code:
N = int(input())
alp = list("MARCH")
data = [0]*5
for i in range(N):
    s = list(input())
    for i in range(5):
        if alp[i] == s[0]: data[i] += 1

flag = 0
for i in range(5):
    if data[i] != 0: flag += 1

if flag < 3:
    print(0)
else:
    ans = 0
    for a in range(3):
        for b in range(a+1,4):
            for c in range(b+1,5):
                ans += data[a]*data[b]*data[c]
    print(ans)

Submission status: Accepted

Solution code:
import itertools
from collections import Counter

n=int(input())
s=[input()[0] for _ in range(n)]
d=Counter(s)
ans=0
for i,j,k in itertools.combinations("MARCH",3):
    ans+=d[i]*d[j]*d[k]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
m,a,r,c,h = 0,0,0,0,0
for i in range(n):
    s = input()[0]
    if s=='M':m+=1
    elif s=='A':a+=1
    elif s=='R':r+=1
    elif s=='C':c+=1
    elif s=='H':h+=1
x = [m,a,r,c,h]
ans = 0
for i in range(5):
    for j in range(i):
        for k in range(j):
                ans += x[i]*x[j]*x[k]
print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import Counter


N = int(input())
C = Counter()
for s in sys.stdin.readlines():
    C[s[0]] += 1

I = ['M', 'A', 'R', 'C', 'H']
ans = 0
for i in range(1 << 5):
    bit = i
    if bin(bit).count('1') == 3:
        var = 1
        for k in range(5):
            if (bit >> k) & 1:
                var *= C[I[k]]
        ans += var

print(ans)

Submission status: Accepted

Solution code:
import collections
import itertools
N=int(input())
S=[input() for _ in range(N)]
l=[]
l2=[]
l3=[]
sq=[]
lst=[]
cnt=0
for i in range(N):
    if (S[i][0]=="M")or(S[i][0]=="A")or(S[i][0]=="R")or(S[i][0]=="C")or(S[i][0]=="H"):
        l2.append(S[i][0])
c=collections.Counter(l2)
values=list(c.values())	#aのCollectionのvalue値のリスト(n_1こ、n_2こ…)
key=list(c.keys())	#先のvalue値に相当する要素のリスト(要素1,要素2,…)
for i in range(len(key)):
    sq.append(values[i])
    l.append([key[i],values[i]])#lは[要素i,n_i]の情報を詰めたmatrix
lst=list(itertools.combinations(sq,3))
for i in range(len(lst)):
    l3=list(lst[i])
    cnt=cnt+l3[0]*l3[1]*l3[2]

print(cnt)

Submission status: Accepted

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

from itertools import combinations


def main():

    N = int(input())

    count = {x: 0 for x in "MARCH"}

    for _ in range(N):
        s = input()[0]
        if s in count:
            count[s] += 1

    result = 0
    for a, b, c in combinations("MARCH", 3):
        result += count[a] * count[b] * count[c]

    print(result)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
initials = ['M', 'A', 'R', 'C', 'H']
names = dict()
for init in initials:
  names[init] = set()

for i in range(N):
  si = str(input())
  if si[0] in initials:
    names[si[0]].add(si)
#print(names)

from itertools import combinations
ans = 0
for init in combinations(initials, 3):
  cmb = len(names[init[0]]) * len(names[init[1]]) * len(names[init[2]])
  ans += cmb
  #print(init, cmb)

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
L=[]
for i in range (N):
	L.append(input())
M=0
A=0
R=0
C=0
H=0
for i in L:
	if i[0]=="M":
		M+=1
	elif i[0]=="A":
		A+=1
	elif i[0]=="R":
		R+=1
	elif i[0]=="C":
		C+=1
	elif i[0]=="H":
		H+=1
ans=(M*A*R)+(M*A*C)+(M*A*H)+(M*R*C)+(M*R*H)+(M*C*H)+(A*R*C)+(A*R*H)+(A*C*H)+(R*C*H)
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()

m=0
a=0
r=0
c=0
h=0

for i in range(n):
    s=ss()
    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
mat=[m,a,r,c,h]
#print(mat)
arr=list(combinations([0,1,2,3,4],3))
ans=0
for i in arr:
    if mat[i[0]]>0 and mat[i[1]]>0 and mat[i[2]]>0:
        ans+=mat[i[0]]*mat[i[1]]*mat[i[2]]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
march = 'MARCH'
c = [0] * 5

for _ in range(n):
    s = input()
    for i in range(5):
        if s[0] == march[i]:
            c[i] += 1
ans = 0
for i in range(3):
    for j in range(i+1, 4):
        for k in range(j+1, 5):
            ans += c[i] * c[j] * c[k]
            # print('i:{}, j:{}, k:{}, ci:{}, cj:{}, ck:{}, ci*cj*ck:{}'
            #       .format(i, j, k, c[i], c[j], c[k], c[i] * c[j] * c[k]))

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
march = 'MARCH'
c = [0] * 5

for _ in range(n):
    s = input()
    for i in range(5):
        if s[0] == march[i]:
            c[i] += 1

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

print(ans)

Submission status: Accepted

Solution code:
_,*l=open(0);from itertools import*;print(sum(x*y*z for x,y,z in combinations([sum(c==s[0]for s in l)for c in'MARCH'],3)))

Submission status: Accepted

Solution code:
_,*l=open(0)
import itertools as it
print(sum(x*y*z for x,y,z in it.combinations([sum(s[0]==c for s in l) for c in 'MARCH'],3)))

Submission status: Accepted

Solution code:
l=[input()[0] for _ in range(int(input()))]
import itertools as it
print(sum(x*y*z for x,y,z in it.combinations([l.count(c) for c in 'MARCH'],3)))

Submission status: Accepted

Solution code:
from collections import *
d=Counter()
for _ in range(int(input())): 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: Accepted

Solution code:
n=int(input())
from collections import *
d=Counter()
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: 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
ans=ans+a*r*(c+h)+a*c*h+r*c*h

print(ans)

Submission status: Accepted

Solution code:
m=[0]*5
for i in range(int(input())):
        try: m["MARCH".index(input()[0])]+=1
        except: continue
ans = 0
for i in range(5):
        for j in range(i+1,5):
                for k in range(j+1, 5):
                        ans += m[i]*m[j]*m[k]
print(ans)

Submission status: Accepted

Solution code:
ListM = []
ListA = []
ListR = []
ListC = []
ListH = []
N = int(input())
for j in range(N):
 S = input()
 if S[0] == "M":
  ListM.append(S)
 elif S[0] == "A":
  ListA.append(S)
 elif S[0] == "R":
  ListR.append(S)
 elif S[0] == "C":
  ListC.append(S)
 elif S[0] == "H":
  ListH.append(S)
 S = ()
print(len(ListM)*len(ListA)*len(ListR)+len(ListM)*len(ListA)*len(ListC)+len(ListM)*len(ListA)*len(ListH)+len(ListM)*len(ListR)*len(ListC)+len(ListM)*len(ListH)*len(ListR)+len(ListM)*len(ListC)*len(ListH)+\
len(ListC)*len(ListA)*len(ListR)+len(ListH)*len(ListA)*len(ListR)+len(ListC)*len(ListA)*len(ListH)+len(ListH)*len(ListC)*len(ListR))

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = [input() for i in range(N)]
dic = defaultdict(int)
for s in S:
    if s[0] in "MARCH":
        dic[s[0]] += 1

march = list("MARCH")
L = list(combinations(march, 3))
ans = 0
for l in L:
    tmp = 1
    for y in l:
        tmp *= dic[y]
    ans += tmp
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
start={"M","A","R","C","H"}
import collections
d=collections.defaultdict(set)
for i in range(n):
    a=input()
    if a not in d[a[0]] and a[0] in start:
        d[a[0]].add(a)

lis=[len(i) for i in d.values() if len(i)>0]

num=len(lis)
if num<3:
    print(0)
    exit()
ans=0
for x in range(num-2):
    for y in range(x+1,num-1):
        for z in range(y+1,num):
            ans+=lis[x]*lis[y]*lis[z]
print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    ans = []
    for i in range(N):
        s = input()
        if s[0] in ["M", "A", "R", "C", "H"]:
            ans.append(s[0])
    from collections import Counter
    c = Counter(ans)
    ret = 0
    from itertools import combinations
    for com in combinations(c.values(), 3):
        ret += com[0]*com[1]*com[2]
    print(ret)


if __name__ == '__main__':
    main()

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=0

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

ans+=a*r*c
ans+=a*r*h
ans+=a*c*h

ans+=r*c*h

print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
import collections
N = int(input())
S = [input() for i in range(N)]
table = collections.defaultdict(int)

for x in S:
    table[x[0]] += 1

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


ans = 0
for x in combinations(tmp, 3):
    ans += table[x[0]]*table[x[1]]*table[x[2]]
print(ans)

Submission status: Accepted

Solution code:
import sys
argVec = sys.argv
if len(argVec) > 1:
    GBN_DEBUG = True
else:
    GBN_DEBUG = False

#S = input()
N = int(input())
#S, T = input().split()
#N, M = map(int, input().split())
S = [input() for _ in range(N)]
#A = A = list(map(int, input().split()))

def dprn(s, i):
    if GBN_DEBUG:
        print(", " + s + " = " + str(i), end = "")

def dprns(s):
    if GBN_DEBUG:
        print(", " + s, end = "")

def dprni(i):
    if GBN_DEBUG:
        print(str(i), end=" ")

def puts(s):
    print(s)

def puti(i):
    print(str(i))

startM = 0
startA = 0
startR = 0
startC = 0
startH = 0

for i in range(N):
    if S[i][0] == 'M':
        startM += 1
    if S[i][0] == 'A':
        startA += 1
    if S[i][0] == 'R':
        startR += 1
    if S[i][0] == 'C':
        startC += 1
    if S[i][0] == 'H':
        startH += 1

mar = startM * startA * startR
mac = startM * startA * startC
mah = startM * startA * startH
mrc = startM * startR * startC
mrh = startM * startR * startH
mch = startM * startC * startH
arc = startA * startR * startC
arh = startA * startR * startH
ach = startA * startC * startH
rch = startR * startC * startH

ans = mar + mac + mah + mrc + mrh + mch + arc + arh + ach + rch
puti(ans)

Submission status: Accepted

Solution code:
N = int(input())
m = a = r = c = h = 0
for _ in range(N):
  s_in = input()
  if s_in[0] == "M": m += 1
  elif s_in[0] == "A": a += 1
  elif s_in[0] == "R": r+= 1
  elif s_in[0] == "C": c += 1
  elif s_in[0] == "H": h += 1

all_l = [m, a, r, c, h]
ans = 0
import itertools
for v in itertools.combinations(all_l, 3):
  if v[0] * v[1] * v[2] > 0:
    ans += v[0] * v[1] * v[2]
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
from itertools import combinations
from functools import reduce
from operator import mul
n = int(input())
S = [input()[0] for _ in range(n)]
S = [s for s in S if s in {"M","A","R","C","H"}]
cs = Counter(S)
ptn = combinations(cs.keys(), 3)

ans = 0
for p in ptn:
  arr = [cs[i] for i in p]
  ans += reduce(mul, arr)
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
from collections import defaultdict
import sys
input = sys.stdin.readline

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

ans = 0
for h in combinations(['M', 'A', 'R', 'C', 'H'], r=3):
    prd = 1
    for s in h:
        prd *= cnt[s]
    ans += prd
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
N = int(input())
d = {}
for _ in range(N):
    s = input()
    if not s[0] in ("M","A","R","C","H"):
        continue
    if s[0] in d.keys():
        d[s[0]] += 1
    else:
        d[s[0]] = 1
ret = 0
comb = combinations(d.values(), 3)
for i in comb:
    tmp = 1
    for j in i:
        tmp *= j
    ret += tmp

print(ret)

Submission status: Accepted

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

if sum(S) == 0:
    print(0)
    exit(0)

I = [0, 0, 0, 0, 0, 0, 1, 1, 1, 2]
J = [1, 2, 3, 1, 1, 2, 2, 3, 2, 3]
K = [2, 3, 4, 3, 4, 4, 3, 4, 4, 4]
ans = 0
for i in range(10):
    ans += S[I[i]]*S[J[i]]*S[K[i]]
print(ans)

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    nameCount = [0] * 5
    N = int(input())
    for _ in range(N):
        s = input().strip("\n")
        if s[0] == "M": nameCount[0] += 1
        elif s[0] == "A": nameCount[1] += 1
        elif s[0] == "R": nameCount[2] += 1
        elif s[0] == "C": nameCount[3] += 1
        elif s[0] == "H": nameCount[4] += 1
        else: continue
    Ans = 0
    for i in range(3):
        for j in range(i+1, 4):
            for k in range(j + 1, 5):
                Ans += nameCount[i] * nameCount[j] * nameCount[k]
    print(Ans)


    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc089/tasks/abc089_c

from itertools import combinations

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

S=dict()
w=['M','A','R','C','H']

for e in s:
    fst=e[0]
    if fst in w:
        S[fst]=S.get(fst,0)+1

C=list(combinations(S,3))

ans=0
for c in C:
    tmp=1
    for e in c:
        tmp*=S[e]
    ans+=tmp
print(ans)