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 itertools

n = int(input())
name_list = []
march = [0] * 5
name = {'M', 'A', 'R', 'C', 'H'}

for i in range(n):
    s = input()
    if s[0] not in name:
        continue
    else:
        name_list.append(s[0])
        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
if len(set(name_list)) < 3:
    print(0)
    exit()
else:
    ans = 0
    for i in itertools.combinations(set(name_list), 3):
        tmp = 1
        for j in i:
            if j == 'M':
                j = 0
            elif j == 'A':
                j = 1
            elif j == 'R':
                j = 2
            elif j == 'C':
                j = 3
            else:
                j = 4
            tmp *= march[j]
        ans += tmp

    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
    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:
n=int(input())
m=0
a=0
r=0
c=0
h=0
for i in range(n):
  s=input()[0:1]
  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=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
from collections import defaultdict
import sys
input = sys.stdin.readline

N = int(input())
S = [input().rstrip() for _ in range(N)]
cnt = defaultdict(int)
for s in S:
    if s[0] in 'MARCH':
        cnt[s[0]] += 1
ans = 0
for comb in combinations('MARCH', 3):
    ans += cnt[comb[0]] * cnt[comb[1]] * cnt[comb[2]]
print(ans)

Submission status: Accepted

Solution code:
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations
import math
import bisect
from collections import defaultdict, deque
import sys
# input = sys.stdin.readline
# sys.setrecursionlimit(1000000)
# MOD = 10 ** 9 + 7
# INF = float("inf")
import numpy as np


def main():
    n = int(input())
    dict = defaultdict(int)
    for _ in range(n):
        s = input()
        if s[0] in ['M', 'A', 'R', 'C', 'H']:
            dict[s[0]] += 1
    ans = 0
    if len(dict) < 3:
        print(ans)
    else:
        l = [v for v in dict.values() if v != 0]
        for a, b, c in combinations(l, 3):
            ans += a * b * c
        print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import Counter
from operator import mul
from functools import reduce


def cmb(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


n = int(readline())
s = []
check = ['M', 'A', 'R', 'C', 'H']
for i in range(n):
    ss = readline().rstrip().decode()
    if ss[0] in check:
        s.append(ss[0])
counter = list(Counter(s).values())
if len(counter) < 3:
    print(0)
    exit()
ans = cmb(sum(counter), 3)
for v in counter:
    if v >= 2:
        ans -= cmb(v, 2) * (len(s) - v)
        if v >= 3:
            ans -= cmb(v, 3)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict
dic = defaultdict(int)
march = ["M","A","R","C","H"]
n = int(input())
for i in range(n):
    s = input()
    if s[0] in march:
        dic[s[0]] += 1
ans = 0
for i in range(5):
    for j in range(5):
        for k in range(5):
            if i != j and j != k and k != i:
                ans += dic[march[i]]*dic[march[j]]*dic[march[k]]
print(ans//6)

Submission status: Accepted

Solution code:
n,*name=open(0)
n=int(n)
l=[0]*5
for c in name:
	x=c[0]
	if x=="M":
		l[0]+=1
	elif x=="A":
		l[1]+=1
	elif x=="R":
		l[2]+=1
	elif x=="C":
		l[3]+=1
	elif x=="H":
		l[4]+=1
from itertools import combinations
ans=0
for c in combinations(range(5),3):
	ans+=l[c[0]]*l[c[1]]*l[c[2]]
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin,setrecursionlimit
from math import factorial

setrecursionlimit(10 ** 7)

n = int(stdin.readline().rstrip())

li = [stdin.readline().rstrip() for i in range(n)]

name_list = [0]*5

for i in li:
    if i[0] in "MARCH":
        name_list["MARCH".index(i[0])] += 1

point = sum(1 for i in name_list if i != 0)

def combinations_count(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))#組み合わせ

from itertools import combinations
lin = list(combinations(name_list, 3))

count = 0

for i in lin:
    if 0 not in i:
        po = 1
        for j in i:
            po *= j
        count += po
print(count)

Submission status: Accepted

Solution code:
n = int(input())
ls = {'M':0,'A':0,'R':0,'C':0,'H':0}
head = set(["M","A","R","C","H"])

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

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

Submission status: Accepted

Solution code:
from itertools import combinations
N=int(input())
m,a,r,c,h=0,0,0,0,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
res=0
for x in combinations([m,a,r,c,h],3):
    res+=x[0]*x[1]*x[2]
print(res)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
march = ["M", "A", "R", "C", "H"]
num = [0] * 5
for i in range(n):
    s = input()
    if s[0] in march:
        num[march.index(s[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 += num[i] * num[j] * num[k]
print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [input() for i in range(N)]
    from itertools import combinations
    S = {"M": 0, "A": 1, "R": 2, "C": 3, "H": 4}
    ans = 0
    cnt = [0]*5
    for a in A:
        c = a[0]
        if c in S.keys():
            cnt[S[c]] += 1
    for comb in combinations(range(5), 3):
        ans += cnt[comb[0]]*cnt[comb[1]]*cnt[comb[2]]
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
from decimal import Decimal
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
d = defaultdict(int)
s = ['M','A','R','C','H']
for _ in range(n):
    a = input()
    for i,t in enumerate(s):
        if a[0] == t:
            d[i] += 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 permutations


def main():
    n = int(input())
    l = ["M", "A", "R", "C", "H"]
    count = {x: 0 for x in l}
    for _ in range(n):
        s = input()[0]
        if s in count:
            count[s] += 1
    answer = 0
    for p in permutations(l, 3):
        answer += count[p[0]] * count[p[1]] * count[p[2]]
    print(answer // 6)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
ls = []
for i in range(N):
  ls.append(input())

l = [0,0,0,0,0]
for i in range(N):
  if ls[i][0] == "M":
    l[0] += 1
  if ls[i][0] == "A":
    l[1] += 1
  if ls[i][0] == "R":
    l[2] += 1
  if ls[i][0] == "C":
    l[3] += 1
  if ls[i][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):
      ans += l[i]*l[j]*l[k]
print(ans)

Submission status: Accepted

Solution code:
from operator import mul
from functools import reduce


def cmb(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


N = int(input())

cnt = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
chars = set()
for _ in range(N):
    S = input()
    if S[0] in cnt:
        cnt[S[0]] += 1


combs = [
    ['M', 'A', 'R'],
    ['M', 'A', 'C'],
    ['M', 'A', 'H'],
    ['M', 'R', 'C'],
    ['M', 'R', 'H'],
    ['M', 'C', 'H'],
    ['A', 'R', 'C'],
    ['A', 'R', 'H'],
    ['A', 'C', 'H'],
    ['R', 'C', 'H']
]
ans = 0
for c1, c2, c3 in combs:
    ans += cnt[c1] * cnt[c2] * cnt[c3]

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
m,a,r,c,h = 0,0,0,0,0
for i in range(n):
    s = input()
    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
ans = 0
if m*a*r != 0:
    ans += m*a*r
if m*a*c != 0:
    ans += m*a*c
if m*a*h != 0:
    ans += m*a*h
if m*r*c != 0:
    ans += m*r*c
if m*r*h != 0:
    ans += m*r*h
if m*c*h != 0:
    ans += m*c*h
if a*r*c != 0:
    ans += a*r*c
if a*r*h != 0:
    ans += a*r*h
if a*c*h != 0:
    ans += a*c*h
if r*c*h != 0:
    ans += r*c*h
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
m_num = 0
r_num = 0
c_num = 0
a_num = 0
h_num = 0
for i in range(n):
    tmp = input()
    if tmp[0] == 'C':
        c_num += 1
        
    elif tmp[0] == 'R':
        r_num += 1
    
    elif tmp[0] == 'M':
        m_num += 1
        
    elif tmp[0] == 'A':
        a_num += 1
    
    elif tmp[0] == 'H':
        h_num += 1
        
print(m_num*c_num*r_num + a_num*c_num*r_num + h_num*c_num*r_num + m_num*r_num*a_num 
      + m_num*r_num*h_num + m_num*c_num*a_num +  m_num*c_num*h_num + a_num*h_num*m_num + a_num*h_num*r_num + a_num*h_num*c_num )

Submission status: Accepted

Solution code:

import itertools
n = int(input())
li = ['M','A','R','C','H']
d = {}
for l in li:
    d[l] = 0
ans = 0

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

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

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

# https://atcoder.jp/contests/abc089/tasks/abc089_c
# 12:34-12:50 done


def main():
    N = int(input())
    S = [None] * N
    for i in range(N):
        S[i] = input()[0]
    
    march = {s: 0 for s in "MARCH"}

    for s in S:
        if s in "MARCH":
            march[s] += 1
    
    march_filter = []
    for k, v in march.items():
        if v > 0:
            march_filter.append(v)
    
    n = len(march_filter)

    if n < 3:
        return 0

    members = []

    def rec(i, limit, member):
        if i == limit:
            if len(member) == 3:
                members.append(member)
            return None

        member_1 = member[:]
        member_2 = member[:]
        member_1.append(i)

        rec(i+1, n, member_1)
        rec(i+1, n, member_2)

    rec(0, n, [])

    ans = 0
    for member in members:
        tmp = 1
        for m in member:
            tmp *= march_filter[m]
        ans += tmp
    
    return ans


print(main())

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
s = list()
li = [0]*5
for _ in range(n):
    k = input()[0]
    if k=="M":
        li[0]+=1
    elif k=="A":
        li[1]+=1
    elif k=="R":
        li[2]+=1
    elif k=="C":
        li[3]+=1
    elif k=="H":
        li[4]+=1

import itertools
li = itertools.combinations(li,3)
ans = 0
for k in li:
    cnt  =1
    for i in k:
        cnt*=i
    ans += cnt
print(ans)

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = [input() for i in range(N)]

dic = defaultdict(int)
for s in S:
    if s[0] in "MARCH":
        dic[s[0]] += 1

march = list("MARCH")
comb = list(combinations(march, 3))

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

Submission status: Accepted

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

n, *s = [s[0] for s in sys.stdin.read().split()]

def main():
    c = Counter(s)
    res = 0
    for i, j, k in combinations('MARCH', 3):
        res += c[i] * c[j] * c[k]
    print(res)

if __name__ ==  '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import *
N = int(input())
m,a,r,c,h = 0,0,0,0,0
for _ in range(N):
  H =str(input())
  if H[0] == 'M':
    m += 1
  elif H[0] == 'A':
    a += 1
  elif H[0] == 'R':
    r += 1
  elif H[0] == 'C':
    c += 1
  elif H[0] == 'H':
    h += 1

L = [m,a,r,c,h]
L = [i for i in L if i > 0]

if len(L) < 3:
  print(0)
  exit()
else:
  ans = 0
  for l in combinations(L,3):
    a,b,c = l
    ans += (a*b*c)
    
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations as cmb

n=int(input())

idx=[0,0,0,0,0]

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

ans=0
for a,b,c in cmb(idx,3):
    ans+=a*b*c

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
M = 0
A = 0
R = 0
C = 0
H = 0
for _ in range(n):
    x = input()[0]
    if x == "M":
        M += 1
    elif x == "A":
        A += 1
    elif x == "R":
        R += 1
    elif x == "C":
        C += 1
    elif x == "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:
import sys
import itertools
sys.setrecursionlimit(10000)
def resolve():
    N = int(input())
    d = {
        "M": 0,
        "A": 0,
        "R": 0,
        "C": 0,
        "H": 0
    }
    for i in range(N):
        name = input()
        if name[0] in d:
            d[name[0]] += 1
    
    import itertools
    combs = list(itertools.combinations(d.keys(), 3))

    cnt = 0
    for comb in combs:
        cnt += d[comb[0]] * d[comb[1]] * d[comb[2]]
    
    print(cnt)

if '__main__' == __name__:
    resolve()

Submission status: Accepted

Solution code:
from itertools import *
N = int(input())
march = []
for _ in range(N):
  H =str(input())
  if H[0] == 'M' or H[0] == 'A' or H[0] == 'R' or H[0] == 'C' or H[0] == 'H':
    march.append(H[0])
march = ''.join(march)
m = march.count('M')
a = march.count('A')
r = march.count('R')
c = march.count('C')
h = march.count('H')
l = [m,a,r,c,h]
L = []
for i in range(len(l)):
  if l[i] > 0:
    L.append(l[i])
if len(L) < 3:
  print(0)
  exit()
else:
  ans = 0
  for l in combinations(L,3):
    a,b,c = l
    ans += (a*b*c)
    
print(ans)

Submission status: Accepted

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

a=["M","A","R","C","H"]
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:
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N = int(input())
S = [input().rstrip() for _ in range(N)]

from collections import defaultdict
d = defaultdict(int)

for s in S:
    key = s[0]
    d[key] += 1

from itertools import combinations
c = combinations("MARCH",3)
ans = 0
for x,y,z in c:
    ans += d[x]*d[y]*d[z]

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
m=[]
a=[]
r=[]
c=[]
h=[]
for i in range(n):
    k=input()
    if k[0]=="M":
        m.append(k)
    elif k[0]=="A":
        a.append(k)
    elif k[0]=="R":
        r.append(k)
    elif k[0]=="C":
        c.append(k)
    elif k[0]=="H":
        h.append(k)
s=0
s=s+len(m)*len(a)*len(r)+len(m)*len(a)*len(c)+len(m)*len(a)*len(h)+len(m)*len(r)*len(c)+len(m)*len(r)*len(h)+len(m)*len(c)*len(h)+len(a)*len(r)*len(c)+len(a)*len(r)*len(h)+len(a)*len(c)*len(h)+len(r)*len(c)*len(h)
print(s)

Submission status: Accepted

Solution code:
from itertools import combinations
from collections import Counter
s = 0
n = int(input())
l = Counter(list(input()[0] for _ in range(n)))
for a,b,c in combinations("MARCH",3):
  s += l[a]*l[b]*l[c]
print(s)

Submission status: Accepted

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


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


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


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


from itertools import combinations
base = list(combinations(arr,3))
ans = 0
for c in base:
    ans += c[0] * c[1] * c[2]

print(ans)

Submission status: Accepted

Solution code:
import itertools

N=int(input())
m = [0] * 5
for i in range(N):
  S = input()
  if S[0] == 'M':
    m[0] += 1
  elif S[0] == 'A':
    m[1] += 1
  elif S[0] == 'R':
    m[2] += 1
  elif S[0] == 'C':
    m[3] += 1
  elif S[0] == 'H':
    m[4] += 1
ans = 0
for (a,b,c) in itertools.combinations([0,1,2,3,4], 3):
  ans += m[a] * m[b] * m[c]
print(ans)

Submission status: Accepted

Solution code:
from itertools import permutations
from collections import defaultdict
n = int(input())
d = defaultdict(int)
for _ in range(n):
    name = input()
    d[name[0]] += 1

prefix = list('MARCH')
path = []
for i in range(5):
    for j in range(i + 1, 5):
        for k in range(j + 1, 5):
            path.append((prefix[i], prefix[j], prefix[k]))
ans = 0
for a, b, c in path:
    ans += d.get(a, 0) * d.get(b, 0) * d.get(c, 0)
print(ans)

Submission status: Accepted

Solution code:
url = "https://atcoder.jp/contests/abc089/tasks/abc089_c"
import itertools
import math

def main():
    mojiretu = ('M', 'A', 'R', 'C', 'H')
    dic = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
    t = input()
    count = 0
    for i in range(int(t)):
        tmp = input()
        if tmp[0] in mojiretu:
            dic[tmp[0]] += 1
    for l in itertools.combinations(mojiretu, 3):
        count += dic[l[0]] * dic[l[1]] * dic[l[2]]
    print(count)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
d = {}
s = "MARCH"
for c in s:
    d[c] = 0
for _ in range(N):
    c = input().strip()[0]
    if c in d:
        d[c] += 1

r = 0
for i in range(5):
    a = s[i]
    for j in range(i+1, 5):
        b = s[j]
        for k in range(j+1, 5):
            c = s[k]
            r += d[a]*d[b]*d[c]
print(r)

Submission status: Accepted

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

p = [0, 0, 0, 0, 0, 0, 1, 1, 1, 2]
q = [1, 1, 1, 2, 2, 3, 2, 2, 3, 3]
r = [2, 3, 4, 3, 4, 4, 3, 4, 4, 4]

d = [0] * 5

for i in range(n):
    if s[i][0] == "M":
        d[0] += 1
    elif s[i][0] == "A":
        d[1] += 1
    elif s[i][0] == "R":
        d[2] += 1
    elif s[i][0] == "C":
        d[3] += 1
    elif s[i][0] == "H":
        d[4] += 1
        
ans = 0
for i in range(0,10):
    ans += (d[p[i]] * d[q[i]] * d[r[i]])
print(ans)

Submission status: Accepted

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

l=[i[0] for i in s if i[0]=="M" or i[0]=="A" or i[0]=="R" or i[0]=="C" or i[0]=="H"]
c=collections.Counter(l)
v=list(c.values())
vn=len(v)

if vn<3:print(0)
if vn==3:print(v[0]*v[1]*v[2])
if vn==4:print(v[0]*v[1]*v[2]+v[0]*v[1]*v[3]+v[0]*v[2]*v[3]+v[1]*v[2]*v[3])
if vn==5:print(v[0]*v[1]*v[2]+v[0]*v[1]*v[3]+v[0]*v[1]*v[4]+v[0]*v[2]*v[3]+v[0]*v[2]*v[4]+v[0]*v[3]*v[4]+v[1]*v[2]*v[3]+v[1]*v[2]*v[4]+v[1]*v[3]*v[4]+v[2]*v[3]*v[4])

Submission status: Accepted

Solution code:
import itertools
from collections import Counter

n = int(input())
c = Counter()
for i in range(n):
    tmp = input().strip()
    if tmp[0] in ['M', 'A', 'R', 'C', 'H']:
        c[tmp[0]] += 1

result = 0
for v in itertools.permutations(c.values(), 3):
    result += v[0] * v[1] * v[2]

print(result // 6)

Submission status: Accepted

Solution code:
from itertools import combinations
n = int(input())
w = [0] * 5
march = 'MARCH'
for i in range(n):
  s = input()[0]
  if s in march:
    w[march.index(s)] += 1
print(sum(map(lambda a:a[0]*a[1]*a[2], combinations(w, 3))))

Submission status: Accepted

Solution code:
from itertools import combinations as c
n=int(input())
s=[input() for _ in range(n)]
march=[0]*5
for i in range(n):
    if s[i][0]=='M':march[0]+=1
    elif s[i][0]=='A':march[1]+=1
    elif s[i][0]=='R':march[2]+=1
    elif s[i][0]=='C':march[3]+=1
    elif s[i][0]=='H':march[4]+=1
print(sum(i*j*k for i, j, k in c(march, 3)))

Submission status: Accepted

Solution code:
n = int(input())
list_N = [input() for _ in range(n)]
list_N = list(set(list_N))
cnt = [0 for _ in range(5)]

for i in range(len(list_N)):
    l = list(list_N[i])
    if l[0] in "M":
        cnt[0] += 1
    elif l[0] in "A":
        cnt[1] += 1
    elif l[0] in "R":
        cnt[2] += 1
    elif l[0] in "C":
        cnt[3] += 1
    elif l[0] in "H":
        cnt[4] += 1

ans = 0
l  = []
if cnt.count(0) == 2:
    for num in cnt:
        if num != 0:
            l.append(num)
    ans += l[0]*l[1]*l[2]
if cnt.count(0) == 1:
    for num in cnt:
        if num != 0:
            l.append(num)
    ans += l[0] * l[1] * l[2]
    ans += l[0] * l[1] * l[3]
    ans += l[0] * l[2] * l[3]
    ans += l[2] * l[1] * l[3]
if cnt.count(0) == 0:
    l = cnt
    ans += l[0] * l[1] * l[2]
    ans += l[0] * l[1] * l[3]
    ans += l[0] * l[1] * l[4]
    ans += l[0] * l[2] * l[3]
    ans += l[0] * l[2] * l[4]
    ans += l[0] * l[3] * l[4]
    ans += l[1] * l[2] * l[3]
    ans += l[1] * l[2] * l[4]
    ans += l[1] * l[3] * l[4]
    ans += l[2] * l[3] * l[4]

if cnt.count(0) > 2:
    print(0)
else:
    print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
march = "MARCH"
n = int(input())
dic = defaultdict(int)
for i in range(n):
    s = input()
    for j in range(5):
        if s[0] == march[j]:
            dic[march[j]] += 1
            break
        

ans = 0
for i in range(5):
    if dic[march[i]] >= 1:
        for j in range(i + 1, 5):
            if dic[march[j]] >= 1:
                for k in range(j + 1, 5):
                    if dic[march[k]] >= 1:
                        ans += dic[march[i]] * dic[march[j]] * dic[march[k]]


print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = [input()[0] for i in range(n)]
work = [0, 0, 0, 0, 0]
for el in s:
    if el == "M":
        work[0] += 1
    elif el == "A":
        work[1] += 1
    elif el == "R":
        work[2] += 1
    elif el == "C":
        work[3] += 1
    elif el == "H":
        work[4] += 1
temp = sum(work)
result = temp*(temp-1)*(temp-2)//6
for el in work:
    result -= el*(el-1)*(temp-el)//2
    result -= el*(el-1)*(el-2)//6
print(result)

Submission status: Accepted

Solution code:
n = int(input()) # 入力が1つ
# map(int, input().split()) # 入力が複数
# [int(i) for i in input().split()] # 配列で数字

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

initial = ['M', 'A', 'R', 'C', 'H']
combi = []
for i in range(len(initial)):
    for j in range(i + 1, len(initial)):
        for k in range(j + 1, len(initial)):
            combi.append((initial[i], initial[j], initial[k]))

ans = 0
for a, b, c in combi:
    x, y, z = d.get(a), d.get(b), d.get(c)
    ans += x * y * z
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import itertools
n = int(input())
d = {}
for i in range(n):
  s = str(input())[0]
  if (s == 'M') or (s == 'A') or (s == 'R') or (s == 'C') or (s == 'H') :
    if s in d:
      d[s] += 1
    else:
      d[s] = 1
if len(d) <= 2:
  print(0)
else:
  d = sorted(d.values())
  ans = 0
  for team in itertools.combinations(d, 3):
    cnt = 1
    for i in team:
      cnt *= i
    ans += cnt
  print(ans)

Submission status: Accepted

Solution code:
import itertools
n = int(input())
d = {}
for i in range(n):
  s = str(input())[0]
  if (s == 'M') or (s == 'A') or (s == 'R') or (s == 'C') or (s == 'H') :
    if s in d:
      d[s] += 1
    else:
      d[s] = 1
if len(d) <= 2:
  print(0)
else:
  d = sorted(d.values())
  if len(d) == 3:
    ans = 1
    for i in d:
      ans *= i
    print(ans)
  else:
    ans = 0
    for team in itertools.combinations(d, 3):
      cnt = 1
      for i in team:
        cnt *= i
      ans += cnt
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
str_cnt = {'M' : 0, 'A' : 0, 'R' : 0, 'C' : 0, 'H' : 0}
for i in range(N):
    s = input()
    if s[0] in 'MARCH':
        str_cnt[s[0]] += 1
import itertools
ans = 0
for i in itertools.combinations(['M', 'A', 'R', 'C', 'H'], 3):
    ans += str_cnt[i[0]] * str_cnt[i[1]] * str_cnt[i[2]]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = [[] for i in range(N)]
march = [[] for i in range(5)]
for i in range(N):
    S[i] = input()
for i in range(N):
    if S[i][0] == "M":
        march[0].append(S[i])
    elif S[i][0] == "A":
        march[1].append(S[i])
    elif S[i][0] == "R":
        march[2].append(S[i])
    elif S[i][0] == "C":
        march[3].append(S[i])
    elif S[i][0] == "H":
        march[4].append(S[i])
        
c = [0]*5
for i in range(5):
    c[i] = len(march[i])

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:
import itertools
N = int(input())
S = [0]*5
for i in range(N):
    a = input()
    if a[0] == 'M':
        S[0] += 1
    if a[0] == 'A':
        S[1] += 1
    if a[0] == 'R':
        S[2] += 1
    if a[0] == 'C':
        S[3] += 1
    if a[0] == 'H':
        S[4] += 1
S.sort(reverse=True)
if S[2] == 0:
    print(0)
elif S[3] == 0:
    print(S[0]*S[1]*S[2])
elif S[4] == 0:
    print(S[0]*S[1]*S[2]+S[3]*S[1]*S[2]+S[0]*S[1]*S[3]+S[0]*S[2]*S[3])
else:
    ans = 0
    for x,y,z in itertools.combinations([0,1,2,3,4], 3):
        ans += S[x]*S[y]*S[z]
    print(ans)

Submission status: Accepted

Solution code:
from itertools import product

n = int(input())
s = list(input() for _ in range(n))

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

res = 0
for pattern in product([0, 1], repeat=5):
    if sum(pattern) == 3:
        p = 1
        for i, j in enumerate(pattern):
            if j == 1:
                p *= name[i]
        res += p
print(res)

Submission status: Accepted

Solution code:
import numpy as np
from functools import reduce
from operator import add,sub,mul,truediv
from fractions import gcd
import itertools

n = int(input())


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

x = ['m','a','r','c','h']

cnt = [0,0,0,0,0]
for i in range(n):
    s = str(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


ans = 0
for v in itertools.combinations(cnt,3):
    t = v[0] 
    for i in range(1,3):
        t*=v[i]

    ans+=t

print(ans)