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: Wrong Answer

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)
k=len(l)
if k<3:
    print(0)
    exit()
elif k==3:
    ans=1
    for i in l:
        ans += 1 * (i - 1)
elif k==4:
    ans=4
    for i in l:
        ans += 3 * (i - 1)
else:
    ans=10
    for i in l:
        ans+=6*(i-1)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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)
    s = c[0]

    for i in range(1,len(c)):
        s *= c[i]

    ans = s
    
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from math import comb, factorial
from functools import reduce
from itertools import combinations
func = lambda r, tup: r + factorial(tup[0])*factorial(tup[1])*factorial(tup[2])

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 = reduce(func, combinations(S.values(), 3), 0)
    print(ans)

main()

Submission status: Wrong Answer

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

cnt=[]
ans=0
for i in range(N):
    if S[i][0]=='M':
        cnt.append('M')
    elif S[i][0]=='A':
        cnt.append('A')
    elif S[i][0]=='R':
        cnt.append('R')
    elif S[i][0]=='C':
        cnt.append('C')
    elif S[i][0]=='H':
        cnt.append('H')
        
import math
import itertools
c_list = list(itertools.combinations(cnt, 3))

for v in itertools.combinations(cnt, 3):
    print(set(v))
    if len(set(v))==3:
        ans+=1

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#60 C - March
import collections
N = int(input())
S = [input() for _ in range(N)]
S = [s[0] for s in S if s[0] == 'M' or s[0] == 'A' or s[0] == 'R' or s[0] == 'C' or s[0] == 'H']

cnt = collections.Counter(S)
n = len(cnt)

ans = ((n*(n-1)*(n-2))//(3*2))
if ans == 1:
    for i in cnt.values():
        if i>=2:
            ans *= i
else:
    for i in cnt.values():
        if i>=2:
            ans += (n- (((n-1)*(n-2)*(n-3))//(3*2)))*(i-1)
print(ans)

Submission status: Wrong Answer

Solution code:
#60 C - March
import collections
N = int(input())
S = [input() for _ in range(N)]
S = [s[0] for s in S if s[0] == 'M' or s[0] == 'A' or s[0] == 'R' or s[0] == 'C' or s[0] == 'H']

cnt = collections.Counter(S)
n = len(cnt)

ans = ((n*(n-1)*(n-2))//(3*2))
if ans == 1:
    for i in cnt.values():
        if i>=2:
            ans * i
else:
    for i in cnt.values():
        if i>=2:
            ans += (n- (((n-1)*(n-2)*(n-3))//(3*2)))*(i-1)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
S = [input()[:1] for _ in range(N)]
c = Counter(S)

first_name = 'MARCH'
c = [c[i] for i in first_name if c[i]]

ans = 0
if len(c) > 2:
    ans += c[0]*c[1]*c[2]

if len(c) > 3:
    for i in c[3:]:
        for j in range(3):
            tmp = c[:3]
            tmp[j] = i
            ans += tmp[0]*tmp[1]*tmp[2]
if len(c) > 4:
    tmp = c[2:]
    for j in range(3):
        ans += tmp[0]*tmp[1]*c[j]
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import itertools

n = int(input())
s = []
t = [0]*5
for i in range(n):
    s1 = str(input())
    if s1[0] == 'M':
        t[0] += 1
    elif s1[0] == 'A':
        t[1] += 1
    elif s1[0] == 'R':
        t[2] += 1
    elif s1[0] == 'C':
        t[3] += 1
    elif s1[0] == 'H':
        t[4] += 1
t.sort()
t = t[t.count(0):]
if len(t) <= 2:
    print(0)
else:
    q = 0
    for h in itertools.combinations(t,3):
        q += math.factorial(h[0])*math.factorial(h[1])*math.factorial(h[2])
    print(q)

Submission status: Wrong Answer

Solution code:
import collections
import math

N = int(input())
S = [input()[0] for _ in range(N)]
S = [s for s in S if s in ['M','A','R','C','H']]

C = collections.Counter(S)
ans = math.comb(len(list(C.elements())), 3)
L = list(C.most_common())
for s,c in L:
    if c > 1:
        ans -= (c - 1) * (len(L) - 1)

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
name = []
for _ in range(N):
    a = input()
    name.append(a[0])
name = Counter(name)
kouho = []
kouho.append(name["M"])
kouho.append(name["A"])
kouho.append(name["R"])
kouho.append(name["C"])
kouho.append(name["H"])
name = []
for i in kouho:
    if i == 0:
        continue
    name.append(i)
total = sum(name)
seki = 1
for i in name:
    seki = seki*i

if len(name) < 3:
    print(0)
elif len(name) == 3:
    print(seki)
elif len(name) == 4:
    ans = seki*4
    hiku = total-4
    ans = ans-hiku
    print(ans)
else:
    ans = seki*10
    hiku = total-5
    ans = ans-hiku
    print(ans)

Submission status: Wrong Answer

Solution code:
d = {}
for _ in range(int(input())):
    s = input()[0]
    d[s] = d.get(s, 0) + 1

b, ans = False, 1
for m in "MARCH":
    if m in d:
        b = True
        ans *= d[m]
else:
    print(ans if b else 0)

Submission status: Wrong Answer

Solution code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()

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

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

cnts = [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):

      cs = [cnts[i],cnts[j],cnts[k]]
      if 0 in cs:
        continue


      cnt = sum(cs)
      tot = (cnt*(cnt-1)*(cnt-2))//6

      for l in range(3):
        if cs[l]>0:
          tot//=cs[l]
      
      ans += tot
print(ans)

Submission status: Wrong Answer

Solution code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()

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

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

cnts = [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):

      cs = [cnts[i],cnts[j],cnts[k]]


      cnt = sum(cs)
      tot = (cnt*(cnt-1)*(cnt-2))//6

      for l in range(3):
        if cs[l]>0:
          tot//=cs[l]
      
      ans += tot
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import combinations

n = int(input())
c = {
    "M": 0,
    "A": 0,
    "R": 0,
    "C": 0,
    "H": 0
}
ck = list(c.keys())
cnt = 0

for i in range(n):
    s = input()
    if s[0] in c.keys():
        c[s[0]] += 1
        cnt += 1

if cnt >= 3:
    ans = 0
    for p in list(combinations("MARCH", 3)):
        f = True
        cc = c.copy()
        for j in range(2):
            if cc[p[j]] != 0:
                cc[p[j]] -= 1
            else:
                f = False
                break
        if f and cc[p[2]] != 0:
            ans += cc[p[0]] + cc[p[1]] + cc[p[2]]
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

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

for i in range(n):
    s = str(input())
    if s[0] in march:
        dic.setdefault(s[0],0)
        dic[s[0]] += 1
#print(dic)

ans = 0
if len(dic) in [3,4,5]:
    vl = list(dic.values())
    print(vl)
    for i in range(len(vl)-2):
        for j in range(i+1,len(vl)-1):
            for k in range(j+1,len(vl)):
                #print(vl[i],vl[j],vl[k])
                ans += vl[i]*vl[j]*vl[k]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
march = ['M','A','R','C','H']
dic = {}
#for i in march:
#    dic.setdefault(i,0)
#print(dic)

for i in range(n):
    s = str(input())
    if s[0] in march:
        dic.setdefault(s[0],0)
        dic[s[0]] += 1
print(dic)

ans = 0
if len(dic) == 3:
    ans = 1
    for item in dic.items():
        ans *= item[1]
elif len(dic) == 4:
    tmp_ans = 1
    for item in dic.items():
        tmp_ans *= item[1]
    for item in dic.items():
        ans += tmp_ans//item[1]
elif len(dic) == 5:
    vl = list(dic.values())
    print(vl)
    for i in range(3):
        for j in range(i+1,4):
            for k in range(j+1,5):
                ans += vl[i]*vl[j]*vl[k]
print(ans)

Submission status: Wrong Answer

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


ans = 0
for i in range(n):
  for j in range(i+1,n):
    for k in range(j+1,n):
      p = s[i][0]
      q = s[j][0]
      r = s[k][0]
      if (p=='M'or'A'or'C'or'R'or'H') and (q=='M'or'A'or'C'or'R'or'H') and (r=='M'or'A'or'C'or'R'or'H') and (p!=q) and (q!=r) and (r!=p):
        ans += 1
        
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import combinations

n=int(input())
cnt=[0]*26

for i in range(n):
    s=input()
    cnt[ord(s[0])-ord('A')]+=1

ans=0
mod=10**9+7

for c1,c2,c3 in combinations(["M","A","R","C","H"],3):
    c1=ord(c1)-ord("A")
    c2=ord(c2)-ord("A")
    c3=ord(c3)-ord("A")

    ans+=cnt[c1]*cnt[c2]*cnt[c3]
    ans%=mod

print(ans)

Submission status: Wrong Answer

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

march=[0]*5
string="MARCH"

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

if march.count(0)>=3:
    print(0)
    exit()

while march.count(0):
    march.remove(0)

ans=1
for i_0 in range(len(march)):
    for i_1 in range(i_0+1,len(march)):
        for i_2 in range(i_1+1,len(march)):
            ans =  march[i_0]*march[i_1]*march[i_2]
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
name=[]
for i in range(N):
  name.append(input())
M=0
A=0
R=0
C=0
H=0
letters=['M','A','R','C','H']
for i in range(N):
  for j in letters:
    if name[i][0]==j:
      if j=='M':
        M+=1
      elif j=='A':
        A+=1
      elif j=='R':
        R+=1
      elif j=='C':
        C+=1
      elif j=='H':
        H+=1
counter=0
if M==0:
  M+=1
  counter+=1
if A==0:
  A+=1
  counter+=1
if C==0:
  C+=1
  counter+=1
if R==0:
  R+=1
  counter+=1
if H==0:
  H+=1
  counter+=1
counter=5-counter
if counter<3:
  print(0)
  exit()
print(counter*(counter-1)*(counter-2)//6*M*A*C*R*H)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = dict()
for i in range(n):
    s = list(input())
    if s[0] == "M" or s[0] == "A" or s[0] == "R" or s[0] == "C" or s[0] == "H":
        if s[0] not in d:
            d[s[0]] = 1
        else:
            d[s[0]] += 1
count = 0
d = list(d.values())
if len(d) == 3:
    count += d[0] * d[1] * d[2]
elif len(d) == 4:
    count += d[0] * d[1] * d[2]
    count += d[3] * d[1] * d[2]
    count += d[0] * d[1] * d[3]
    count += d[0] * d[3] * d[2]
elif len(d) == 5:    
    count += d[0] * d[1] * d[2]
    count += d[3] * d[1] * d[2]
    count += d[0] * d[1] * d[3]
    count += d[0] * d[3] * d[2]
    
    # count += d[0] * d[1] * d[2]
    count += d[4] * d[1] * d[2]
    count += d[0] * d[1] * d[4]
    count += d[0] * d[4] * d[2]

    count += d[4] * d[1] * d[2]
    # count += d[3] * d[1] * d[2]
    count += d[4] * d[1] * d[3]
    count += d[4] * d[3] * d[2]


print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = dict()
for i in range(n):
    s = list(input())
    if s[0] == "M" or s[0] == "A" or s[0] == "R" or s[0] == "C" or s[0] == "H":
        if s[0] not in d:
            d[s[0]] = 1
        else:
            d[s[0]] += 1
count = 0
d = list(d.values())
if len(d) == 3:
    count = 1
    for i in d:
        count *= i
elif len(d) == 4:
    count += d[0] * d[1] * d[2]
    count += d[3] * d[1] * d[2]
    count += d[0] * d[1] * d[3]
    count += d[0] * d[3] * d[2]
elif len(d) == 5:    
    count += d[0] * d[1] * d[2]
    count += d[3] * d[1] * d[2]
    count += d[0] * d[1] * d[3]
    count += d[0] * d[3] * d[2]

    # count += d[0] * d[1] * d[2]
    count += d[4] * d[1] * d[2]
    count += d[0] * d[1] * d[4]
    count += d[0] * d[4] * d[2]

    count += d[4] * d[1] * d[2]
    # count += d[3] * d[1] * d[2]
    count += d[4] * d[1] * d[3]
    count += d[4] * d[3] * d[2]


print(count)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from itertools import combinations

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

c = defaultdict(int)

for i in range(N):
  if S[i][0] in {'M','A','R','C','H'}:
    c[S[i][0]] += 1

if len(c) < 3:
  print(0)
  exit()

if len(c)==3:
  ans=0
  for k in c.keys():
    ans *= c[k]
  print(ans)
  exit()

else:
  ans = 0
  l = len(c)
  keys = list(c.keys())
  for C in combinations(range(l),3):
    tmp = c[keys[C[0]]]*c[keys[C[1]]]*c[keys[C[2]]]
    ans += tmp
  print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
moji = list('MARCH')
check = [0]*5
for i in range(n):
    s = input()
    if s[0] in moji:
        check[moji.index(s[0])] += 1
ans = 1
flg = 0
for i in range(5):
    if check[i] != 0:
        ans *= check[i]
    flg += check[i]
if flg:
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import math

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

n = int(input())
s = [input()[:1] for _ in range(n)]
s = Counter([i for i in s if i in ['M', 'A', 'R', 'C', 'H']])

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

ans = combinations_count(len(s), 3)
j = combinations_count((len(s)-1), len(s)-3)
for i in s.values():
    ans += (i-1)*j
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import math

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

n = int(input())
s = [input()[:1] for _ in range(n)]
s = Counter([i for i in s if i in ['M', 'A', 'R', 'C', 'H']])

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

ans = combinations_count(len(s), 3)
j = combinations_count((len(s)-1), 2)
for i in s.values():
    ans += (i-1)*j
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
from collections import Counter
n = int(input())
s = [input()[0] for _ in range(n)]
cnt = Counter(s)
print(cnt)

ans = 0
for x,y,z in itertools.combinations("MARCH",3):
 # print(x,y,z)
  ans += cnt[x]*cnt[y]*cnt[z]
  #print(cnt[x],cnt[y],cnt[z])
        
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
march="MARCH"
c=[0 for _ in range(5)]
for i in range(n):
    s=str(input())
    for j in range(5):
        if s[0]==march[j]:
            c[j]+=1

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

Submission status: Wrong Answer

Solution code:
n=int(input())
m=[0,0,0,0,0]
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
m="".join(map(str,m))
m=m.replace("0","")
if len(m)==0:
    print(0)
    quit()
p=len(m)
ans=1
for i in range(3):
    ans*=p-i
ans=ans//6
for i in range(len(m)):
    if m[i]!=1:
        ans+=(len(m)-1)*(int(m[i])-1)
print(ans)

Submission status: Wrong Answer

Solution code:
from math import factorial


def combinations_count(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))


def main():
    s = int(input())
    ns = [input()[0] for _ in range(s)]
    Countdict = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
    Count = 0
    dist_Count = 0

    for i in range(s):
        if ns[i] not in Countdict.keys():
            continue
        Countdict[ns[i]] += 1
        Count += 1
        if Countdict[ns[i]] == 1:
            dist_Count += 1

    if Count < 3:
        print(0)
        exit()
    ans = combinations_count(Count, 3)
    for key, value in Countdict.items():
        if value >= 2:
            ans -= (dist_Count-1)*(value-1)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
member = []
count = np.array([0], dtype='int64')

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

Submission status: Wrong Answer

Solution code:

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

Submission status: Wrong Answer

Solution code:
from itertools import combinations

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

# check
cnt = 0
MARCH = ["M", "A", "R", "C", "H"]
for c in combinations(S, 3):

    tops = [s[0] for s in c if s[0] != MARCH]

    if len(set(tops)) == 3:
        cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
from itertools import combinations

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

# check
cnt = 0
MARCH = ["M", "A", "R", "C", "H"]
for c in combinations(S, 3):
    
    tops = [s[0] for s in c if s[0] != MARCH]
    
    if len(set(tops)) == 3:
        cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
from itertools import combinations

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

# check
cnt = 0

MARCH = ["M", "A", "R", "C", "H"]
tops = [s for s in S if s in MARCH]

for c in combinations(tops, 3):
    if len(set(tops)) == 3:
        cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
from itertools import combinations

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

# check
cnt = 0

MARCH = ["M", "A", "R", "C", "H"]
tops = [s for s in S if s in MARCH]

for c in combinations(tops, 3):
    if len(tops) == 3 and len(tops) == len(set(tops)):
        cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=[input() for _ in range(N)]
S.sort()
S.append('0')
dp=[0]*5
for i in range(N+1):
  if i==N:
    continue
  if S[i]==S[i+1]:
    continue
  if S[i][0]=='M':
    dp[0]+=1
  elif S[i][0]=='A':
    dp[1]+=1
  elif S[i][0]=='R':
    dp[2]+=1
  elif S[i][0]=='C':
    dp[3]+=1
  elif S[i][0]=='H':
    dp[4]+=1
ans=0
for i in range(2):
  for j in range(i+1,4):
    for k in range(j+1,5):
      ans+=dp[i]*dp[j]*dp[k]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from itertools import combinations
from collections import Counter
input = sys.stdin.readline


def log(*args):
    print(*args, file=sys.stderr)


def main():
    n = int(input().rstrip())
    s = [input()[0] for _ in range(n)]
    s = [v for v in range(n)]
    c = Counter(s)
    ans = 0
    for x, y, z in combinations('MARCH', 3):
        ans += c[x] * c[y] * c[z]
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import itertools
n = int(input())
sl = []

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

lst = []
for com in itertools.combinations(dic.keys(),3):
    lst.append(com)
print(lst)

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
import itertools

n = int(input())

s = [str(input()) for _ in range(n)]
initial = [''] * n

for i in range(n):
    initial[i] = s[i][0]

reg = Counter(initial)
ele = []

for i, j in reg.items():
    ele.append(i)
ans = 0
for A in itertools.combinations(ele, 3):
    #print(A)
    cnt = 1
    for s in A:
        cnt *= reg[s]
    ans += cnt

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

ans = 0
check_list = ['M','A','R','C','H']
for bit in range(2 ** n):
    print(bin(bit))
    if bin(bit).count('1') != 3:
        continue

    mans = []
    check = []
    for i in range(n):
        if bit >> i & 1:
            if not s[i][0] in mans and s[i][0] in check_list:
                mans.append(s[i][0])
            else:
                break

    if len(mans) == 3:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = [0]*5
x = 1

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

if ans.count(0) == 5:
    print(0)

else:
    for i in ans:
        if i != 0:
            x *= i
    print(x)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = [0]*7
ans = 0

for i in range(n):
  s = input()
  if s[0] == "M":
    l[0] += 1
  elif s[0] == "A":
    l[1] += 1
  elif s[0] == "R":
    l[2] += 1 
  elif s[0] == "C":
    l[3] += 1
  elif s[0] == "H":
    l[4] += 1
    
for i in range(2):
  for j in range(i+1,i+3):
    for k in range(j+1,j+3):
      ans += l[i] * l[j] * l[k]
#      print(i,j,k,ans)
  
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import itertools

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

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

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

print(ans)

Submission status: Wrong Answer

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 = collections.Counter(array)
n = len(array)
ans = n*(n-1)*(n-2)//(3*2)

for i in c:
    if c[i] == 2:
        ans -= n-c[i]
    elif c[i] >= 3:
        value = (c[i]*c[i]-1)//2-1
        ans -= value

print(ans)

Submission status: Wrong Answer

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

print(s)

Mx,Ax,Rx,Cx,Hx=0,0,0,0,0

for n in range(N):
  if   s[n][0] =="M":
    Mx += 1
  elif s[n][0] =="A":
    Ax += 1
  elif s[n][0] =="R":
    Rx += 1
  elif s[n][0] =="C":
    Cx += 1
  elif s[n][0] =="H":
    Hx += 1

MAR = Mx * Ax * Rx
MAC = Mx * Ax * Cx
MAH = Mx * Ax * Hx
MRC = Mx * Rx * Cx
MRH = Mx * Rx * Hx
MCH = Mx * Cx * Hx

ARC = Ax * Rx * Cx
ARH = Ax * Rx * Hx
ACH = Ax * Cx * Hx

RCH = Rx * Cx * Hx

print(MAR+MAC+MAH+MRC+MRH+MCH+ARC+ARH+ACH+RCH)

Submission status: Wrong Answer

Solution code:
import numpy as np
from functools import reduce
from collections import defaultdict

N = int(input())
d = defaultdict(int)
for i in range(N):
    c = input()
    if c[0] in ('M', 'A', 'R', 'C', 'H'):
        d[c[0]] += 1

l = len(d)
if l < 3:
    print(0)
else:
    if l == 3:
        ans = reduce(np.multiply, d.values())
    elif l >= 4:
        ans = 0
        t = reduce(np.multiply, d.values())
        for v in d.values():
            ans += t / v
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import itertools

n = int(input())
a = [i.rstrip() for i in sys.stdin.readlines() if i.rstrip()[0] in ['M','A','R','C','H'] ]

print(len(list(itertools.combinations(a, 3))))

Submission status: Wrong Answer

Solution code:
import itertools
def myAnswer(N:int,S:list) -> int:
   ans = 0
   dic = {}
   for s in S:
      if(s[0] in dic.keys()):
         dic[s[0]] += 1
      else:
         dic[s[0]] = 1
   for c in itertools.combinations(dic.values(),3):
      ans += c[0]*c[1]*c[2]
      
   return ans

def modelAnswer():
   return
def main():
   N = int(input())
   S = [input() for _ in range(N)]
   print(myAnswer(N,S[:]))
if __name__ == '__main__':
   main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import itertools
import collections

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

    array = ['M','A','R','C','H']
    S_after = []
    for s in S:
        if s in array:
            S_after.append(s)
    if len(S_after) < 3:
        print(0)
    combs = itertools.combinations(set(S_after), 3)
    coll = collections.Counter(S_after)

    ans = 0
    for comb in combs:
        if comb[0] != comb[1] != comb[2]:
            ans += coll[comb[0]]*coll[comb[1]]*coll[comb[2]]
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

march = [0]*5
ans = 0
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(march)

for j in itertools.combinations(march,3):
    comb_multi = 1
    for k in range(3):
      comb_multi *= j[k]
    ans += comb_multi
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import os
import math
import bisect
import collections
import itertools
import heapq

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    name = isn(N)

    ret = 0
    s = ['M', 'A', 'R', 'C', 'H']
    for i in itertools.combinations(name, 3):
        if i[0][0] != i[1][0] != i[2][0] and i[0][0] in s and i[1][0] in s and i[2][0] in s:
            ret += 1
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
s=[]
for i in range(N):
  S=input()
  s.append(S)
m=0
a=0
r=0
c=0
h=0
for i in range(N):
  if s[i][0]=="M":
    m+=1
  if s[i][0]=="A":
    a+=1
  if s[i][0]=="R":
    r+=1
  if s[i][0]=="C":
    c+=1
  if s[i][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: Wrong Answer

Solution code:
n=int(input())
march=[0,0,0,0,0]
for i in range(n):
  s=input()
  if s[0]=="M":
    march[0]+=1
  elif s[0]=="A":
    march[1]+=1
  elif s[0]=="R":
    march[2]+=1
  elif s[0]=="C":
    march[3]+=1
  elif s[0]=="H":
    march[4]+=1
ans=1
if march.count(0)>3:
  print(0)
elif march.count(0)==2:
  for i in march:
    if i!=0:
      ans*=i
  print(ans)
elif march.count(0)==1:
  ans=4
  for i in march:
    if i!=0:
      ans+=(i-1)*3
  print(ans)
elif march.count(0)==0:
  ans=10
  for i in march:
    if i!=0:
      ans+=(i-1)*6
  print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input().split())
m,a,r,c,h = 0,0,0,0,0
for s in S:
  if 'M' == s[0]:
    m+=1
  elif 'A' == s[0]:
    a+=1
  elif 'R' == s[0]:
    r+=1
  elif 'C' == s[0]:
    c+=1
  elif 'H' == s[0]:
    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: Wrong Answer

Solution code:
n = int(input())
ans = [0]*5
x = 1

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

if ans.count(0) == 5:
    print(0)
else:
    for i in ans:
        if i != 0:
            x *= i
    print(x)
print(ans)