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:
N = int(input())
M = []
A = []
R = []
C = []
H = []
for _ in range(N):
    s = input()
    if s.startswith("M"):
        M.append(s)
    if s.startswith("A"):
        A.append(s)
    if s.startswith("R"):
        R.append(s)
    if s.startswith("C"):
        C.append(s)
    if s.startswith("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 collections import defaultdict
from itertools import combinations
def inpl(): return list(map(int, input().split()))

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

res = 0
for H in combinations("MARCH", r=3):
    res += C[H[0]] * C[H[1]] * C[H[2]]
print(res)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
s = [input() for _ in range(n)]
cnt = 0
c = Counter(x[0] for x in s)
for x in s:
    if x[0] in "MARCH":
        cnt += 1
ans = cnt * (cnt - 1) * (cnt - 2) // 6
for k, v in c.items():
    if k not in "MARCH":
        continue
    if v >= 2:
        ans -= v * (v - 1) // 2 * (cnt - v)
    if v >= 3:
        ans -= v * (v - 1) * (v - 2) // 6
print(ans)

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    D = dict()
    W = ["M", "A", "R", "C", "H"]
    for w in W: D[w] = 0
    for _ in range(N):
        S = input().strip("\n")
        if S[0] in W:
            D[S[0]] += 1
    
    ans = 0
    for i in range(3):
        for j in range(i+1, 4):
            for k in range(j+1, 5):
                ans += D[W[i]] * D[W[j]] * D[W[k]]
    print(ans)

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
from itertools import combinations as cmbs
c = {"M":0,"A":0,"R":0,"C":0,"H":0}
for i in range(int(input())):
  si = input()
  if si[0] in c:
    c[si[0]] += 1
ans = 0
for i,j,k in cmbs(c.values(),r=3):
  t = i*j*k
  ans += t
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
m = 0
a = 0
r = 0
c = 0
h = 0
for _ in range(n):
    s = str(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

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

Submission status: Accepted

Solution code:
def idx_cmb(n, r):
    import itertools
    lst1 = [i for i in range(0, n)]
    lst = list(itertools.combinations(lst1, r))
    return lst


def main():
    n = int(input())
    s_lst = [str(input()) for _ in range(n)]

    march = [0] * 5
    for i in range(n):
        s = s_lst[i]
        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

    idx_lst = idx_cmb(5, 3)
    x = 0
    for i in range(len(idx_lst)):
        idx1 = idx_lst[i][0]
        idx2 = idx_lst[i][1]
        idx3 = idx_lst[i][2]
        number1 = march[idx1]
        number2 = march[idx2]
        number3 = march[idx3]
        x += number1 * number2 * number3

    print(x)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools
N=int(input())
s=set(["M","A","R","C","H"])
d=dict(zip(list(s),[0]*5))
for _ in range(N):
    try:
        d[input()[0]]+=1
    except KeyError:
        pass
ans=0
for v in itertools.combinations(d.keys(), 3):
    ans+=d[v[0]]*d[v[1]]*d[v[2]]

print(ans)
#S=[input() for _ in range(N) if input()[0] in s]

Submission status: Accepted

Solution code:
n=int(input())
march=["M","A","R","C","H"]
cnt=[0]*5
for i in range(n):
  inp=input()
  for j in march:
    if inp[0]==j:
      cnt[march.index(j)]+=1
ans=0
for i in range(5):
  for j in range(i+1,5):
    for k in range(j+1,5):
      ans+=cnt[i]*cnt[j]*cnt[k]
      
print(ans)

Submission status: Accepted

Solution code:
import itertools

n = int(input())
d = {'M':0, 'A':1, 'R':2, 'C':3, 'H':4}
h = [0, 0, 0, 0, 0]
for _ in range(n):
  name = input()
  if name[0] in d.keys():
    h[d[name[0]]] += 1

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

Submission status: Accepted

Solution code:
import itertools
 
n = int(input())
 
 
data = [[] for i in range(5)]
# print(data)
for i in range(n):
    tmp = str(input())
    if tmp[0] == "M":
        data[0].append(tmp)
    elif tmp[0] == "A":
        data[1].append(tmp)
    elif tmp[0] == "R":
        data[2].append(tmp)
    elif tmp[0] == "C":
        data[3].append(tmp)
    elif tmp[0] == "H":
        data[4].append(tmp)
 
ans = 0
for i, j, k in itertools.combinations([0, 1, 2, 3, 4], 3):
    ans += len(data[i])*len(data[j])*len(data[k])
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
S=[input()[0] for _ in range(N)]
A=[S.count(c) for c in "MARCH"]
ans=0
for i in range(5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            ans+=A[i]*A[j]*A[k]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools

n = int(input())

name = {"M":[],"A":[],"R":[],"C":[],"H":[]}
for i in range(n):
    s = input()
    if s[0] not in name:
        continue
    else:
        name[s[0]].append(s)

ans = 0
for p,q,r in itertools.combinations(name.keys(), 3):
    ans += len(name[p])*len(name[q])*len(name[r])
    
print(ans)

Submission status: Accepted

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


def read():
    N = int(input().strip())
    S = []
    for i in range(N):
        s = input().strip()
        S.append(s)
    return N, S


def solve(N, S):
    Z = [0 for i in range(26)]
    for s in S:
        a = s[0]
        Z[ord(a)-ord("A")] += 1
    ans = 0
    D = [Z[ord(a)-ord("A")] for a in "MARCH"]
    for i, j, k in combinations(D, r=3):
        ans += i * j * k
    return ans


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Submission status: Accepted

Solution code:
import itertools
from collections import defaultdict
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N = ii()
    count = defaultdict(lambda:0)

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

    ans =0
    X = []
    for x in ["M","A","R","C","H"]:
        if count[x] < 1: continue
        X.append(x)
    
    if len(X) < 3:
        print(0)
        exit()

    for V in itertools.combinations(X,3):
        U = list(V)
        res = 1
        for u in U:
            res *= count[u]
        
        ans += res


    print(ans)

        
     


if __name__ == "__main__":
    main()

Submission status: Accepted

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

n = int(input())


data = [[] for i in range(5)]
# print(data)
for i in range(n):
    tmp = str(input())
    if tmp[0] == "M":
        data[0].append(tmp)
    elif tmp[0] == "A":
        data[1].append(tmp)
    elif tmp[0] == "R":
        data[2].append(tmp)
    elif tmp[0] == "C":
        data[3].append(tmp)
    elif tmp[0] == "H":
        data[4].append(tmp)

ans = 0
for i, j, k in itertools.combinations([0, 1, 2, 3, 4], 3):
    ans += len(data[i])*len(data[j])*len(data[k])
print(ans)

Submission status: Accepted

Solution code:
#
# abc089 c
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """4
ZZ
ZZZ
Z
ZZZZZZZZZZ"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO"""
        output = """7"""
        self.assertIO(input, output)


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

    C = [0]*5
    for s in S:
        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 i, c1 in enumerate(C):
        for j, c2 in enumerate(C[i+1:], i+1):
            for c3 in C[j+1:]:
                ans += c1*c2*c3

    print(ans)


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
dict={'M':0,'A':0,'R':0,'C':0,'H':0}
for i in range(n):
  s=input()
  if s[0] in dict:
    dict[s[0]]+=1
data=['M','A','R','C','H']
ans=0
for i in range(3):
  for j in range(i+1,4):
    for k in range(j+1,5):
      ans+=dict[data[i]]*dict[data[j]]*dict[data[k]]
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=[input() for _ in range(n)]
sdic={}
march=['M', 'A', 'R', 'C', 'H']
ans=0
for i in range(n):
  if s[i][0] in march:
    if s[i][0] in sdic:
      sdic[s[i][0]]+=1
    else:
      sdic[s[i][0]]=1
lis=[_ for _ in sdic.values()]
for j in range(len(lis)-2):
  for k in range(j+1,len(lis)-1):
    for l in range(k+1,len(lis)):
      ans+=lis[j]*lis[k]*lis[l]
print(ans)

Submission status: Accepted

Solution code:
#60 C - March
import collections
import itertools
N = int(input())
S = [input() for _ in range(N)]
S = [s[0] for s in S if s[0] == 'M' or s[0] == 'A' or s[0] == 'R' or s[0] == 'C' or s[0] == 'H']

cnt = collections.Counter(S)

comb = itertools.combinations(cnt.keys(),3)

ans = 0
for a,b,c in comb:
    ans += cnt[a]*cnt[b]*cnt[c]
print(ans)

Submission status: Accepted

Solution code:
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from itertools import combinations, permutations, product
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x):
        self.setdefault(x,0)
        self[x] += 1

N = int(input())
L = [0]*26
for _ in range(N):
    S = input()
    L[ston(S[0],'A')] += 1
s = ['M','A','R','C','H']
ans = 0
for l in combinations(s,3):
    x,y,z = map(lambda x:ston(x,'A'), l)
    ans += L[x]*L[y]*L[z]
print(ans)

Submission status: Accepted

Solution code:
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x):
        self.setdefault(x,0)
        self[x] += 1

N = int(input())
L = [0]*26
for _ in range(N):
    S = input()
    L[ston(S[0],'A')] += 1
s = ['M','A','R','C','H']
ans = 0
for l in [[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]]:
    x,y,z = map(lambda x:ston(s[x],'A'), l)
    ans += L[x]*L[y]*L[z]
print(ans)

Submission status: Accepted

Solution code:
#import
import math
#import numpy as np
N = int(input())

first = "MARCH"

dic = {s:0 for s in first}

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

t = []
for key in dic:
    if dic[key] > 0:
        t.append(dic[key])

if len(t) < 3:
    print(0)
else:
    tl = len(t)
    ans = 0
    for i in range(2 ** tl):
        cnt = []
        for j in range(tl):
            if (i >> j) & 1:
                cnt.append(j)

        if len(cnt) == 3:
            tans = 1
            for i in cnt:
                tans *= t[i]

            ans += tans
    
    print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    L = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
    for i in range(N):
        S = input().rstrip()
        if S[0] in L:
            L[S[0]] += 1
    CNT = 0
    i = 0
    S = [0]*5
    for k, v in L.items():
        S[i] = v
        i += 1
    ans = 0
    for p in range(3):
        for q in range(p+1,4):
            for r in range(q+1,5):
                ans += S[p]*S[q]*S[r]
    print(ans)
    

if __name__ == '__main__':
    main()

Submission status: Accepted

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

march = [0] * 5
for _ in range(N):
  S = input()
  S = S[0]
  if S == "M":
    march[0] += 1
  elif S == "A":
    march[1] += 1
  elif S == "R":
    march[2] += 1
  elif S == "C":
    march[3] += 1
  elif S == "H":
    march[4] += 1
  
ls = list(combinations(range(5),3))

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

Submission status: Accepted

Solution code:
from collections import defaultdict
import itertools

n = int(input())
r = defaultdict(int)
for i in range(n):
    r[input()[0]] += 1

ans = 0
for c in itertools.combinations(list('MARCH'), 3):
    a = 1
    for cc in c:
        a *= r[cc]
    ans += a
print(ans)

Submission status: Accepted

Solution code:
import itertools
from collections import defaultdict

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

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

sum_num = 0
l = ["M", "A", "R", "C", "H"]
for a, b, c in itertools.combinations(l, 3):
    sum_num += d[a] * d[b] * d[c]
print(sum_num)

Submission status: Accepted

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

from itertools import combinations as com 
ans=0
A=list(D.values()) ; # print(A)
for l in com(list(range(5)), 3):
    ans+= A[l[0]]* A[l[1]] * A[l[2]]
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
d={}
l="MARCH"
c=[0 for _ in range(5)]
for n in range(N):
    S=input()
    for n in range(len(l)):
        if l[n]==S[0]:
            c[n]+=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(ans)

Submission status: Accepted

Solution code:
from sys import stdin
rs = lambda : stdin.readline().strip()
ri = lambda : int(rs())
ril = lambda : list(map(int, rs().split()))

def main():
    N = ri()
    d = {s: i for i, s in enumerate('MARCH')}
    l = [0] * 5
    for i in range(N):
        s = rs()[0]
        if s in d:
            l[d[s]] += 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)




if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import itertools

input = sys.stdin.readline

def main():
    N = int(input())
    l = ['M', 'A', 'R', 'C', 'H']
    m = [0]*5
    for _ in range(N):
        S = input()[:-1]
        Shead = S[0]
        for i, s0 in enumerate(l):
            if Shead == s0:
                m[i] += 1
                break
    ll = []
    for i, n in enumerate(m):
        if n >= 1:
            ll.append(l[i])
    if len(ll) <= 2:
        print(0)
        return
    ans = 0
    for i, j, k in itertools.combinations(ll, 3):
        ans += m[l.index(i)] * m[l.index(j)] * m[l.index(k)]

    print(ans)

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()
    s = S[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
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 math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

import string

def main():
    n = i_input()
    dic = {"M":0,"A":0,"R":0,"C":0,"H":0}
    key = list(dic.keys())
    for _ in range(n):
        i = s_input()
        t = i[0]
        if t in key:
            dic[t] = dic.get(t) + 1
    ans = 0
    check = False
    l = list(dic.values())
    l = list(itertools.combinations(l, 3))
    for i in l:
        a = i[0]
        b = i[1]
        c = i[2]
        if a != 0 and b != 0 and c != 0:
            ans += a*b*c
            check = True
    if check:
        print(ans)
    else:
        print(0)


if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
dic = {}
cnt = 0

for i 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" :
        if s[0] in dic :
            dic[s[0]] += 1
        else:
            dic[s[0]] = 1

lis = [x for x in dic.values()]

for j in range(len(lis) - 2) :
    for k in range(j + 1, len(lis) - 1) :
        for l in range(k + 1, len(lis)) :
            
            cnt += lis[j] * lis[k] * lis[l]
    
print(cnt)

Submission status: Accepted

Solution code:
import collections
N = int(input())
lsname = []
for i in range(N):
    name = input()
    lsname.append(name[:1])
counterN = collections.Counter(lsname)
lskey = ['M','A','R','C','H']
lsnum = []
for i in lskey:
    if i in counterN.keys():
        lsnum.append(counterN[i])
ans = 0
lenN = len(lsnum)
for i in range(lenN-2):
    for j in range(i+1,lenN-1):
        for k in range(j+1,lenN):
            ans += lsnum[i]*lsnum[j]*lsnum[k]
print(ans)

Submission status: Accepted

Solution code:
import itertools
n = int(input())
num = [0]*5
name = ['M','A','R','C','H']
for _ in range(n):
    s = str(input())
    for i in range(5):
        if s[0] == name[i]:
            num[i] += 1
            break
num = [k for k in num if k != 0]
c = num.count(0)
if 2 <= c:
    print(0)
else:
    d = 0
    for h,j,l in itertools.combinations(num,3):
        d += (h*j*l)
    print(d)

Submission status: Accepted

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

for i in range(N):
    S.append(str(input()))

S = list(set(S))
# print(S)
name = [0 for i in range(5)]

for j in range(len(S)):
    t = str(S[j])
    if t[0] == "M":
        name[0] += 1
    elif t[0] == "A":
        name[1] += 1
    elif t[0] == "R":
        name[2] += 1
    elif t[0] == "C":
        name[3] += 1
    elif t[0] == "H":
        name[4] += 1
# print(name)

for x in range(5):
    for y in range(5):
        if x == y:
            break
        for z in range(5):
            if x == z or y == z:
                break
            if name[x]*name[y]*name[z] > 0:
                ans += name[x]*name[y]*name[z]

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
name_list =[0,0,0,0,0]
alp =  ["M","A","R","C","H"]
for i in range(n):
  s = input()
  if s[0] in alp:
    name_list[alp.index(s[0])] += 1
ans = 0
for i in range(3):
  for j in range(i+1,4):
    for k in range(j+1,5):
      ans += name_list[i] * name_list[j] * name_list[k]

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
Name = [input()[0] for _ in range(N)]
March = {x:Name.count(x) for x in 'MARCH' if Name.count(x) > 0}

import itertools
ans = 0
for x,y,z in itertools.combinations(March.values(), 3):
    ans += x*y*z
print(ans)

Submission status: Accepted

Solution code:
n=int(input())

march=[0]*5

march_dic={"M":0,"A":1,"R":2,"C":3,"H":4}

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

def count_type(march):
    ans=[]
    for i in march:
        if i!=0:
            ans.append(i)
    ans.sort()
    return len(ans),ans

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

    print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
import itertools

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

cnt = Counter(s)
ans = 0
for x, y, z in itertools.combinations("MARCH", 3):
    ans += cnt[x] * cnt[y] * cnt[z]
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
from functools import reduce

n = int(input())
x = [0 for _ in range(5)]
for _ in range(n):
    s = input()
    if s[0] == "M":
        x[0] += 1
    if s[0] == "A":
        x[1] += 1
    if s[0] == "R":
        x[2] += 1
    if s[0] == "C":
        x[3] += 1
    if s[0] == "H":
        x[4] += 1

def f(a, b): return a*b

x = [n for n in x if n != 0]
ans = 0
for c in combinations(x, 3):
    ans += reduce(f, c)

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=[input() for _ in range(n)]
m=sum([1 for i in s if i[0]=='M'])
a=sum([1 for i in s if i[0]=='A'])
r=sum([1 for i in s if i[0]=='R'])
c=sum([1 for i in s if i[0]=='C'])
h=sum([1 for i in s if i[0]=='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:
import itertools
n = int(input())
march = dict()

a = "MARCH"
for i in range(5):
    march[a[i]] = 0

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

res = 0
for i in itertools.combinations("MARCH", 3):
    tmp = 1
    for j in i:
        tmp *= march[j]
    res += tmp

print(res)

Submission status: Accepted

Solution code:
'''
Created on 2020/08/31

@author: harurun
'''
def main():
  from itertools import combinations
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write

  N=int(pin())
  ans=0
  d=[0]*5
  for _ in [0]*N:
    S=pin()[:-1][0]
    if S=="M":
      d[0]+=1
    elif S=="A":
      d[1]+=1
    elif S=="R":
      d[2]+=1
    elif S=="C":
      d[3]+=1
    elif S=="H":
      d[4]+=1
  c=list(combinations([0,1,2,3,4],3))
  for i in c:
    cnt=1
    for j in list(i):
      cnt*=d[j] 
    ans+=cnt 
  print(ans)
  return 
main()

Submission status: Accepted

Solution code:
n = int(input())
li = [0]*5

for k in range(n):
    s = input()
    if s[0]=="M":
        li[0]+=1
    elif s[0]=="A":
        li[1]+=1
    elif s[0]=="R":
        li[2]+=1
    elif s[0]=="C":
        li[3]+=1
    elif s[0]=="H":
        li[4]+=1
        
ans = 0
for i in range(2**5):
    num = 1
    if str(bin(i)).count("1")==3:
        for j in range(5):
            if (i>>j&1)==1:
                num *= li[j]
        else:
            ans += num
print(ans)

Submission status: Accepted

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    def select(n,k):
        return math.factorial(n)//(math.factorial(k)*math.factorial(n-k))
    n = I()
    dic = collections.defaultdict(int)
    for _ in range(n):
        s = S()
        if s[0] in {"M","A","R","C","H"}:
            dic[s[0]] += 1

    vlst = [i for i in dic.values() if i!=0]
    ans = 0
    lenth = len(vlst)

    for i in range(lenth):
        for j in range(i+1,lenth):
            for k in range(j+1,lenth):
                ans += select(vlst[i],1)*select(vlst[j],1)*select(vlst[k],1)
    print(ans)
main()

Submission status: Accepted

Solution code:
import sys
from collections import Counter
from itertools import combinations


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()

S = []
ans = 0

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

C = Counter(S)

for w in combinations(["M","A","R","C","H"],3):
    ans += C[w[0]]*C[w[1]]*C[w[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)]
C = Counter(S)

ans = 0
for x, y, z in combinations("MARCH", 3):
  ans += C[x]*C[y]*C[z]

print(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()
  if S[0] in "MARCH":
    D[S[0]] += 1

ans = 0
for C in combinations(("M", "A", "R", "C", "H"), 3):
  temp = 1
  for c in C:
    temp *= D[c]
  ans += temp

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
import itertools 

n = int(input())

d = defaultdict(int)

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

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

c = itertools.combinations(l, 3)

s = 0

for x in c:
    s += d[x[0]] * d[x[1]] * d[x[2]]

print(s)

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
    if s[0]=="A":
        a+=1
    if s[0]=="R":
        r+=1
    if s[0]=="C":
        c+=1
    if s[0]=="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:
import collections
import itertools
n=int(input())
l,s=[],[]
for i in range(n):
    a=input()
    if a[0]=="M" or a[0]=="A" or a[0]=="R" or a[0]=="C" or a[0]=="H":
        l.append(a[0])
        if s.count(a[0])==0:
            s.append(a[0])
l=collections.Counter(l)
ans=0
for j in itertools.combinations(s,3):
    ans+=(l[j[0]]*l[j[1]]*l[j[2]])
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
li=[0,0,0,0,0]
for i in range(N):
    S=input()
    if S[0]=="M":
        li[0]+=1
    if S[0]=="A":
        li[1]+=1
    if S[0]=="R":
        li[2]+=1
    if S[0]=="C":
        li[3]+=1
    if S[0]=="H":
        li[4]+=1
lim=0
for j in range(5):
    if li[j]!=0:
        lim+=1
temp=1   
li.sort(reverse=True)
ans=0
if lim==3:
    ans=li[0]*li[1]*li[2]
elif lim==4:
    lis=[[1,2,3],[1,2,4],[1,3,4],[2,3,4]]
    for l in range(4):
        for m in range(3):
            temp*=li[lis[l][m]-1]
        ans+=temp
        temp=1
        
elif lim==5:
    lis=[[1,2,3],[1,2,4],[1,2,5],[1,3,4],[1,3,5],[1,4,5],[2,3,4],[2,3,5],[2,4,5],[3,4,5]]
    for l in range(10):
        for m in range(3):
            temp*=li[lis[l][m]-1]
        ans+=temp
        temp=1
        
else:
    ans=0

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = [input()[:1] for _ in range(N)]
c = [S.count(s) for s in 'MARCH' if S.count(s)]
ans = 0
if len(c) > 2:
    ans += c[0]*c[1]*c[2]

if len(c) > 3:
    for i in c[3:]:
        for j in range(3):
            tmp = c[:3]
            tmp[j] = i
            ans += tmp[0]*tmp[1]*tmp[2]
if len(c) > 4:
    tmp = c[3:]
    for j in range(3):
        ans += tmp[0]*tmp[1]*c[j]
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
S = [input()[:1] for _ in range(N)]
c = Counter(S)

first_name = 'MARCH'
c = [c[i] for i in first_name if c[i]]

ans = 0
if len(c) > 2:
    ans += c[0]*c[1]*c[2]

if len(c) > 3:
    for i in c[3:]:
        for j in range(3):
            tmp = c[:3]
            tmp[j] = i
            ans += tmp[0]*tmp[1]*tmp[2]
if len(c) > 4:
    tmp = c[3:]
    for j in range(3):
        ans += tmp[0]*tmp[1]*c[j]
print(ans)