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: Time Limit Exceeded

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

t = [s_i[0] for s_i in s if s_i[0] in "MARCH"]
count = 0
for t_i in t:
	for t_j in t:
		for t_k in t:
			if len(set((t_i, t_j, t_k))) == 3:
				count += 1

print(count//6)

Submission status: Time Limit Exceeded

Solution code:
from math import factorial
import itertools
N = int(input())
S = set([input() for i in range(N)])
march = set("MARCH")
S2 = [i for i in S if i[0] in march]

result = 0
for i in itertools.combinations(S2,3):
    if not (i[0][0]==i[1][0] or i[1][0]==i[2][0] or i[0][0]==i[2][0]):
        result += 1

print(result)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())

arr = []
for i in range(n):
	arr.append(raw_input())

count = 0

for combs in list(itertools.combinations(range(n),3)):
	rest = 'MARCH'
	c = 0
	for i in combs:
		if arr[i][0] in rest:
			rest = rest.replace(arr[i][0],'')
			c += 1
		else :
			break

	if c == 3:
		count += 1

print count

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

import itertools

N = int(input())
name_list = []
for i in range(N):
    name_str = input()
    # 1文字目がMARCHの名前だけリストに詰める
    if name_str[0] == "M" or name_str[0] == "A" or name_str[0] == "R" or name_str[0] == "C" or name_str[0] == "H":
        name_list.append(name_str)
# 3人を選ぶ組み合わせ
cmb_list = list(itertools.combinations(name_list, 3))

ans = 0
for names in cmb_list:
    # 各人の名前のイニシャルを取得
    init1 = names[0][0]
    init2 = names[1][0]
    init3 = names[2][0]
    # 重複がなければ条件を満たす
    if init1 != init2 and init1 != init3 and init2 != init3:
        ans += 1
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import re
import itertools

n = int(input())
ls = [input() for _ in range(n)]
new_ls = []
ans = 0

for name in ls:
    if re.match(r"[MARCH]", name):
        new_ls.append(name[:1])

comb_ls = list(itertools.combinations(new_ls, 3))


if new_ls:
    for comb in comb_ls:
        s = set(comb)
        if len(s) == 3:
            ans += 1
    print(ans)
else:
    print(0)
    quit()

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
names = []
initial = ['M', 'A', 'R', 'C', 'H']
ans = 0
for i in range(n):
  name = input()
  if name[0] in initial:
    names.append(name)

combo = list(itertools.combinations(names, 3))

for i in combo:
  if not i[0][0] == i[1][0] and not i[0][0] == i[2][0] and not i[1][0] == i[2][0]:
    ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import os,sys
import itertools

if __name__ == "__main__":
    n = int(raw_input())
    t = []
    for i in range(n):
        t.append(raw_input())
    c = list(itertools.combinations(t,3))
    #print(c)
    result = 0
    for comb in c:
        march_list = {}
        for k in "MARCH":
            march_list[k] = 0
        for i in range(3):
            try:
                march_list[comb[i][0]] += 1
            except:
                pass
                
            
        c_sum = 0
        is_ok = True
        for k,v in march_list.items():
            c_sum += v
            if v >= 2:
                is_ok = False
        if c_sum != 3:
            is_ok = False
        if is_ok:
            result += 1
    print(result)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import collections

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

a = []
for i in list(itertools.combinations(seq,3)):
    temp = [i[0][0],i[1][0],i[2][0]]
    countdict = collections.Counter(temp)
    if len(countdict) == 3:
        a.append(i)

print(len(a))

Submission status: Time Limit Exceeded

Solution code:
import itertools
letters = ['M','A','R','C','H']
N = int(input())
a = []
com_s = []

for i in range(N):
    x = input()
    if x[0] in letters:
        a.append(x)

coms = list(itertools.combinations(a,3))
for com in coms:
    if com[0][0] != com[1][0] and com[1][0] != com[2][0] and com[2][0] != com[0][0]:
        com_s.append(com)

print(len(com_s))

Submission status: Time Limit Exceeded

Solution code:
import itertools
letters = ['M','A','R','C','H']
N = int(input())
a = []
com_s = []

for i in range(N):
    x = input()
    if x[0] in letters:
        a.append(x)

coms = list(itertools.combinations(a,3))
for com in coms:
    if com[0][0] != com[1][0] and com[1][0] != com[2][0] and com[2][0] != com[0][0]:
        com_s.append(com)

print(len(com_s))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import itertools

N = int(input())
a = [input() for i in range(N)]

march = {'M','A','R','C','H'}

b = [item for item in a if item[:1] in march]

c = list(itertools.combinations(b, 3))

d = []

for item in c:
	initial_list = [name[:1] for name in item]
	initial_set = set(initial_list)
	if len(initial_list) == len(initial_set):
		d.append(item)

print(len(d))

Submission status: Time Limit Exceeded

Solution code:
#coding=utf-8
from itertools import combinations
from collections import Counter

def solve(n, ss):
    filtered_ss = list(filter(lambda x: x in "MARCH", ss))

    gc = Counter(filtered_ss)
    if len(gc) < 3:
        return 0

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

    return ans

def main():
    n = int(input())
    ss = []
    for x in range(n):
        ss = ss + [input()[0]]
    print(solve(n, ss))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#coding=utf-8
from itertools import combinations
from collections import Counter

def solve(n, ss):
    filtered_ss = list(filter(lambda x: x in "MARCH", map(lambda x:x[0], ss)))

    gc = Counter(filtered_ss)
    if len(gc) < 3:
        return 0

    ans = 0
    for permutation in combinations("MARCH", 3):
        if permutation[0] in gc.keys() and permutation[1] in gc.keys() and permutation[2] in gc.keys():
            tmp = (gc[permutation[0]] * gc[permutation[1]] * gc[permutation[2]])
            ans = ans + tmp

    return ans

def main():
    n = int(input())
    ss = []
    for x in range(n):
        ss = ss + [input()]
    print(solve(n, ss))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#coding=utf-8
import itertools

#[a] -> {a: Int} 
def group_count(l):
    group = list(set(l))
    dic = {}
    for x in group:
        dic[x] = l.count(x)
    return dic

def solve(n, ss):
    filtered_ss = list(filter(lambda x: x in "MARCH", map(lambda x:x[0], ss)))

    gc = group_count(filtered_ss)
    if len(gc) < 3:
        return 0

    ans = 0
    for permutation in itertools.combinations("MARCH", 3):
        if permutation[0] in gc.keys() and permutation[1] in gc.keys() and permutation[2] in gc.keys():
            tmp = (gc[permutation[0]] * gc[permutation[1]] * gc[permutation[2]])
            ans = ans + tmp

    return ans

def main():
    n = int(input())
    ss = []
    for x in range(n):
        ss = ss + [input()]
    print(solve(n, ss))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())

members = []
for i in range(N):
    member = input()
    members.append(member)


members_march = [member for member in members if member[0] in ['M','A','R','C','H'] ]

march_conb = itertools.combinations(members_march,3)

print(len([conb for conb in march_conb if len(set([member[0] for member in conb])) == 3]))

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())

members = []
for i in range(N):
    member = input()
    members.append(member)


members_march = [member for member in members if member[0] in ['M','A','R','C','H'] ]

march_conb = itertools.combinations(members_march,3)

result = []
for conb in march_conb:
    if len(set([member[0] for member in conb])) == 3:
        result.append(conb)

print(len(result))

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input().strip())
    S = []
    D1 = {}
    D2 = {}
    for _ in range(N):
        in_s = input().strip()[0]
        if in_s in ['M','A','R','C','H']:
            S.append(in_s)  
    S.sort()
    count = 0
    for i in range(len(S)):
        D1 = {}
        D2 = {}
        D1[S[i]]=True
        for j in range(i+1, len(S)):
            D2 = {}
            if S[j] in D1: continue
            D2[S[j]]=True
            for k in range(j+1, len(S)):
                if S[k] in D2: continue
                count += 1
    return count
if __name__ == '__main__':
    print(main())

Submission status: Time Limit Exceeded

Solution code:
import itertools
def main():
    N = int(input().strip())
    S = []
    for _ in range(N):
        in_s = (input().strip())[0]
        if in_s in ['M','A','R','C','H']:
            S.append(in_s)

    if not S:
        return 0

    pat = itertools.combinations(S, 3);
    
    count = 0
    for x in pat:
        if len(x) == len(set(x)):
            count += 1
    return count
    
if __name__ == '__main__':
    print(main())

Submission status: Time Limit Exceeded

Solution code:
import itertools
def main():
    N = int(input().strip())
    S = [input().strip() for _ in range(N)]
    MARCH_S = [x[0] for x in S if x[0] in ['M','A','R','C','H']]
    if not MARCH_S:
        return 0

    pat = list(itertools.combinations(MARCH_S, 3));
    pat_len = len(pat)
    
    for x in ['M','A','R','C','H']:
        pat_len -= len([p for p in pat if p.count(x) > 1])

    return pat_len
    
if __name__ == '__main__':
    print(main())

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lis = []
for i in range(n):
    lis.append(input())
count = 0

lis2 = []

for i in range(n):
    if lis[i][0:1] in 'MARCH':
        lis2.append(lis[i])
        
for i in range(len(lis2)-2):
    for j in range(i+1, len(lis2)-1):
        for k in range(j+1, len(lis2)):
            if lis2[i][0:1] != lis2[j][0:1] and lis2[j][0:1] != lis2[k][0:1] \
            and lis2[k][0:1] != lis2[i][0:1]:
                count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S={input() for i in range(N)}
count=0
for x in S:
    for y in S-{x}:
        for z in S-{x,y}:
            A={x[0],y[0],z[0]}
            if len(A)==3 and A<={'M','A','R','C','H'}:
                count+=1
print(int(count/6))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import itertools


def filter_name(n):
    return n == "M" or n == "A" or n == "R" or n == "C" or n == "H"


def filter_ok(l):
    if l[0][0:1] == l[1][0:1] or l[0][0:1] == l[2][0:1] or l[1][0:1] == l[2][0:1]:
        return False
    return True


n = input()
a = []
for i in range(n):
    b = raw_input()
    if filter_name(b[0:1]):
        a.append(b)

a = list(itertools.combinations(a, 3))
a = filter(filter_ok, a)
print len(a)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import itertools


def filter_name(n):
    return n == "M" or n == "A" or n == "R" or n == "C" or n == "H"


def filter_ok(l):
    dic = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
    for i in l:
        dic[i[0:1]] += 1
        if dic[i[0:1]] >= 2:
            return False
    return True


n = input()
a = []
for i in range(n):
    b = raw_input()
    if filter_name(b[0:1]):
        a.append(b)

a = list(itertools.combinations(a, 3))
a = filter(filter_ok, a)
print len(a)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import itertools


def filter_name(n):
    return n == "M" or n == "A" or n == "R" or n == "C" or n == "H"


def filter_ok(l):
    dic = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
    for i in l:
        dic[i[0:1]] += 1
        if dic[i[0:1]] >= 2:
            return False
    return True


n = input()
a = []
for i in range(n):
    b = raw_input()
    if filter_name(b[0:1]):
        a.append(b)

c = list(itertools.combinations(a, 3))
a = filter(filter_ok, c)
print len(a)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import itertools


def filter_name(n):
    return n == "M" or n == "A" or n == "R" or n == "C" or n == "H"


def filter_ok(l):
    dic = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
    for i in l:
        dic[i[0:1]] += 1
    for num in dic.values():
        if num >= 2:
            return False
    return True


n = input()
a = []
for i in range(n):
    b = raw_input()
    if filter_name(b[0:1]):
        a.append(b)

c = list(itertools.combinations(a, 3))
a = filter(filter_ok, c)
print len(a)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import itertools


def filter_name(n):
    return n.startswith("M") or n.startswith("A") or n.startswith("R") or n.startswith("C") or n.startswith("H")


def filter_ok(l):
    dic = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
    for i in l:
        dic[i[0:1]] += 1
    for num in dic.values():
        if num >= 2:
            return False
    return True


n = input()
a = []
for i in range(n):
    b = raw_input()
    if filter_name(b):
        a.append(b)

c = list(itertools.combinations(a, 3))
a = filter(filter_ok, c)
print len(a)

Submission status: Time Limit Exceeded

Solution code:
def convert(input_lis):
    return [i[0] for i in input_lis]


lis = [i for i in [input() for i in range(int(input()))]
       if i[0] == 'M' or i[0] == 'A'or i[0] == 'R'or i[0] == 'C'or i[0] == 'H']
import itertools
ans_list = []
for i in [sorted(i) for i in [i for i in filter(lambda x: len(list(set(convert(x)))) == len(convert(x)),
                                                itertools.combinations(lis, 3))]]:
    if sorted(i) not in ans_list:
        ans_list.append(i)

print(len(ans_list))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import itertools


def filter_name(n):
    return n.startswith("M") or n.startswith("A") or n.startswith("R") or n.startswith("C") or n.startswith("H")


def filter_ok(l):
    dic = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
    for i in l:
        dic[i[0:1]] += 1
    for num in dic.values():
        if num >= 2:
            return False
    return True


n = input()
a = []
for i in range(n):
    b = raw_input()
    if filter_name(b):
        a.append(b)

r = filter(filter_name, a)
c = list(itertools.combinations(r, 3))
r = filter(filter_ok, c)
print len(r)

Submission status: Time Limit Exceeded

Solution code:
N = int(raw_input())
lis = []

for i in range(N):
    te = raw_input()
    if te[0] == "M" or te[0] == "A" or te[0] == "R" or te[0] == "C" or te[0] == "H":
        lis.append(te)

count = 0
for i in range(len(lis)):
    if len(lis) >= 3:
        a = lis[i][0]
        for j in range(len(lis)):
            if j<=i:
                continue
            if lis[j][0] != a and len(lis)>=3:
                b = lis[j][0]
                for k in range(len(lis)):
                    if len(lis)<3:
                        break
                    if k<=i or k<=j:
                        continue
                    if lis[k][0] != a and lis[k][0] != b:
                        c = lis[k][0]
                        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import itertools


def filter_name(n):
    return n.startswith("M") or n.startswith("A") or n.startswith("R") or n.startswith("C") or n.startswith("H")


def filter_ok(l):
    dic = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
    for i in l:
        dic[i[0:1]] += 1
    for num in dic.values():
        if num >= 2:
            return False
    return True


n = input()
a = []
for i in range(n):
    a.append(raw_input())

r = filter(filter_name, a)
c = list(itertools.combinations(r, 3))
r = filter(filter_ok, c)
print len(r)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S_row = [input() for _ in range(N)]

S = list(filter(lambda n: n[0] in "MARCH", S_row))

ans = 0
for i, s1 in enumerate(S):
    for j, s2 in enumerate(S[i+1:]):
        if s2[0] != s1[0]:
            for s3 in S[i+j+1:]:
                if s3[0] != s1[0] and s3[0] != s2[0]:
                    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())

array = []
dict = {}
dict["M"] = dict["A"] = dict["R"] = dict["C"] = dict["H"] = 0
for i in range(n):
    tmp = input()
    dict[tmp[0]] = dict.get(tmp[0], 0) + 1

if dict["M"] == 0 and dict["A"] == 0 and dict["R"] == 0 and dict["C"] == 0 and dict["H"] == 0:
    print(0)
else:
    tmp = []
    for i in [dict["M"], dict["A"], dict["R"], dict["C"], dict["H"]]:
        if i != 0:
            tmp.append(i)
    judge = 0
    for l in tmp:
        if l != 0 and l != 1:
            tmp2 = list(tmp)
            tmp2.remove(l)
            judge += (l-1)*len(tmp2)

    res = len(list(itertools.combinations(range(sum(tmp)), 3))) - judge

    print(res)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [input() for _ in range(N)]
ans = 0
for a in range(N):
    fuga = ['M', 'A', 'R', 'C', 'H']
    ch = S[a][0]
    if ch not in fuga:
        continue
    fuga.remove(ch)
    for b in range(a+1, N):
        ch = S[b][0]
        temp = fuga[:]
        if ch not in temp:
            continue
        temp.remove(ch)
        ans += sum(1 * (S[c][0] in temp) for c in range(b+1, N))
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
march = ["M", "A", "R", "C", "H"]
d = {"M":0, "A":0, "R":0, "C":0, "H":0}


for i in range(n):
    s = input()
    if s[0] in march:
        d[s[0]] = d.get(s[0], 0)+1
ans = 0
li = []
for i in d:
    for j in d:
        for k in d:
            if i!=j and j!=k and k!=i and not set([i,j,k]) in li:
                li.append(set([i,j,k]))
                ans += d[i]*d[j]*d[k]
print(ans)

Submission status: Accepted

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

c = (
    s.count("M"),
    s.count("A"),
    s.count("R"),
    s.count("C"),
    s.count("H"),
)
from itertools import combinations
a = sum(x*y*z for x, y, z in combinations(c, 3))
print(a, flush=True)

Submission status: Accepted

Solution code:
import itertools
n = int(input())  # nは入力回数
#num_list = [int(input()) for _ in range(n)]
ans = 0

set_m = set()
set_a = set()
set_r = set()
set_c = set()
set_h = set()

for i in range(n):
    s = input()
    if s[0] == "M":
        set_m.add(s)
    if s[0] == "A":
        set_a.add(s)
    if s[0] == "R":
        set_r.add(s)
    if s[0] == "C":
        set_c.add(s)
    if s[0] == "H":
        set_h.add(s)

l_m = len(set_m)
l_a = len(set_a)
l_r = len(set_r)
l_c = len(set_c)
l_h = len(set_h)

l_l = [l_m,l_a,l_r,l_c,l_h]

comb_list = list(itertools.combinations(l_l,3))

for i in range(len(comb_list)):
    ans += comb_list[i][0]*comb_list[i][1]*comb_list[i][2]

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
l=[0,0,0,0,0]
for _ 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 i in range(0,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:
n=int(input())
l=[0,0,0,0,0]
for _ 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

for i in l:
    if i==0:l.remove(i)
total=len(l)
if total<3:ans=0
else:
    ans=0
    for i in range(0,total-2):
        for j in range(i+1,total-1):
            for k in range(j+1,total):
                ans+=l[i]*l[j]*l[k]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = [0] * 5
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

res = 0
res += a[0] * a[1] * a[2]
res += a[0] * a[1] * a[3]
res += a[0] * a[1] * a[4]
res += a[0] * a[2] * a[3]
res += a[0] * a[2] * a[4]
res += a[0] * a[3] * a[4]
res += a[1] * a[2] * a[3]
res += a[1] * a[2] * a[4]
res += a[1] * a[3] * a[4]
res += a[2] * a[3] * a[4]
print(res)

Submission status: Accepted

Solution code:
N = int(input())

dic = {"M" : 0, "A": 0, "R": 0, "C": 0, "H": 0}
for _ in range(N):
  s = input()
  if s[0] in dic:
    dic[s[0]] += 1
      
char = ["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 += dic[char[i]] * dic[char[j]] * dic[char[k]]
      
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

N = int(input())
count = [0] * 5
for i in range(N):
    tmp = input()
    if tmp[0] == "M":
        count[0] += 1
    if tmp[0] == "A":
        count[1] += 1
    if tmp[0] == "R":
        count[2] += 1
    if tmp[0] == "C":
        count[3] += 1
    if tmp[0] == "H":
        count[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 += count[i]*count[j]*count[k]

print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations

n = int(input())
S = [input() for _ in range(n)]
initials = ('M', 'A', 'R', 'C', 'H')
d = {}
for s in S:
  if s[0] in initials:
    d[s[0]] = d.get(s[0], 0) + 1

print(sum(d[x] * d[y] * d[z] for x, y, z in combinations(d.keys(), 3)))

Submission status: Accepted

Solution code:
import math
"""
int(input())
map(int, input().split())
list(map(int, input().split()))
input()
input().split()
"""

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

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 23 14:49:47 2020

@author: liang
"""

"""
【組み合わせ生成】
    itertools.combinations(iterable, r)
【総積】
    numpy.prod(iterable)
"""
from itertools import combinations
import numpy as np

N = int(input())
d = [0]*5
for i in range(N):
    s = input()
    if s[0] == "M":
        d[0] += 1
    if s[0] == "A":
        d[1] += 1
    if s[0] == "R":
        d[2] += 1
    if s[0] == "C":
        d[3] += 1
    if s[0] == "H":
        d[4] += 1
    
ans = 0
for lis in combinations(d,3):
    ans += np.prod(lis)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = [input() for i in range(N)]

MARCH_dic = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
MARCH_list = ['M', 'A', 'R', 'C', 'H']

for i in range(N):
  if S[i][0] in MARCH_list:
    MARCH_dic[S[i][0]] += 1
    
p_01 = MARCH_dic['M'] * MARCH_dic['A'] * MARCH_dic['R']
p_02 = MARCH_dic['M'] * MARCH_dic['A'] * MARCH_dic['C']
p_03 = MARCH_dic['M'] * MARCH_dic['A'] * MARCH_dic['H']
p_04 = MARCH_dic['M'] * MARCH_dic['R'] * MARCH_dic['C']
p_05 = MARCH_dic['M'] * MARCH_dic['R'] * MARCH_dic['H']
p_06 = MARCH_dic['M'] * MARCH_dic['C'] * MARCH_dic['H']
p_07 = MARCH_dic['A'] * MARCH_dic['R'] * MARCH_dic['C']
p_08 = MARCH_dic['A'] * MARCH_dic['R'] * MARCH_dic['H']
p_09 = MARCH_dic['A'] * MARCH_dic['C'] * MARCH_dic['H']
p_10 = MARCH_dic['R'] * MARCH_dic['C'] * MARCH_dic['H']

ans = 0

for i in range(10):
  ans += eval(f"p_{str(i+1).zfill(2)}")
  
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

for i in range (0, N):
	S = str(input())
	if S[0] == 'M':
		MARCH[0]+=1
	if S[0] == 'A':
		MARCH[1]+=1
	if S[0] == 'R':
		MARCH[2]+=1
	if S[0] == 'C':
		MARCH[3]+=1
	if S[0] == 'H':
		MARCH[4]+=1
        
import itertools as it
mokou = list(it.product([0,1], repeat = 5))
count = 0

for i in range (0, len(mokou)):
	if sum(mokou[i]) == 3:
		zen = 1
		for j in range (0, 5):
			if mokou[i][j] == 1:
				zen=zen*MARCH[j]
		count+=zen
        
print(count)

Submission status: Accepted

Solution code:
import collections
import itertools

N = int(input())
S = [input()[0] for _ in range(N)]
A = []
ans = 0

for i in S:
    if i == 'M' or i == 'A' or i == 'R' or i == 'C' or i == 'H':
        A.append(i)
        
if len(A) != 0:       
    C = collections.Counter(A).most_common()
    v,c = zip(*C)
    #print(C)
    #print(c)

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

print(ans)

Submission status: Accepted

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

tot = 0
L = [v for k,v in d.items()]
for i in range(0,5):
  for j in range(i+1,5):
    for k in range(j+1,5):
      #print(i,j,k)
      tot += L[i]*L[k]*L[j]

#print(d)
print(tot)

Submission status: Accepted

Solution code:
n = int(input())
march = {}
for s in "MARCH":
  march[s] = 0
for _ in range(n):
  s = input()[0]
  if s in "MARCH":
    march[s] += 1
ans = 0
for i in range(5):
  s1 = "MARCH"[i]
  n1 = march[s1]
  for j in range(i + 1, 5):
    s2 = "MARCH"[j]
    n2 = march[s2]
    for k in range(j + 1, 5):
      s3 = "MARCH"[k]
      n3 = march[s3]
      ans += n1 * n2 * n3
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations

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

letters = {"M":0, "A":0, "R":0, "C":0, "H":0, }
to_check = combinations([i for i in "MARCH"], 3)

for word in s:
    if word[0] in letters:
        letters[word[0]] += 1

count = 0
for i in to_check:
    count += letters[i[0]] * letters[i[1]] * letters[i[2]]

print(count)

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()[0]]+=1
print(sum([S[a]*S[b]*S[c] for a,b,c in combinations("MARCH",3)]))

Submission status: Accepted

Solution code:
n = int(input())
Mnum = 0
Anum = 0
Rnum = 0
Cnum = 0
Hnum = 0
for i in range(n):
  a = input()
  if a[0] == "M":
    Mnum+=1
  elif a[0] == "A":
    Anum+=1
  elif a[0] == "R":
    Rnum+=1
  elif a[0] == "C":
    Cnum+=1
  elif a[0] == "H":
    Hnum+=1
alist = []
alist.append(Mnum)
alist.append(Anum)
alist.append(Rnum)
alist.append(Cnum)
alist.append(Hnum)
from itertools import combinations
print(sum([a*b*c for a,b,c in combinations(alist,3)]))

Submission status: Accepted

Solution code:
n=int(input())
dic={"M":0,"A":0,"R":0,"C":0,"H":0}
check=["M","A","R","C","H"]

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

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

Submission status: Accepted

Solution code:
from collections import Counter
from itertools import combinations, starmap
func = lambda x, y, z: x*y*z

def main():
    with open(0) as f:
        N, *S = f.read().split()
    S = [s[0] for s in S if s[0] in list('MARCH')]
    S = Counter(S)
    ans = sum(starmap(func, combinations(S.values(), 3)))
    print(ans)

main()

Submission status: Accepted

Solution code:
N=int(input())
S=[input() for _ in range(N)]
cnt=[0]*N
cnt2=[]
flag=0

if len(S)>1:
    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

for i in range(N):
    if cnt[i]!=0:
        cnt2.append(cnt[i])
        
import math
import itertools
ans=0

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s_l = [  input() for _ in range(n)  ]

name_d = ['M','A','R','C','H']
sub_s = {}
for d in name_d:                    
    sub_s[d] = 0

for s in s_l:
    if s[0] in name_d:
        sub_s[s[0]] += 1

ans = 0
memo = set()
for i in range(5):
    for j in range(5):
        for k in range(5):
            a,b,c = sorted([i, j, k])
            if a != b and a!=c and b!=c:
                key = str(a)+str(b)+str(c)
                if key not in memo:
                    ans +=sub_s[name_d[a]] * sub_s[name_d[b]] * sub_s[name_d[c]]
                    memo.add(key)
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations as cmbs
from sys import stdin


def main():
    c = {"M":0,"A":0,"R":0,"C":0,"H":0}
    for si in map(lambda s:s[0],stdin):
        if si in c:
            c[si] += 1
    print(sum(i*j*k for i,j,k in cmbs(c.values(),r=3)))


main()

Submission status: Accepted

Solution code:
from itertools import combinations as cmbs
from sys import stdin
c = {"M":0,"A":0,"R":0,"C":0,"H":0}
for si in map(lambda s:s[0],stdin):
    if si in c:
        c[si] += 1
print(sum(i*j*k for i,j,k in cmbs(c.values(),r=3)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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