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:
import itertools
n = int(input())
sl = []
for i in range(n):
    name = input()
    if name[0] in ['M','A','R','C','H']:
        sl.append(name)
if len(sl) < 3:
    print(0)
    exit()

dic = {'M':0,'A':1,'R':2,'C':3,'H':4}

cnt = 0
for com in itertools.combinations(sl,3):
    lst = [0]*5
    for name in com:
        if lst[dic[name[0]]] == 0:
            lst[dic[name[0]]] += 1
    if sum(lst) == 3:
       cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools

def main():
    MARCH = ['M','A','R','C','H']
    N = int(input())
    S = []
    cnt = 0
    for _ in range(N):
        s = input()
        if not s[0] in MARCH:
            continue
        S.append(s)
    for a,b,c in itertools.combinations(S,3):
        # print(a,b,c,cnt)
        if a[0] == b[0] or b[0] == c[0] or a[0] == c[0]:
            continue
        cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools

def main():
    M = ['M','A','R','C','H']
    N = int(input())
    S = []
    cnt = 0
    for _ in range(N):
        S.append(input())
    for a,b,c in itertools.combinations(S,3):
        if a[0] == b[0] or b[0] == c[0] or a[0] == c[0]:
            continue
        if a[0] in M and b[0] in M and c[0] in M:
            cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    num_m = 0
    num_a = 0
    num_r = 0
    num_c = 0
    num_h = 0
    inlis = []
    for i in range(n):
        s = input()
        if s in inlis:
            pass
        else:
            inlis.append(s)
            if s[0] == "M":
                num_m += 1        
            if s[0] == "A":
                num_a += 1
            if s[0] == "R":
                num_r += 1
            if s[0] == "C":
                num_c += 1
            if s[0] == "H":
                num_h += 1
    numlis = [num_m, num_a, num_r, num_c, num_h]
    ans = 0
    if sum(numlis) < 3:
        print(0)
    else:
        for i in range(5):
            for j in range(5):
                for k in range(5):
                    if i == j or i == k or j == k:
                        pass
                    else:
                        ans += numlis[i] * numlis[j] * numlis[k]
        print(int(ans/6))
                    


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


n = I()
s = SR(n)

name_h = tuple([name[0] for name in s if name[0] in {'M', 'A', 'R', 'C', 'H'}])

ans = list(itertools.combinations(name_h, 3))
ans = len([a for a in ans if len(set(a)) == 3])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy


mod = 10**9 + 7
def combi(n,r):
    x = math.factorial(n)%mod
    y = math.factorial(r)
    y = pow(y,mod-2,mod)
    return x*y%mod

if __name__ == "__main__":
    n = int(input())
    S = [input() for i in range(n)]
    koho = []
    for i in range(n):
        if S[i][0] == "M" or S[i][0] == "A" or S[i][0] == "R" or S[i][0] == "C" or S[i][0] == "H":
            koho.append(S[i])
    c = list(itertools.combinations(koho,3))
    cnt = 0
    for name1,name2,name3 in c:
        if name1[0] != name2[0] and name1[0] != name3[0] and name2[0] != name3[0]:
            cnt+=1
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
count ={'M':0,'A':0,'R':0,'C':0,'H':0}
init_set = set()
cnt=0

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

ans=0
ans = len(list(itertools.combinations(range(cnt),3)))

if len(init_set)<3:
  print(0)
else:  
  for key,val in count.items():
    if val==0:
      continue
    else:
      if val==1:
        continue
      elif val==2:
        ans-= len(list(itertools.combinations(range(cnt-val),1)))
      elif val>=3:
        ans-= len(list(itertools.combinations(range(val),3)))
        ans-= len(list(itertools.combinations(range(val),2))) * (cnt-val)
  else:
    print(ans)

Submission status: Time Limit Exceeded

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

# 同じ文字から始まらない 3 人の選び方
from itertools import combinations

cnt = 0
for v in combinations(A, 3):
    if v[0][0] == v[1][0] or v[1][0] == v[2][0] or v[2][0] == v[0][0]:
        continue
    cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n=int(input())
e=[]
for i in range(n):
  a=input()
  if a[0] in "MARCH":
    e.append(a)
count=0
for a,b,c in itertools.combinations(e,3):
  if a[0]!=b[0] and b[0]!=c[0] and c[0]!=a[0]:
    count+=1
print(count)

Submission status: Time Limit Exceeded

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
pattern = list(combinations(NAME,3))
LEN = len(S)
cnt=0
for s1 in range(LEN-2):
    for s2 in range(s1+1,LEN-1):
        for s3 in range(s2+1,LEN):
            if (S[s1],S[s2],S[s3]) in pattern:
                cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S =[]
for n in range(N):
    s = input()
    S.append(s[0])
NAME = ["M","A","R","C","H"]
from itertools import permutations
pattern = list(permutations(NAME,3))
LEN = len(S)
cnt=0
for s1 in range(LEN-2):
    for s2 in range(s1+1,LEN-1):
        for s3 in range(s2+1,LEN):
            if (S[s1],S[s2],S[s3]) in pattern:
                cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import collections
N = int(input())
MARCH = ['M','A','R','C','H']
array = collections.deque()
cnt = 0
for i in range(N):
    s = input()
    if s[0] in MARCH:
        array.append(s[0])

c = list(itertools.combinations(array,3))
for i in c:
    if len(set(i)) == 3:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
MARCH = ['M','A','R','C','H']
array = []
cnt = 0
for i in range(N):
    s = input()
    if s[0] in MARCH:
        array.append(s[0])

c = list(itertools.combinations(array,3))
for i in c:
    if len(set(i)) == 3:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools
total = int(input())
lis1 = [input() for x in range(total)]
lis2 = []
for name in lis1:
  if "M" == name[0] or "A" == name[0] or "R" == name[0] or "C" == name[0] or "H" == name[0]:
    lis2.append(name)
count = 0
for a in itertools.combinations(lis2,3):
  if a[0][0] != a[1][0] and a[1][0] != a[2][0] and a[0][0] != a[2][0]:
    count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
total = int(input())
lis1 = []
for x in range(total):
  lis1.append(input())
lis2 = []
for name in lis1:
  if "M" == name[0] or "A" == name[0] or "R" == name[0] or "C" == name[0] or "H" == name[0]:
    lis2.append(name)
count = 0
for a in itertools.combinations(lis2,3):
  if a[0][0] != a[1][0] and a[1][0] != a[2][0] and a[0][0] != a[2][0]:
    count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

tm=(list(itertools.combinations(li,3)))

for j in tm:
    if j[0][0]!=j[1][0] and j[1][0]!=j[2][0] and j[2][0]!=j[0][0]:
        ans+=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

tm=(list(itertools.combinations(li,3)))

for j in tm:
    if j[0][0]!=j[1][0] and j[1][0]!=j[2][0] and j[2][0]!=j[0][0]:
        ans+=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
char = ['M', 'A', 'R', 'C', 'H']

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

# print(s)

from itertools import permutations, combinations,combinations_with_replacement,product

c = list(combinations(s,3))

ans = 0

for i in c:
    if i[0] != i[1] and i[0] != i[2] and i[1] != i[2]:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#import collections
#aa = collections.Counter(a) # list to list
from itertools import combinations # (string,3) 3回


mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    S = []
    for i in range(n):
        s = input()
        S.append(s)
    na = ['M','A','R','C','H']
    cnt = 0
    for a,b,c in combinations(S,3):
        if a[0] in na and b[0] in na and c[0] in na and a[0]!=b[0] and b[0]!=c[0] and c[0]!= a[0]:
            cnt += 1
    print(cnt)



if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

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

def main():
    mojiretu = ('M', 'A', 'R', 'C', 'H')
    t = input()
    ttt = []
    for i in range(int(t)):
        tmp = input()
        if tmp[0] in mojiretu:
            ttt.append(tmp)
    if len(ttt) < 3:
        print(0)
        exit()
    li = list(itertools.combinations([v[0] for v in ttt], 3))
    count = 0
    for s in li:
        if len(set(s)) == 3:
            count += 1
    print(count)





if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

import itertools


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

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

    result = []
    for comb in list(itertools.combinations(march, 3)):
        if comb[0] != comb[1] and comb[0] != comb[2] and comb[1] != comb[2]:
            result.append(comb)

    print(len(result))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
q = []
import sys
from collections import Counter
import itertools

for _ in range(n):
    s = input()
    a = s[0]
    
    if a =='M' or a =='A' or a =='R' or a =='C' or a =='H':
        q.append(a)
        
b = Counter(q)
m = 0

if len(b) < 3:
    print(0)
    sys.exit()
else:
    p = list(itertools.combinations(q,3))

ans = 0
for i in p:
    if len(Counter(i)) == 3:
        ans += 1
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

n = int(input())
S = []

for _ in range(n):
  s = input()
  if s[0] in set(['M','A','R','C','H']):
    S.append(s[0]) 
  
print(sum([1 for pattern_i in combinations(S, 3) if len(set(pattern_i))==3]))

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

comb = combinations(S, 3)
ans = 0

for i in list(comb):

    cnt = 0

    if i.count("M") > 1:
        continue
    if i.count("A") > 1:
        continue
    if i.count("R") > 1:
        continue
    if i.count("C") > 1:
        continue
    if i.count("H") > 1:
        continue

    cnt += i.count("M")
    cnt += i.count("A")
    cnt += i.count("R")
    cnt += i.count("C")
    cnt += i.count("H")

    if cnt == 3:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
lis = [input() for _ in range(n)]
lis.sort()
choice = list(itertools.combinations(range(n), 3))
count = 0
for ch in choice:
    master = set(['M','A','R','C','H'])
    se = set([lis[ch[0]][0],lis[ch[1]][0],lis[ch[2]][0]])
    #print(master,se,master - se)
    if len(master - se) == 2:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
lis = [input() for _ in range(n)]
lis.sort()
choice = list(itertools.combinations(range(n), 3))
count = 0
for ch in choice:
    master = ['M','A','R','C','H']
    for c in ch:
        if lis[c][0] in master:
            master.remove(lis[c][0])
        else:
            break
        if len(master) == 2:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

N = int(input())
SSS = [input() for _ in range(N)]

# Filter1
filter_1 = {'M', 'A', 'R', 'C', 'H'}
canditates = [S for S in SSS if S[0] in filter_1]

n_satisfied = 0
for cand in combinations(canditates, 3):
    cond1 = cand[0][0] != cand[1][0]
    cond2 = cand[1][0] != cand[2][0]
    cond3 = cand[2][0] != cand[0][0]
    if cond1 and cond2 and cond3:
        n_satisfied += 1

print(n_satisfied)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

N = int(input())
Sn = [input() for _ in range(N)]

Ln = []
for i in range(N):
    if Sn[i][0] not in {"M", "A", "R", "C", "H"}:
        continue
    Ln.append(Sn[i])


ans = 0
for a, b, c in combinations(Ln, 3):
    if len({a[0], b[0], c[0]}) != 3:
        continue
    ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:

N = int(input())
S = []

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

for i in range(N):
  s = input()
  if s[0] in T:
    S.append(s)

from itertools import combinations

result = list(combinations(S, 3))

ans = 0
for r in result:
  if r[0][0] == r[1][0] or r[0][0] == r[2][0] or r[1][0] == r[2][0]: 
    continue
  ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

N = int(input())
name=[]
for i in range(N):
    si = input()
    if si[0] in ['M', 'A', 'R', 'C', 'H']:
        name.append(si)
if name==[]:
    print(0)
    exit()

ans=0
for i, names in enumerate(list(combinations(name, 3))):
    x,y,z=names[0][0],names[1][0],names[2][0]
    if x==y or y==z or z==x:
        continue
    else:
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
LL = [input() for x in range(n)]
LL = [x for x in LL if x[0] in ['M','A','R','C','H']]
import itertools
LL = list(itertools.combinations(LL, 3))
ANS = [x for x in LL if x[0][0] != x[1][0] and x[1][0] != x[2][0] and x[0][0] != x[2][0]]
print(len(ANS))

Submission status: Time Limit Exceeded

Solution code:
import itertools
heads = ["M","A","R","C","H"]

N = int(input())
S = []

for i in range(N):
  s = input()[0]
  if s in heads:
    S.append(s)

combi = list(itertools.combinations(S,3))
con = 0

for i in combi:
  if len(set(i)) == 3:
    con += 1
    
print(con)

Submission status: Time Limit Exceeded

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

march = 'MARCH'

h = []
for x in s:
  if x[0] in march:
    h.append(x[0])

ans = 0
import itertools
for com in itertools.combinations(h, r=3):
  for x in com:
    if not x[0] in march:
      break
  if len(com) == len(set(com)):
    ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
S = [input().rstrip() for _ in range(N)]

S = [s for s in S if s[0] in 'MARCH']

C = list(itertools.combinations(S, 3))
#print(C)

cnt = 0
for c in C:
	#print(c)
	x, y, z = c
	if x[0] != y[0] and y[0] != z[0] and x[0] != z[0]:
		cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
from itertools import combinations

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

lin = []

for i in range(n):
    if li[i][0] in "MARCH":
        lin.append(li[i][0])

liv = list(combinations(lin, 3))
point = 0
for i in liv:
    if i[0] != i[1] and i[0] != i[2] and i[2] != i[1]:
        point += 1
print(point)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import numpy as np
import math
from math import factorial
from itertools import combinations

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

lin = []

for i in range(n):
    if li[i][0] in "MARCH":
        lin.append(li[i][0])

liv = list(combinations(lin, 3))
point = 0
for i in liv:
    if i[0] != i[1] and i[0] != i[2] and i[2] != i[1]:
        point += 1
print(point)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

ans = 0
combs = list(itertools.combinations(M+A+R+C+H, 3))
for comb in combs:
    flag = True
    for s in [M, A, R, C, H]:
        n = len(set(comb) & set(s))
        if n >= 2:
            flag = False
            break
    if flag:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())

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

l = [i for i in l if i in {'M','A','R','C','H'}]

l2 = [i for i in list(itertools.combinations(l,3)) if len(set(i)) == 3]

print(len(l2))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

for i,s in enumerate(S):
    if not s in ['M', 'A', 'R', 'C', 'H']:
        S.pop(i)

count = 0
for i in itertools.combinations(S,3):
    if i[0][0] != i[1][0] and i[0][0] != i[2][0] and i[1][0] != i[2][0]:
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
ary = []
for i in range(n):
    s = input()[0]
    if s == "M" or s == "A" or s =="R" or s =="C" or s == "H":
        ary.append(s)
print(len([ i for i in itertools.combinations(ary,3) if len(set(i)) == 3]))

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
n = int(input())
Names = [""] * n
for i in range(n):
  Names[i] = input()
march = ["M", "A", "R", "C", "H"] 
counter = 0
for three_man in combinations(Names, 3):
  if three_man[0][0] in march and three_man[1][0] in march and three_man[2][0] in march:
    if three_man[0][0] != three_man[1][0] and three_man[1][0] != three_man[2][0] and three_man[2][0] != three_man[0][0]:
      counter += 1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

ans = 0
for s in combinations(S, 3):
    _flag = True
    pre = list(map(lambda x: x[0], s))
    for p in pre:
        if p not in ['M', 'A', 'R', 'C', 'H']:
            _flag = False
    if len(pre) != len(list(set(pre))):
        _flag = False
    if _flag:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n=int(input())
s=list(filter(lambda _s: _s == "M" or _s == "A" or _s == "R" or _s == "C" or _s == "H", (input()[0] for _ in range(n))))

if len(s) < 3:
    print(0)
    quit()

print(len(list(filter(lambda x: len(set(x))==3, itertools.combinations(s, 3)))))

Submission status: Time Limit Exceeded

Solution code:
import itertools

n=int(input())
s=list(map(lambda _s: _s[0], filter(lambda _s: _s[0] == "M" or _s[0] == "A" or _s[0] == "R" or _s[0] == "C" or _s[0] == "H", list(input() for _ in range(n)))))

if len(s) == 0:
    print(0)
    quit()

print(len(list(filter(lambda x: len(set(x))==3, itertools.combinations(s, 3)))))

Submission status: Time Limit Exceeded

Solution code:
import itertools

n=int(input())
s=list(input() for _ in range(n))
s=list(map(lambda _s: _s[0], filter(lambda _s: _s[0] == "M" or _s[0] == "A" or _s[0] == "R" or _s[0] == "C" or _s[0] == "H", s)))

if len(s) == 0:
    print(0)
    quit()

print(len(list(filter(lambda x: len(x)==3, map(set, itertools.combinations(s, 3))))))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n=int(input())
name=[]
initial=[]
for _ in range(n):
    s=input()
    if s[0] in ["M","A","R","C","H"] and not s in name:
        name.append(s)
        initial.append(s[0])
c=Counter(initial)
num=[v for k,v in c.items()]

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
s = "MARCH"
lst = []

for i in range(N):
  begin = input()[0] 
  if begin in list(s):
    lst.append(begin)
ans = [1 for i in list(itertools.combinations(lst,3)) if (len(set(i)) == 3)]
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
s = "MARCH"
lst = []

for i in range(N):
  begin = input()[0] 
  if begin in list(s):
    lst.append(begin)
ans = 0
for i in list(itertools.combinations(lst,3)):
  if (len(set(i)) == 3):
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
import itertools
N = int(input())
s = "MARCH"
lst = []

for i in range(N):
  begin = list(input())[0] 
  if begin in list(s):
    lst.append(begin)
ans = 0
for i in list(itertools.combinations(lst,3)):
  if (len(set(i)) == 3):
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
import sys
import math
from collections import Counter
input = sys.stdin.readline

def P(n, r):
    return math.factorial(n)//math.factorial(n-r)

def C(n, r):
    return P(n, r)//math.factorial(r)

N = int(input())
arr = [input() for i in range(N)]
ini_arr = [j[0] for j in arr if j[0] == "M" or j[0] == "A" or j[0] == "R" or j[0] == "C" or j[0] == "H"]
dic = Counter(ini_arr)
key_num = len(dic)
val_num = sum(v for v in dic.values())
if key_num < 3:
    print(0)
else:
    total = C(len(ini_arr), 3)
    for i in dic.values():
        if i == 2:
            total -= C(val_num - i, 1)
        elif i >= 3:
            total -= C(i, 2) * C(val_num - i, 1)  + C(i, 3)
    print(total)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
import sys
import math
from collections import Counter

def P(n, r):
    return math.factorial(n)//math.factorial(n-r)

def C(n, r):
    return P(n, r)//math.factorial(r)

N = int(sys.stdin.readline().strip())
arr = [sys.stdin.readline().strip() for i in range(N)]
mar_arr = [j for j in arr if j[0] == "M" or j[0] == "A" or j[0] == "R" or j[0] == "C" or j[0] == "H"]
ini_arr = [k[0] for k in mar_arr]
dic = Counter(ini_arr)
key_num = len(dic)
val_num = sum(v for v in dic.values())
if key_num < 3:
    print(0)
else:
    total = C(len(ini_arr), 3)
    for i in dic.values():
        if i == 2:
            total -= C(val_num - i, 1)
        elif i >= 3:
            total -= C(i, 2) * C(val_num - i, 1)  + C(i, 3)
    print(total)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
import math
from collections import Counter

def P(n, r):
    return math.factorial(n)//math.factorial(n-r)

def C(n, r):
    return P(n, r)//math.factorial(r)

N = int(input())
arr = [input() for i in range(N)]
mar_arr = [j for j in arr if j[0] == "M" or j[0] == "A" or j[0] == "R" or j[0] == "C" or j[0] == "H"]
ini_arr = [k[0] for k in mar_arr]
dic = Counter(ini_arr)
key_num = len(dic)
val_num = sum(v for v in dic.values())
if key_num < 3:
    print(0)
else:
    total = C(len(ini_arr), 3)
    for i in dic.values():
        if i == 2:
            total -= C(val_num - i, 1)
        elif i >= 3:
            total -= C(i, 2) * C(val_num - i, 1)  + C(i, 3)
    print(total)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N=int(input())
march='MARCH'
S=[]
for _ in range(N):
    s=input()
    if s[0] in march:
        S.append(s)
cnt=0
if len(S)>=3:
    cnt=0
    combi=list(itertools.combinations(S,3))
    for i in combi:
        head=[]
        for j in range(3):
            head.append(i[j][0])
        if len(set(head))==3:
            cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
n = int(input())
arr = [input()[0] for s in range(n)]
arr = [s for s in arr if s in "MARCH"]
combi = [len(set(i)) for i in combinations(arr, 3)]
print(sum([1 for i in combi if i==3]))

Submission status: Time Limit Exceeded

Solution code:
import copy
from itertools import combinations
N=int(input())
S=list(input()[0] for _ in range(N))
cS=copy.deepcopy(S)
ans=0
for i in cS:
    if i not in ['M', 'A', 'R', 'C', 'H']:
        S.remove(i)
P=list(combinations(S,3))
for i in P:
    if len(set(i))==3:
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#https://atcoder.jp/contests/abc089/tasks/abc089_c
import itertools
N = int(input())
S = [input() for _ in range(N)]
march = [0]*max(N,3)
ans = 0
for s in S:
    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

for i,j,k in itertools.combinations(march,3):
    ans += i*j*k
print(ans)

Submission status: Time Limit Exceeded

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

S = list(set(S))

N = len(S)
selected = [""] * 2
cnt = 0
for i in range(N):
    selected[0] = S[i][0]
    for k in range(i+1, N):
        if selected[0] == S[k][0]:
            continue
        selected[1] = S[k][0]
        for t in range(k+1, N):
            if selected[1] == S[t][0]:
                continue
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

import itertools

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

delete = []

for i in range(n):
    if s[i][0] == "M" or s[i][0] == "A" or s[i][0] == "R" or s[i][0] == "C" or s[i][0] == "H":
        pass
    else:
        delete.append(i)

diff = 0
for i in range(len(delete)):
    del s[delete[i] - diff]
    diff += 1

cand = list(itertools.combinations(s,3))

ans = 0
for i in range(len(cand)):
    if cand[i][0][0] != cand[i][1][0] and cand[i][1][0] != cand[i][2][0] and cand[i][2][0] != cand[i][0][0]:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

X=list(itertools.combinations(S,3))
res=len(X)
for i in range(len(X)):
    Y=[X[i][0][0],X[i][1][0],X[i][2][0]]
    if len(set(Y))<3:
        res-=1

print(res)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import collections

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

b = list(itertools.combinations(name,3))
total = 0
for tap in b:
    d = []
    for c in tap:
        d.append(c[0])
        
    d.sort()    
    e = collections.Counter(d)

    cnt = 0
    for v in e.values():
        if v == 1:
            cnt += 1
    if cnt == 3:
        total += 1

print(total)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n=int(input())
list1=[]
for j in range(n):
  s=input()
  if s[0]=='M' or s[0]=='A' or s[0]=='R' or s[0]=='C' or s[0]=='H':
    list1.append(s[0])

list1.sort()

list2=list(itertools.combinations(list1, 3))

cnt=0
for j in range(len(list2)):
  if len(list2[j])==len(set(list2[j])):
    cnt+=1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n=int(input())
list1=[]
for j in range(n):
  s=input()
  if s[0]=='M' or s[0]=='A' or s[0]=='R' or s[0]=='C' or s[0]=='H':
    list1.append(s[0])

#list1.sort()

list2=list(itertools.combinations(list1, 3))

cnt=0
for j in range(len(list2)):
  if len(list2[j])==len(set(list2[j])):
    cnt+=1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = []
for i in range(n):
    s.append(str(input()))
for i,j in enumerate(s):
    if j[0] != 'M' and j[0] != 'A' and j[0] != 'R' and j[0] != 'C' and j[0] != 'H':
        s.pop(i)
import itertools
count = 0
for i in itertools.combinations(s, 3):
    check = []
    for j in i:
        check.append(j[0])
    if len(list(set(check))) == 3:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
from itertools import combinations

N = int(input())
S = []
m = ['M', 'A', 'R', 'C', 'H']
c = defaultdict(int)
ans = 0

if N <= 2:
    print(0)
else:
    for i in range(N):
        na = input()
        fs = na[0]
        
        if fs in m and na not in S:
            S.append(na)
            
            if fs == 'M':
                c['M'] += 1
            elif fs == 'A':
                c['A'] += 1
            elif fs == 'R':
                c['R'] += 1
            elif fs == 'C':
                c['C'] += 1
            elif fs == 'H':
                c['H'] += 1
        
    con = list(combinations(m, 3))
    for i, j, k in con:
        ans += c[i] * c[j] * c[k]
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
i=0
s=[]
con=["M","A","R","C","H"]
select_1=[]
while i<N:
    a=input()
    s.append(a)
    i+=1
for ss in s:
    if ss[0] in con:
        select_1.append(ss)
i=0
l=len(select_1)
select=[]
count=0
while i<l:
    select.append(select_1[i])
    j=i
    while j<l:
        select.append(select_1[j])
        k=j
        while k<l:
            select.append(select_1[k])
            if select[0][0]!=select[1][0] and select[0][0]!=select[2][0] and select[1][0]!=select[2][0]:
                count+=1
            select.pop()
            k+=1
        select.pop()
        j+=1
    select.pop()   
    i+=1

print(count)