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
import itertools
input = sys.stdin.readline


def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def main():
    n = I()
    mylist = ("M", "A", "R", "C", "H")
    mylist2 = [0 for i in range(5)]
    for i in range(n):
        word = input().rstrip()[0]
        for i, k in enumerate(mylist):
            if word == k:
                mylist2[i] += 1
    mylist2 = [i for i in mylist2 if i != 0]
    
    
    if len(mylist2) <= 2:
        print(0)
        sys.exit()
    result = 0
    for a, b, c in itertools.combinations(mylist2, 3):
        result += a * b * c
    print(result)
    
main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools

n = int(input())
li = [0]*5
ans = 0

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

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

print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations

count_dict = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}

n = int(input())
for _ in range(n):
    s = input()
    if s[0] in count_dict:
        count_dict[s[0]] += 1

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

Submission status: Accepted

Solution code:
n = int(input())
cs = ['M', 'A', 'R', 'C', 'H']
nums = dict()
for c in cs:
    nums.setdefault(c, 0)

for i in range(n):
    s = input()
    try:
        nums[s[0]] += 1
    except:
        pass

from itertools import combinations
ans = 0
for c1, c2, c3 in combinations(cs, 3):
    ans += nums[c1] * nums[c2] * nums[c3]
print(ans)

Submission status: Accepted

Solution code:
import sys
from itertools import combinations

input = sys.stdin.readline


def main():
    N = int(input())
    S = [""] * N
    for i in range(N):
        S[i] = input().rstrip()

    count = dict(M=0, A=0, R=0, C=0, H=0)
    for s in S:
        if s[0] in "MARCH":
            count[s[0]] += 1

    ans = 0
    for c in combinations("MARCH", 3):
        ans += count[c[0]] * count[c[1]] * count[c[2]]

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import Counter
from itertools import combinations

N = int(input())
cheack = list('MARCH')
S = []
for _ in range(N):
    s = input()
    if s[0] in cheack:
        S.append(s[0])

C = Counter(S)
ans = 0
keys = C.keys()
if len(C.values()) >= 3:
    for comb in combinations(keys, 3):
        tmp = 1
        for i in comb:
            tmp *= C[i]
        ans += tmp
else:
    ans = 0
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

march = 'MARCH'
mdict = {s:0 for s in march}

for i in range(N):
  S = input()
  if S[0] in march:
    mdict[S[0]] += 1
  
lst = [mdict[key] for key in mdict]
ans = 0
for i in range(3):
  for j in range(i+1, 4):
    for k in range(j+1, 5):
      ans += lst[i] * lst[j] * lst[k]
      
print(ans)

Submission status: Accepted

Solution code:
import itertools

n = int(input())
a = []
for _ in range(n):
    b = list(map(str,input()))
    a.append(b)

ans = [0]*5

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

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

print(cnt)

Submission status: Accepted

Solution code:
from itertools import combinations
from collections import Counter
n = int(input())
s = []
ans = 0

for i in range(n):
    name = input()
    if name[0] in 'MARCH':
        s.append(name[0])

count = Counter(s)
for i, j, k in combinations(count, 3):
    ans += count[i] * count[j] * count[k]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
p = [list(str(input())) for _ in range(n)]
m = 0
a = 0
r = 0
c = 0
h = 0
for i in p:
    if i[0] == 'M':
        m += 1
    if i[0] == 'A':
        a += 1
    if i[0] == 'R':
        r += 1
    if i[0] == 'C':
        c += 1
    if i[0] == 'H':
        h += 1
ln = [m, a, r, c, h]
import itertools
ans = 0
for j in itertools.combinations(ln, 3):
    ans += j[0] * j[1] * j[2]
print(ans)

Submission status: Accepted

Solution code:
import itertools
n = int(input())
m = 0
a = 0
r = 0
c = 0
h = 0
for i in range(n):
    dum = input()
    if dum[0] == "M":
        m += 1
    elif dum[0] == "A":
        a += 1
    elif dum[0] == "R":
        r += 1
    elif dum[0] == "C":
        c += 1
    elif dum[0] == "H":
        h += 1
march = [m,a,r,c,h]
ans = 0
for i in itertools.combinations(march,3):
    if i.count(0) == 0:
        ans += i[0]*i[1]*i[2]
print(ans)

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(0,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())
dic={}
M,A,R,C,H=0,0,0,0,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
        
l=[M,A,R,C,H]

p=[[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]]
cnt=0
for i in range(10):
    cnt+=l[p[i][0]]*l[p[i][1]]*l[p[i][2]]
print(cnt)

Submission status: Accepted

Solution code:
import itertools

n = int(input())

MARCH = [0]*5
for _ 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 l in itertools.combinations(MARCH,3):
    ans += l[0]*l[1]*l[2]

print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
import sys
n=int(input())
m=0
a=0
r=0
c=0
h=0
tmp=set()
for i in range(n):
    s=input()
    if s[0]=="M":
        m+=1
        tmp.add("m")
    elif s[0]=="A":
        a+=1
        tmp.add("a")
    elif s[0]=="R":
        r+=1
        tmp.add("r")
    elif s[0]=="C":
        c+=1
        tmp.add("c")
    elif s[0]=="H":
        h+=1
        tmp.add("h")
if len(tmp)<3:
    print(0)
    sys.exit()
tt=[]
for i in [m,a,r,c,h]:
    if i>0:
        tt.append(i)
ans=0
for i,j,k in combinations(tt,3):
    ans+=i*j*k
print(ans)

Submission status: Accepted

Solution code:
import itertools

n = int(input())
s = [input() for _ in range(n)]
march = list("MARCH")
marchlist = [0 for _ in range(5)]

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

ans = 0
for i in itertools.combinations(marchlist, 3):
	tmpans = 1
	for j in range(3):
		tmpans *= i[j]
	ans += tmpans

print(ans)

Submission status: Accepted

Solution code:
import itertools

N = int(input())

MARCH = [0, 0, 0, 0, 0]

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

total = 0
for a, b, c in itertools.combinations(MARCH, 3):
    total += a * b * c
    #print(a, b, c)
print(total)

Submission status: Accepted

Solution code:
n=int(input())
S=[input() for _ in range(n)]
s=[0]*5

for i in range(n):
    if S[i][0]=="M":
        s[0]+=1
    elif S[i][0]=="A":
        s[1]+=1
    elif S[i][0]=="R":
        s[2]+=1
    elif S[i][0]=="C":
        s[3]+=1
    elif S[i][0]=="H":
        s[4]+=1
#print(s)
ans=0
for i in range(3):
    for j in range(i+1,4):
        ans+=s[i]*s[j]*sum(s[j+1:])
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())
count ={'M':0,'A':0,'R':0,'C':0,'H':0}

for _ in range(n):
  temp = input()
  init = temp[0]
  if init in ('M','A','R','C','H'):
    count[init]+=1

ans=0

for x,y,z in list(itertools.combinations(count,3)):
  ans+=count[x]*count[y]*count[z]
else:
  print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations

n = int(input())
# 先頭文字だけが問題なので先頭文字について辞書で管理
march = ['M', 'A', 'R', 'C', 'H']
d = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
for _ in range(n):
    s = input()
    if s[0] in march:
        d[s[0]]= d.get(s[0], 0) + 1

cnt = 0
# 'MARCH'から 3 つ選ぶのは 10 通り
for a, b, c in combinations('MARCH', 3):
    cnt += d[a] * d[b] * d[c]

print(cnt)

Submission status: Accepted

Solution code:
from itertools import combinations


N, *S = open(0).read().split()
MARCH = ("M", "A", "R", "C", "H")
cnt = {c: 0 for c in MARCH}
for s in S:
    if s[0] in MARCH:
        cnt[s[0]] += 1
print(sum(cnt[a] * cnt[b] * cnt[c] for a, b, c in combinations(MARCH, 3)))

Submission status: Accepted

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

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 sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
# import math
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)


n=l()[0]
A=[input() for i in  range(n)]
d={"M":0,"A":0,"R":0,"C":0,"H":0}
for i in range(n):
    if A[i][0] in d:
        d[A[i][0]]+=1
s="MARCH"
ans=0
for i in range(5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            ans+=(d[s[i]]*d[s[j]]*d[s[k]])
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
from itertools import combinations


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

    name = defaultdict(int)
    march = ['M', 'A', 'R', 'C', 'H']

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

    ans = 0
    for c in combinations(march, 3):
        tmp = 1
        for cc in c:
            tmp *= name[cc]
        ans += tmp

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n= int(input())
from itertools import combinations
d=[0,0,0,0,0]

f={}
f['M']=0
f['A']=1
f['R']=2
f['C']=3
f['H']=4

e={}
e['M']=0
e['A']=0
e['R']=0
e['C']=0
e['H']=0


for _ in range(n):

    s = input()[0]
    if s in ['M','A','R','C','H']:
        e[s]=1
        d[f[s]]+=1


k = e['M']+e['A']+e['R']+e['C']+e['H']

cnt=0
if k>=3:
    c = list(combinations(d,3))

    for j in c:
        tmp=1
        for l in j:
            tmp*=l
        
        cnt+=tmp

print(cnt)

Submission status: Accepted

Solution code:

n = int(input())
L = 'MARCH'
S = []
for i in range(n):
    s = input()
    if s[0] in L:
        S.append(s[0]) #頭文字を入れ込む

import collections
c = collections.Counter(S)#それぞれの出現回数を辞書型で返してくれる
 
ans = 0
import itertools
for i,j,k in itertools.combinations(c.values(), 3):#辞書型の値をリスト化して，それを三つ取るcombinaeion
    ans += i*j*k
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = []
m,a,r,c,h = 0,0,0,0,0

for i in range(n):
  s = input()
  if s[0] is 'M':
    m += 1
  if s[0] is 'A':
    a += 1
  if s[0] is 'R':
    r += 1
  if s[0] is 'C':
    c += 1
  if s[0] is 'H':
    h += 1
    
list = [m,a,r,c,h]

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

Submission status: Accepted

Solution code:
import collections
import itertools
def solve(n, s_list):

    counter = collections.Counter()
    for s in s_list:
        if s[0] in "MARCH":
            counter[s[0]] += 1

    ans = 0
    for i, j, k in itertools.combinations("MARCH",3):
        ans += counter[i]*counter[j]*counter[k]

    return ans


if __name__ == "__main__":
    n = int(input())
    s_list = [input() for i in range(n)]
    print(solve(n, s_list))

Submission status: Accepted

Solution code:

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n=n0()
S=s2(n)

d={"M":0,"A":0,"R":0,"C":0,"H":0}
for s in S:
    if s[0] in "MARCH":
        d[s[0]]+=1

l=list(d.values())

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

Submission status: Accepted

Solution code:
import math

N = int(input())
names = []
for i in range(N):
  names.append(input()[0])
  
conbi = []  
count = 0
ans = 0

while count< 2** 5:
  twodig = bin(count)
  list_td = list(twodig)
  list_tdc = list_td[2:]
  while len(list_tdc) < 5:
    list_tdc.insert(0, "0")
  conbi.append(list_tdc)
  count+= 1
  
conbi2 = list(filter(lambda x: x.count("1") == 3, conbi))

m = names.count("M")
a = names.count("A")
r = names.count("R")
c = names.count("C")
h = names.count("H")

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

for x in conbi2:
  p = x.index("1")
  x[p] = "0"
  q = x.index("1")
  x[q] = "0"
  r = x.index("1")
  x[r] = "0"
  
  ans+= MARCH[p]* MARCH[q]* MARCH[r]

print(int(ans))

Submission status: Accepted

Solution code:
import collections
N = int(input())
C = collections.Counter([input()[0] for _ in range(N)]).most_common()
CC = {c[0]:c[1] for c in C if c[1] != 0 and c[0] in ['M','A','R','C','H']}
count = 0
s = []
for k1,v1 in CC.items():
    for k2,v2 in CC.items():
        for k3,v3 in CC.items():
            key = ''.join(sorted([k1,k2,k3]))
            if k1 != k2 and k2 != k3 and k1 != k3 and key not in s:
                s.append(key)
                count += v1*v2*v3
print(count)

Submission status: Accepted

Solution code:
n = int(input())
L = 'MARCH'
S = []
for i in range(n):
    s = input()
    if s[0] in L:
        S.append(s[0])

import collections
c = collections.Counter(S)

ans = 0
import itertools
for i,j,k in itertools.combinations(c.values(), 3):
    ans += i*j*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)]
counter = Counter([initial for initial in s if initial in 'MARCH'])

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

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
s = [input() for _ in range(n)]
names = [name for name in s if name[0] in 'MARCH']
counter = Counter([name[0] for name in names])

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
import numpy as np

N = INT()
S = [input() for _ in range(N)]
march = ["M", "A", "R", "C", "H"]

cnt = defaultdict(int)

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

#print(march_lis)
ans = 0
#print(cnt)
#print(cnt.keys())
#print(cnt.values())

for x, y, z in combinations(cnt.values(), 3):
	#print(x, y, z)
	ans += x*y*z
print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
import numpy as np

N = INT()
S = [input() for _ in range(N)]
march = ["M", "A", "R", "C", "H"]
march_lis = [0]*5

for s in S:
	if s[0].upper() in march:
		march_lis[march.index(s[0].upper())] += 1

#print(march_lis)
ans = 0
for x, y, z in combinations(march_lis, 3):
	#print(x, y, z)
	ans += x*y*z
print(ans)

Submission status: Accepted

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

for i in range(n):
    S=''
    S=s[i]
    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
print(M*A*R+M*A*C+M*A*H+M*R*C+M*R*H+M*C*H+A*R*C+A*R*H+A*C*H+R*C*H)

Submission status: Accepted

Solution code:
from collections import Counter
from itertools import combinations
n = int(input())
S = [input()[0] for _ in range(n)]
C = Counter(S)
ans = 0
for i, j, k in combinations(['M', 'A', 'R', 'C', 'H'], 3):
    ans += C[i] * C[j] * C[k]
print(ans)

Submission status: Accepted

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

import sys
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n = ii()
    d = defaultdict(int)
    for _ in range(n):
        name = input()
        d[name[0]] += 1
    # print(d)
    buf = []
    for char in "M A R C H".split():
        if char in d:
            buf.append(d[char])
    
    # print(buf)
    if len(buf) < 3:
        print(0)
    else:
        ans = 0
        for pattern in combinations(buf, r=3):
            tmp = 1
            for num in pattern:
                tmp *= num
            ans += tmp
        print(ans)
    


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
S =[]
for n in range(N):
    s = input()
    S.append(s[0])
S=sorted(S)
NAME = sorted(["M","A","R","C","H"])
from itertools import combinations
from collections import Counter
pattern = list(combinations(NAME,3))
LEN = len(S)
cnt=0
Counter_S =Counter(S)
cnt = 0
for p in pattern:
    cnt +=(Counter_S[p[0]] * Counter_S[p[1]] * Counter_S[p[2]])
print(cnt)

Submission status: Accepted

Solution code:
import itertools

n = int(input())

l = [0]*5
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 a,b,c in itertools.combinations(l,3):
    ans += a*b*c

print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
n = int(input())
l = [0]*5
ans = 0

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
    
for a,b,c in combinations(l, 3):
  ans += a* b* c
  
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
head = ["M","A","R","C","H"]
num = [0] * 5
ans = 0

for _ in range(n):
    s = input()[0]
    
    for i in range(5):
        if s == head[i]:
            num[i] += 1
            break
            
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            ans += num[i] * num[j] * num[k]
            
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
import itertools

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

n = [d['m'], d['a'], d['r'], d['c'], d['h']]
ans = 0

a = itertools.combinations(n, 3)
for aa in a:
  t = 1
  for aaa in aa:
    t *= aaa
  ans += t

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
m=[]
a=[]
r=[]
c=[]
h=[]

for i in range(n):
    s=input()
    if s[0]=='M':
        m.append(s)
    elif s[0]=='A':
        a.append(s)
    elif s[0]=='R':
        r.append(s)
    elif s[0]=='C':
        c.append(s)
    elif s[0]=='H':
        h.append(s)

num=[0]*5
num[0]=len(m)
num[1]=len(a)
num[2]=len(r)
num[3]=len(c)
num[4]=len(h)

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

Submission status: Accepted

Solution code:
from itertools import combinations
from collections import Counter
N=int(input())
S=Counter()
for i in range(N):
    s=input()
    S[s[0]]+=1
print(sum([S[a]*S[b]*S[c] for a,b,c in combinations("MARCH",3)]))

Submission status: Accepted

Solution code:
import itertools

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

seq = ('m', 'a', 'r', 'c', 'h')
ret = 0

for item in itertools.combinations(seq, 3):
    tmp = 1
    for val in item:
        tmp *= my_dict[val]
    ret += tmp

print(ret)

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] == "R":
    r += 1
  if s[0] == "A":
    a += 1
  if s[0] == "C":
    c += 1
  if s[0] == "H":
    h += 1
    
from itertools import combinations
march = [m,a,r,c,h]
base = list(combinations(march,3))

result = 0
for b in base:
  result += b[0] * b[1] * b[2]
  
print(result)

Submission status: Accepted

Solution code:
import itertools

n=int(input())

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

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

Submission status: Accepted

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
n = ii()
sm = set()
sa = set()
sr = set()
sc = set()
sh = set()

for _ in range(n):
    tmp = input()
    d = tmp[0]
    if d == 'M':
        sm.add(tmp)
    elif d == 'A':
        sa.add(tmp)
    elif d == 'R':
        sr.add(tmp)
    elif d == 'C':
        sc.add(tmp)
    elif d == 'H':
        sh.add(tmp)

d = {}
d['m'] = len(sm)
d['a'] = len(sa)
d['r'] = len(sr)
d['c'] = len(sc)
d['h'] = len(sh)
A = 'march'
ans = 0
for i in range(1<<5):
    output = []
    for j in range(5):
        if ((i>>j)&1)==1:
            output.append(A[j])
    if len(output) == 3:
        ans += d[output[0]]*d[output[1]]*d[output[2]]
print(ans)

Submission status: Accepted

Solution code:
import itertools

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

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

print(ans)