Problem:


Score : 300 points

Problem Statement

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

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

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

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

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

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

Constraints

1 \leq N \leq 10^5

S_i consists of uppercase English letters.

1 \leq |S_i| \leq 10

S_i \neq S_j (i \neq j)

Input

Input is given from Standard Input in the following format:

N
S_1
:
S_N

Output

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

Sample Input 1

5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI

Sample Output 1

2

We can choose three people with the following names:

MASHIKE, RUMOI, HABORO

MASHIKE, RUMOI, HOROKANAI

Thus, we have two ways.

Sample Input 2

4
ZZ
ZZZ
Z
ZZZZZZZZZZ

Sample Output 2

0

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

Sample Input 3

5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO

Sample Output 3

7



Sample input:
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI


Sample output:
2

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    import collections
    import itertools
    import numpy as np
    N = int(input())
    Ss = [input()[0] for _ in range(N)]

    march_letter = [item for item in Ss if item in ['M', 'A', 'R', 'C', 'H']]
    march_cnt = collections.Counter(march_letter)

    if len(march_cnt) < 3:
        res = 0
    else:
        res_list = itertools.combinations(march_cnt.values(),3)

        res = 0
        for element in res_list:
            res += np.prod(np.array(element))
    print(res)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
n = int(input())
li = [0]*5
for i 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
total = li[0]*li[1]*li[2] + li[0]*li[1]*li[3] + li[0]*li[1]*li[4] + li[0]*li[2]*li[3] + li[0]*li[2]*li[4] + li[0]*li[3]*li[4] + li[1]*li[2]*li[3] + li[1]*li[2]*li[4] + li[1]*li[3]*li[4] + li[2]*li[3]*li[4]
print(total)

Submission status: Accepted

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

# In[11]:


import itertools


# In[20]:


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


# In[21]:


ans = 0
for myset in list(itertools.combinations("MARCH",3)):
    ans += S[myset[0]]*S[myset[1]]*S[myset[2]]
print(ans)


# In[ ]:

Submission status: Accepted

Solution code:
n=int(input())
#a,b=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
import itertools
dic={'M':0,'A':0,'R':0,'C':0,'H':0}
for i in range(n):
    s=input()
    dic[s[0]]=dic.get(s[0],0)+1
ans=0
pt=['M','A','R','C','H']
for v in itertools.combinations(pt,3):
    ans+=dic[v[0]]*dic[v[1]]*dic[v[2]]
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
n = int(input())
march = [0 for _ in range(5)]
for i in range(n):
    s = input()

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import Counter
import itertools

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

ans = 0
for x,y,z in itertools.combinations('MARCH',3):
    ans += counter[x] * counter[y] * counter[z]

print(ans)

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n = k()
name = [s() for i in range(n)]
m = [i for i in name if i.startswith("M")]
a = [i for i in name if i.startswith("A")]
r = [i for i in name if i.startswith("R")]
c = [i for i in name if i.startswith("C")]
h = [i for i in name if i.startswith("H")]
ml,al,rl,cl,hl = len(m),len(a),len(r),len(c),len(h)

ans = ml*al*rl + ml*al*cl + ml*al*hl +ml*rl*cl + ml*rl*hl + ml*cl*hl + al*cl*hl + al*rl*cl + al*rl*hl + rl*cl*hl

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n = int(input())
    cc = ['M', 'A', 'R', 'C', 'H']
    cnt = defaultdict(int)
    for _ in range(n):
        s = input()
        if s[0] in cc:
            cnt[s[0]] += 1

    ans = 0
    from itertools import combinations
    kc = list(cnt.keys())
    for a, b, c in combinations(kc, 3):
        ans += cnt[a] * cnt[b] * cnt[c] 
    print(ans)
    
t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

abc

"""

Submission status: Accepted

Solution code:
n=int(input())
march="MARCH"
c=[0 for _ in range(5)]
for i in range(n):
    s=str(input())
    for j in range(5):
        if s[0]==march[j]:
            c[j]+=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:
from collections import Counter
from itertools import combinations
N = int(input())
S = [input()[0] for _ in range(N)]
cnt = Counter(S)
ans = 0
for a, b, c in combinations('MARCH', 3):
    ans += cnt[a] * cnt[b] * cnt[c]

print(ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    S= []
    from collections import defaultdict
    import itertools
    D = defaultdict(int)
    for _ in range(n):
        s = input()
        D[s[0]] += 1

    L = ['M','A','R','C','H']
    ans = 0
    for p in list(itertools.combinations(L,3)):
        t = 1
        for i in p:
            t *= D[i]
        ans += t
    print(ans)

main()

Submission status: Accepted

Solution code:
N = int(input())
cnt_li = [0, 0, 0, 0, 0]
comb = [
    [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],
]
for _ in range(N):
    s = input()
    if s[0] == 'M':
        cnt_li[0] += 1
    if s[0] == 'A':
        cnt_li[1] += 1
    if s[0] == 'R':
        cnt_li[2] += 1
    if s[0] == 'C':
        cnt_li[3] += 1
    if s[0] == 'H':
        cnt_li[4] += 1
ans = 0
for i in range(len(comb)):
    one, two, three = comb[i]
    mid = cnt_li[one] * cnt_li[two] * cnt_li[three]
    ans += mid
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations

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

ans = 0
for a, b, c in list(combinations(d.keys(), 3)):
    ans += (d[a] * d[b] * d[c])

print(ans)

Submission status: Accepted

Solution code:
# だるいので強引

n = int(input())
d = {}
dd = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for _ in range(n):
    s = input()
    if s[0] in list("MARCH") and s not in d:
        d[s] = True
        dd[s[0]] += 1

ans = 0
ans += dd["M"] * dd["A"] * dd["R"]
ans += dd["M"] * dd["A"] * dd["C"]
ans += dd["M"] * dd["A"] * dd["H"]
ans += dd["M"] * dd["R"] * dd["C"]
ans += dd["M"] * dd["R"] * dd["H"]
ans += dd["M"] * dd["C"] * dd["H"]
ans += dd["A"] * dd["R"] * dd["C"]
ans += dd["A"] * dd["R"] * dd["H"]
ans += dd["A"] * dd["C"] * dd["H"]
ans += dd["R"] * dd["C"] * dd["H"]
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n=int(input())

a="MARCH"
cnt=[0]*5
for i in range(n):
    s=input()
    for i in range(5):
        if s[0]==a[i]:
            cnt[i]+=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:
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    d = defaultdict(int)
    for _ in range(n):
        si = input()
        d[si[0]] += 1
    dn = {0:"M",1:"A",2:"R",3:"C",4:"H"}
    ans = 0
    for j in itertools.combinations(range(5),3):
        ans += d[dn[j[0]]]*d[dn[j[1]]]*d[dn[j[2]]]
    print(ans)
    return None

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

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

ans=0
for q in list(itertools.combinations([0,1,2,3,4], 3)):
    c=1
    for i in q:
        c*=l[i]
    ans+=c
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

d = defaultdict(int)
n = readInt()
for c in [input() for i in range(n)]:
	d[c[0]]+=1
tar = [d["M"],d["A"],d["R"],d["C"],d["H"]]
ans = 0
for a in itertools.combinations(tar,3):
	ans+=a[0]*a[1]*a[2]

print(ans)

Submission status: Accepted

Solution code:
import sys
from itertools import combinations
def input(): return sys.stdin.readline().strip()


def main():
    n = int(input())
    d = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
    for _ in range(n):
        c = input()
        if c[0] in d: d[c[0]] += 1
    #print(d)
    ans = 0
    for a, b, c in combinations(['M', 'A', 'R', 'C', 'H'], 3):
        ans += d[a] * d[b] * d[c]
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def INT():
    return int(input())

def MI():
    return map(int, input().split())

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

from itertools import combinations

N = INT()
march = {}

for ini in "MARCH":
    march[ini] = 0
    
for _ in range(N):
    s = input()
    
    if s[0] in "MARCH":
        march[s[0]] += 1

ans = 0

for comb in combinations(march.values(), 3):
    tmp = 1
    for c in comb:
        tmp *= c
    
    ans += tmp
    
print(ans)

Submission status: Accepted

Solution code:
import itertools

N = int(input())
count = [0, 0, 0, 0, 0]
for _ in range(N):
    l = input()[0]
    if l == 'M':
        count[0] += 1
    elif l == 'A':
        count[1] += 1
    elif l == 'R':
        count[2] += 1
    elif l == 'C':
        count[3] += 1
    elif l == 'H':
        count[4] += 1
ans = 0
for c in itertools.combinations(count, 3):
    ans += c[0]*c[1]*c[2]

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
S_dict={'M':0,'A':0,'R':0,'C':0,'H':0}

for n in range(N):
    S = list(input())[0]
    try:
        S_dict[S]+=1
    except:
        pass
S_dict

from itertools import combinations
ans=0
for c_ in combinations(S_dict.keys(),3):
    ans+=S_dict[c_[0]]*S_dict[c_[1]]*S_dict[c_[2]]
print(ans)

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n = ri()
c = collections.Counter([rr()[0] for _ in range(n)])
d = [v for k, v in c.items() if k in 'MARCH']
ans = 0
if len(d) >= 3:
    for lis in itertools.combinations(d, 3):
        a, b, c = lis
        ans += a*b*c
    print(ans)
else:
    print(0)

Submission status: Accepted

Solution code:
from itertools import combinations
n=int(input())
d=dict({'M':0,'A':0,'R':0,'C':0,'H':0})
for _ in range(n):
    s=input()[0]
    if s in d:
        d[s]+=1
ans=0
for a,b,c in list(combinations(d.keys(),3)):
    ans+=(d[a]*d[b]*d[c])
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
from collections import defaultdict
dic = defaultdict(int)
for _ in range(N):
    s = input()
    dic[s[0]]+= 1
print(dic['M']*dic['A']*dic['R']+dic['M']*dic['A']*dic['C']+dic['M']*dic['A']*dic['H']+dic['M']*dic['C']*dic['R']+dic['M']*dic['H']*dic['R']+dic['M']*dic['C']*dic['H']+dic['C']*dic['A']*dic['R']+dic['H']*dic['A']*dic['R']+dic['C']*dic['H']*dic['R']+dic['C']*dic['A']*dic['H'])

Submission status: Accepted

Solution code:
from collections import Counter
from itertools import combinations
n = int(input())
s = []
for _ in range(n):
  t = input()[0]
  if t in {"M","A","R","C","H"}:
    s.append(t)

count = Counter(s)
if len(count) < 3:
  print(0)
  exit()

nums = []
for i in count.values():nums.append(i)

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

Submission status: Accepted

Solution code:
N = int(input())
S = [input()[0] for i in range(N)]
from collections import Counter
ctr = Counter(S)
 
ans = 0
import itertools
for ptn in itertools.combinations('MARCH', 3):
    a,b,c = ptn
    ans += ctr[a] * ctr[b] * ctr[c]
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 = 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
    
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 functools import reduce
from operator import mul
from itertools import combinations
n = int(input())
cnt = [0]*5
for _ in range(n):
    s = input()
    if s[0] not in 'MARCH':
        continue
    i = 'MARCH'.index(s[0])
    cnt[i] += 1


ans = 0
for subset in combinations(range(5), 3):
    ans += reduce(mul, [cnt[i] for i in subset])

print(ans)

Submission status: Accepted

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

for i in range(5):
    for j in range(i+1, 5):
        for k in range(j+1, 5):
            result += m[i]*m[j]*m[k]
print(result)

Submission status: Accepted

Solution code:
import itertools
N = int(input())
dic = [0 for _ in range(5)]
for i in range(N):
    S = input()
    data = S[0]
    if data == "M":  dic[0] += 1
    if data == "A":  dic[1] += 1
    if data == "R":  dic[2] += 1
    if data == "C":  dic[3] += 1
    if data == "H":  dic[4] += 1
    
a = range(5)
comb = list(itertools.combinations(a, 3))

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

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
s = [str(input()) for _ in range(n)]
count = [0]*5
# M A R C H
for i in range(n):
    if s[i][0] == "M":
        count[0] += 1
    elif s[i][0] == "A":
        count[1] += 1
    elif s[i][0] == "R":
        count[2] += 1
    elif s[i][0] == "C":
        count[3] += 1
    elif s[i][0] == "H":
        count[4] += 1
ans = 0
ans += count[0]*count[1]*count[2]
ans += count[0]*count[1]*count[3]
ans += count[0]*count[1]*count[4]
ans += count[0]*count[2]*count[3]
ans += count[0]*count[2]*count[4]
ans += count[0]*count[3]*count[4]
ans += count[1]*count[2]*count[3]
ans += count[1]*count[2]*count[4]
ans += count[1]*count[3]*count[4]
ans += count[2]*count[3]*count[4]
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)+(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:
n=int(input())
d={'M':0,'A':0,'R':0,'C':0,'H':0}
ans=0
for _ in range(n):
	i=input()
	try:
		d[i[0]]+=1
	except:
		pass
ans+=d['M']*d['A']*d['R']
ans+=d['M']*d['A']*d['C']
ans+=d['M']*d['A']*d['H']
ans+=d['M']*d['C']*d['H']
ans+=d['M']*d['R']*d['H']
ans+=d['A']*d['R']*d['C']
ans+=d['A']*d['R']*d['H']
ans+=d['A']*d['C']*d['H']
ans+=d['R']*d['C']*d['H']
ans+=d['M']*d['C']*d['R']
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect

sys.setrecursionlimit(10**6)
def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()


def C(line):
    return [sys.stdin.readline() for _ in range(line)]

def nck(n, k, mod):
    bunbo = bunshi = 1
    for i in range(k):
        bunshi = (bunshi * (n-i)) % mod
        bunbo = (bunbo * (i+1)) % mod
    return (bunshi * pow(bunbo, mod-2, mod)) % mod

N = z()
s = []
M,A,R,C,H = 0, 0, 0, 0, 0
for i in range(N):
    tmp = S()
    if (tmp[0] == 'M'):
        M+=1
    elif (tmp[0] == 'A'):
        A+=1
    elif (tmp[0] == 'R'):
        R+=1
    elif (tmp[0] == 'C'):
        C+=1
    elif (tmp[0] == 'H'):
        H+=1
ans = M*A*R + M*A*C + M*A*H + M*R*C + M*R*H \
     + M*C*H + A*R*C + A*C*H + R*C*H+ A*R*H
print(ans)

Submission status: Accepted

Solution code:
import sys

n=int(input())
if n<3:
  print(0)
  sys.exit()

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

for i in range(n):
  s=input()
  s0=s[0]
  
  if s0=="M":
    m+=1
  elif s0=="A":
    a+=1
  elif s0=="R":
    r+=1
  elif s0=="C":
    c+=1
  elif s0=="H":
    h+=1

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


ans=0
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:
n = int(input())
s = [input() for _ in range(n)]

name_cnt = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
for s_i in s:
    if s_i[0] in name_cnt.keys():
        name_cnt[s_i[0]] += 1

name_set = set()
name_chars = list(name_cnt.keys())

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

Submission status: Accepted

Solution code:
from itertools import combinations

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

d = dict()
for name in s:
    if name[0] not in d:
        d[name[0]] = 1
    else:
        d[name[0]] += 1

res = 0
for v in combinations(['M', 'A', 'R', 'C', 'H'], 3):
    if v[0] in d and v[1] in d and v[2] in d:
        res += d[v[0]] * d[v[1]] * d[v[2]]

print(res)

Submission status: Accepted

Solution code:
from itertools import combinations

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

d = dict()
for name in s:
    if name[0] not in d:
        d[name[0]] = 1
    else:
        d[name[0]] += 1

res = 0
for v in list(combinations(['M', 'A', 'R', 'C', 'H'], 3)):
    if v[0] in d and v[1] in d and v[2] in d:
        res += d[v[0]] * d[v[1]] * d[v[2]]

print(res)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
#l = list()
ch = ['M', 'A', 'R', 'C', 'H']
c = Counter([])
c['M'] = 0
c['A'] = 0
c['R'] = 0
c['C'] = 0
c['H'] = 0
for i in range(n):
    s = str(input())
    if s[0] in ch:
        c[s[0]] += 1
        # l.append(s[0])
cnt = 0
for i in range(5):
    for j in range(i+1, 5):
        for k in range(j+1, 5):
            # print(i,j,k)
            cnt += c.most_common()[i][1] * \
                c.most_common()[j][1]*c.most_common()[k][1]
print(cnt)

Submission status: Accepted

Solution code:
N=int(input())
M=[]
A=[]
R=[]
C=[]
H=[]

for i in range(N):
    tmp=input()
    if tmp[0]=="M":
        M.append(tmp)
    elif tmp[0]=="A":
        A.append(tmp)
    elif tmp[0]=="R":
        R.append(tmp)
    elif tmp[0]=="C":
        C.append(tmp)
    elif tmp[0]=="H":
        H.append(tmp)

m=len(M)
a=len(A)
r=len(R)
c=len(C)
h=len(H)

if len(M)+len(A)+len(R)+len(C)+len(H)<=2:
    print(0)
else:
    print(m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*c*h+ a*r*h+r*c*h)

Submission status: Accepted

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

cnt=[0]*5

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

ans=0
keta=[0]*5
for i in range(7,29):
 
    for x in range(5):
        keta[x]=(i>>x)&1

    if sum(keta)!=3:
        continue
    
    product=1
    for j in range(5):
        if keta[j]==1:
            product*=cnt[j]

    ans+=product

print(ans)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
m=0
a=0
r=0
c=0
h=0

n=int(input())
for i in range(n):
    p=input()
    if p[0]=="M":
        m+=1
    elif p[0]=="A":
        a+=1
    elif p[0]=="R":
        r+=1
    elif p[0]=="C":
        c+=1
    elif p[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 as comb
from collections import Counter


def main():
    n = int(input())
    ss = [input()[0] for _ in range(n)]
    marchs = ['M', 'A', 'R', 'C', 'H']
    ssc = Counter(ss)

    Counts = []
    for march in marchs:
        if march in ssc:
            Counts.append(ssc[march])

    ans = 0
    for a, b, c in comb(Counts, 3):
        ans += a*b*c
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
n=int(input())
s=[input() for _ in range(n)]
d={"M":0,"A":0,"R":0,"C":0,"H":0}
l=itertools.combinations(["M","A","R","C","H"],3)
for i in range(n):
    if s[i][0] in d:
        d[s[i][0]]+=1
ans=0
for i in l:
    a,b,c=i
    ans+=d[a]*d[b]*d[c]
print(ans)

Submission status: Accepted

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

import itertools

n = int(input())
names = []
march = {
    'M': 0,
    'R': 0,
    'A': 0,
    'C': 0,
    'H': 0
}

while True:
    try:
        names.append(input())
    except EOFError:
        break


for name in names:
    try:
        march[name[0]] += 1
    except KeyError:
        continue

patterns = list(itertools.combinations(['M', 'A', 'R', 'C', 'H'], 3))

total = 0
for pattern in patterns:
    total += march[pattern[0]] * march[pattern[1]] * march[pattern[2]]

print(total)

Submission status: Accepted

Solution code:
member = []
count = 0
name_count = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
N = int(input())
for i in range(N):
    name = input()
    member.append(name)
for i in range(N):
    if member[i][0] in name_count:
        name_count[member[i][0]] += 1
count += name_count['M'] * name_count['A'] * name_count['R']
count += name_count['M'] * name_count['A'] * name_count['C']
count += name_count['M'] * name_count['A'] * name_count['H']
count += name_count['M'] * name_count['R'] * name_count['C']
count += name_count['M'] * name_count['R'] * name_count['H']
count += name_count['M'] * name_count['C'] * name_count['H']
count += name_count['A'] * name_count['C'] * name_count['R']
count += name_count['A'] * name_count['H'] * name_count['R']
count += name_count['A'] * name_count['H'] * name_count['C']
count += name_count['H'] * name_count['C'] * name_count['R']
print(count)

Submission status: Accepted

Solution code:
import sys
import itertools

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N = in_n()
    S = [0] * 5

    march = ['M', 'A', 'R', 'C', 'H']
    for i in range(N):
        ts = in_s()
        fs = ts[0]
        if fs in march:
            S[march.index(fs)] += 1

    comb = itertools.combinations(range(5), 3)

    ans = 0
    for com in comb:
        t = 1
        for c in com:
            t *= S[c]
        ans += t

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import bisect,copy,heapq,string
from collections import *
from math import *
from itertools import *
import sys
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
s = list(input() for i in range(n))
t = [0]*5

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

c = combinations(range(5),3)
ans = 0   
for x in c:
        ans += t[x[0]] * t[x[1]] * t[x[2]]

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

march = ("M","A","R","C","H")
prefix = []
d = {}
for _ in range(n):
  pre = input()[0]
  if pre in march:
    if pre not in prefix:
      prefix.append(pre)
      d[pre] = 1
    else:
      d[pre] += 1
      
t = len(prefix)
if t < 3:
  print(0)
  exit()

ans = 0
for i in range(t-2):
  for j in range(i+1, t-1):
    for k in range(j+1,t):
      ans += d[prefix[i]]*d[prefix[j]]*d[prefix[k]]
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
N = int(input())
dic = {}
for _ in range(N):
    x = list(input())[0]
    if x in ("M", "A", "R", "C", "H"):
        if x not in dic:
            dic[x] = 1
        else:
            dic[x] += 1
ans = 0
comb = list(combinations(dic.keys(), 3))
for x, y, z in comb:
    ans += dic[x] * dic[y] * dic[z]
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations

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

cnt = dict({'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0})
for name in s:
    if name[0] in cnt:
        cnt[name[0]] += 1

ans = 0
for i, j, k in combinations(cnt, 3):
    ans += cnt[i] * cnt[j] * cnt[k]
print(ans)

Submission status: Accepted

Solution code:
import itertools
n = int(input())
counters = {"M":0,"A":0,"R":0,"C":0,"H":0}

for _ in range(n):
  s = input()[0]
  
  if s in "MARCH":
  	counters[s] += 1
res = 0
for i in list(itertools.combinations(["M","A","R","C","H"],3)):
  res += counters[i[0]] * counters[i[1]] * counters[i[2]]

print(res)

Submission status: Accepted

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

res = 0

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

Submission status: Accepted

Solution code:
from itertools import combinations
N = int(input())
name = [0]*5
ans = 0
for i in range(N):
    a = input()
    if a[0] == 'M': name[0] += 1
    elif a[0] == 'A': name[1] += 1
    elif a[0] == 'R': name[2] += 1
    elif a[0] == 'C': name[3] += 1
    elif a[0] == 'H': name[4] += 1
if sum(name) < 3:
    print(0)
else:
    for i in combinations(name, 3):
        ans += i[0]*i[1]*i[2]
    print(ans)

Submission status: Accepted

Solution code:
N=int(input())
C=[0]*6

for _ in range(N):
    C['MARCH'.find(input()[0])]+=1

from itertools import*
D=list(combinations(C[:5],3))

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

print(ans)

Submission status: Accepted

Solution code:
import itertools

n = int(input())

C = [0, 1, 2, 3, 4]

march = [0]*5
for i in range(n):
    a = input()
    if a[0] == "M":
        march[0] += 1
    elif a[0] == "A":
        march[1] += 1
    elif a[0] == "R":
        march[2] += 1
    elif a[0] == "C":
        march[3] += 1
    elif a[0] == "H":
        march[4] += 1
 
tst = list(itertools.combinations(C,3))

ans = 0
for i in range(10):
    ans += march[tst[i][0]] * march[tst[i][1]] * march[tst[i][2]]

print(ans)

Submission status: Accepted

Solution code:
import sys

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    N = ii()
    S = [input() for i in range(N)]
    MARCH = 'MARCH'
    dic = {
        'M': 0,
        'A': 0,
        'R': 0,
        'C': 0,
        'H': 0
    }
    for i in range(N):
        if S[i][0] in dic:
            dic[S[i][0]] += 1

    ans = 0

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

    print(ans)

if __name__ == '__main__':
    main()