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())
data = [0 for i in range(5)]
for i in range(n):
    k = input()
    if k[0] == 'M':
        data[0] += 1
    elif k[0] == 'A':
        data[1] += 1
    elif k[0] == 'R':
        data[2] += 1
    elif k[0] == 'C':
        data[3] += 1
    elif k[0] == 'H':
        data[4] += 1
total = 0
print(data)
for i in range(5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            total += data[i] * data[j] * data[k]
print(total)

Submission status: Wrong Answer

Solution code:
n=int(input())
al=list('MARCH')
d=[0]*5
for i in range(n):
    s=list(input())
    if s[0] in al:
        d[al.index(s[0])]+=1
op=[[0],[1]]
for i in range(4):
    tmp=[]
    for j in op:
        j.append(0)
        tmp.append(j)
        j.pop(-1)
        j.append(1)
        tmp.append(j)
    op=tmp
k=[]
for i in op:
    if sum(i)==3:
        k.append(i)
ans=0
for i in k:
    t=1
    for j in range(5):
        if i[j]==1:
            t*=d[j]
    ans+=t
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=[]
a,b,c,d,e=0,0,0,0,0
for i in range(n):
  S=input()
  if S[0]=='M':
    a+=1
  if S[0]=='A':
    b+=1
  if S[0]=='R':
    c+=1
  if S[0]=='C':
    d+=1
  if S[0]=='H':
    e+=1
print(a*b*c*+a*b*d+a*b*e+a*c*d+a*c*e+a*d*e+b*c*d+b*c*e+b*d*e+c*d*e)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
S = [input() for _ in range(N)]
L = ['M', 'A', 'R', 'C', 'H']
dict_S = {}

for i in range(N):
    moji = S[i][0]
    if moji in L:
        if moji not in dict_S:
            dict_S[moji] = 1
        else:
            dict_S[moji] += 1

keys = len(dict_S.keys())

if keys < 3 or keys == None:
    print(0)
else:
    x = int(math.factorial(keys) / math.factorial(3) / math.factorial(keys - 3))
    for v in dict_S.values():
        if v >= 2 and keys > 3:
            x *= v
            x -= 1
        elif v >= 2:
            x *= v
    print(x)

Submission status: Wrong Answer

Solution code:
def factorial(n):
    res = 1
    for i in range(1, n + 1):
        res *= i
    return res


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


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

march = [0] * 5
for c in s:
    if c in 'MARCH':
        march['MARCH'.index(c)] += 1

k = sum(x > 0 for x in march)
if k < 3:
    print(0)
    exit()

ans = combination(k, 3)
for x in march:
    ans += combination(k - 1, 2) * max(x - 1, 0)

print(ans)

Submission status: Wrong Answer

Solution code:
import math


def combi(a, b):
    ans = math.factorial(a) / (math.factorial(a - b) * math.factorial(b))
    return ans


N = int(input())
S = [0] * 5

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

c = 0
N = 0
for i in range(5):
    N += S[i]
    if S[i] != 0:
        c += 1

if c <= 2:
    print(0)

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

Submission status: Wrong Answer

Solution code:
import math


def combi(a, b):
    ans = math.factorial(a) / (math.factorial(a - b) * math.factorial(b))
    return ans

N=int(input())
S=[0]*5

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

c=0
N=0
for i in range(5):
    N+=S[i]
    if S[i]!=0:
        c+=1

if c<=2:
    print(0)

else:
    NG=0
    for i in range(5):
        if S[i]>=3:
            NG=combi(S[i],3)+combi(S[i],2)*(N-3)
        elif S[i]==2:
            NG=combi(S[i],2)*(N-S[i])
    print(int(combi(N,3)-NG))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input() for i in range(n))
m=a=r=c=h=[]
mc=ac=rc=cc=hc=0
ans=1
for i in range(n):
    if s[i][0] == "M" and not s[i] in m:
        m.append(s[i])
        mc+=1
    elif s[i][0] == "A" and not s[i] in a:
        a.append(s[i])
        ac+=1
    elif s[i][0] == "R" and not s[i] in r:
        r.append(s[i])
        rc+=1
    elif s[i][0] == "C" and not s[i] in c:
        c.append(s[i])
        cc+=1
    elif s[i][0] == "H" and not s[i] in h:
        h.append(s[i])
        hc+=1
lis = [mc,ac,rc,cc,hc]
if sum(lis) == 0:
    print(0)
else:
    for i in range(5):
        if lis[i]>0:
            ans = ans*lis[i] 
    print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input() for i in range(n))
m=a=r=c=h=[]
mc=ac=rc=cc=hc=0
ans=1
for i in range(n):
    if s[i][0] == "M" and not s[i] in m:
        mc+=1
    elif s[i][0] == "A" and not s[i] in a:
        ac+=1
    elif s[i][0] == "R" and not s[i] in r:
        rc+=1
    elif s[i][0] == "C" and not s[i] in c:
        cc+=1
    elif s[i][0] == "H" and not s[i] in h:
        hc+=1
lis = [mc,ac,rc,cc,hc]
if sum(lis) == 0:
    print(0)
else:
    for i in range(5):
        if lis[i]>0:
            ans = ans*lis[i] 
    print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input() for i in range(n))
m=[]
a=[]
r=[]
c=[]
h=[]
ans=1
for i in range(n):
    if s[i][0] == "M" and not s[i] in m:
        m.append(s[i])
    elif s[i][0] == "A" and not s[i] in a:
        a.append(s[i])
    elif s[i][0] == "R" and not s[i] in r:
        r.append(s[i])
    elif s[i][0] == "C" and not s[i] in c:
        c.append(s[i])
    elif s[i][0] == "H" and not s[i] in h:
        h.append(s[i])
num=len(m)+len(a)+len(r)+len(c)+len(h)
if num == 0:
    print(0)
else:
    lis = [len(m),len(a),len(r),len(c),len(h)]
    for i in range(5):
        if lis[i]>0:
            ans = ans*lis[i] 
    print(ans)

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
s=list(input() for i in range(n))
m=[]
a=[]
r=[]
c=[]
h=[]
for i in range(n):
    if s[i][0] == "M" and not s[i] in m:
        m.append(s[i])
    elif s[i][0] == "A" and not s[i] in a:
        a.append(s[i])
    elif s[i][0] == "R" and not s[i] in r:
        r.append(s[i])
    elif s[i][0] == "C" and not s[i] in c:
        c.append(s[i])
    elif s[i][0] == "H" and not s[i] in h:
        h.append(s[i])
num = len(m)+len(a)+len(r)+len(c)+len(h)
print(math.factorial(num)/(math.factorial(3)*math.factorial(num)))

Submission status: Wrong Answer

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

from collections import Counter

c = Counter(s)

c = list(c.values())

c_len = len(c)

ans = 0
for i in range(c_len):
    for j in range(i+1, c_len):
        for k in range(j+1, c_len):
            ans += c[i] * c[j] * c[k]

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = [input() for _ in range(N)]
m = 0
a = 0
r = 0
c = 0
h = 0
for t in S:
    if t[0] == "M":
        m += 1
    elif t[0] == "A":
        a += 1
    elif t[0] == "R":
        r += 1
    elif t[0] == "C":
        c += 1
    elif t[0] == "H":
        h += 1
if m == 0:
  m = 1
if a == 0:
  a = 1
if r == 0:
  r = 1
if c == 0:
  c = 1
if h == 0:
  h = 1
print(m*a*r*c*h)

Submission status: Wrong Answer

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

dic={}
for i in s:
    if i[0]=='M' or i[0]=='A' or i[0]=='R' or i[0]=='C' or i[0]=='H':
        if i[0] in dic:
            dic[i[0]]+=1
        else:
            dic[i[0]]=1
if len(dic)<3:
    ans=0
else:
    if len(dic)==3:
        ans = 1
        for i in dic.values():
            ans *=i
    elif len(dic)==4:
        ans = 4
        for i in dic.values():
            ans += 3*(i-1)
    else:
        ans = 10
        for i in dic.values():
            ans += 6*(i-1)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

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

cnt = 0
ans = 1

for v in d.values():
    if v >= 2:
        ans *= v
        cnt += 1
    elif v == 1:
        cnt += 1

if cnt < 3:
    print(0)
    exit()

if cnt == 3:
    print(ans)

if cnt == 4:
    print(4 + 3*(ans-1))

if cnt == 5:
    print(10 + 4*(ans-1))

Submission status: Wrong Answer

Solution code:
n = int(input())

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

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

cnt = 0
ans = 1

for v in d.values():
    if v >= 2:
        ans *= v
        cnt += 1
    elif v == 1:
        cnt += 1

print(cnt, ans)

if cnt < 3:
    print(0)
    exit()

if cnt == 3:
    print(ans)

if cnt == 4:
    print(4 + 3*(ans-1))

if cnt == 5:
    print(10 + 4*(ans-1))

Submission status: Wrong Answer

Solution code:
a=int(input())
lis=[input()[0] for i in range(a)]
lis2=[0,0,0,0,0]
dellist=[]
for m in lis:
  if m=="M":
    lis2[0]+=1
  elif m=="A":
    lis2[1]+=1
  elif m=="R":
    lis2[2]+=1
  elif m=="C":
    lis2[3]+=1
  elif m=="H":
    lis2[4]+=1
a=sum(lis2)
print(lis2,a)
def c3(a):
  return a*(a-1)*(a-2)/6
def c2(a):
  return  a*(a-1)/2
ans=c3(a)
for i in lis2:
  ans=ans-c3(i)-c2(i)*(a-i)
print(int(ans))

Submission status: Wrong Answer

Solution code:
import sys
from operator import mul
from functools import reduce

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

n = int(input())
s = []
for _ in range(n):
  _s = input()
  if _s[:1] == 'M':
    s.append('M')
  elif _s[:1] == 'A':
    s.append('A')
  elif _s[:1] == 'R':
    s.append('R')  
  elif _s[:1] == 'C':
    s.append('C')  
  elif _s[:1] == 'H':
    s.append('H')
if len(s) < 3:
  print(0)
  sys.exit()
t = cmb(len(s),3)
_m = s.count('M')
_a = s.count('A')
_r = s.count('R')
_c = s.count('C')
_h = s.count('H')

m,a,r,c,h = 0,0,0,0,0
if _m >= 2: m = cmb(_m,2)*(_a+_r+_c+_h)
if _a >= 2: a = cmb(_a,2)*(_m+_r+_c+_h)
if _r >= 2: r = cmb(_r,2)*(_m+_a+_c+_h)
if _c >= 2: c = cmb(_c,2)*(_m+_a+_r+_h)
if _h >= 2: h = cmb(_h,2)*(_m+_a+_r+_c)

print(t-m-a-r-c-h)

Submission status: Wrong Answer

Solution code:
N = int(input())
nM = 0
nA = 0
nR = 0
nC = 0
nH = 0
for i in range(N):
  S = input()
  if S[0] == "M": nM += 1
  if S[0] == "A": nA += 1
  if S[0] == "R": nR += 1
  if S[0] == "C": nC += 1
  if S[0] == "H": nH += 1
r = 0
r += nM*nA*nR
r += nM*nA*nC
r += nM*nA*nH
r += nM*nR*nC
r += nM*nR*nH
r += nA*nR*nC
r += nA*nR*nH
r += nA*nC*nH
r += nR*nC*nH
print(r)

Submission status: Wrong Answer

Solution code:
n=int(input())
m=0
a=0
r=0
c=0
h=0
for i in range(n):
	x=input()
	if x[0]=="M":
		m+=1
	elif x[0]=="A":
		a+=1
	elif x[0]=="R":
		r+=1
	elif x[0]=="C":
		c+=1
	elif x[0]=="H":
		h+=1
s=[m,a,r,c,h]
s.sort()
r=0
q=(sum(s)*(sum(s)-1)*(sum(s)-2))//6
for i in range(5):
	if s[i]>1:
		r+=((s[i]*(s[i]-1))//2)*(sum(s)-2)
print(q-r)

Submission status: Wrong Answer

Solution code:
import collections
import itertools

N = int(input())
s = [input()[0] for _ in range(N)]
c = collections.Counter(s)

# print(c)

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

# print(l)

ans = sum([c[i[0]] * c[i[1]] * c[i[2]] for i in l])

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s={"M":0,"A":0,"R":0,"C":0,"H":0}
for i in range(n):
    v=input()
    if v[0] in s:
        s[v[0]]+=1
l=list(s.values())
print(l)
sum=0
for a in range(5):
    for b in range(a+1,5):
        for c in range(b+1,5):
            sum+=l[a]*l[b]*l[c]         
print(sum)

Submission status: Wrong Answer

Solution code:
n=int(input())

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


for i in range(n):
    v=input()
    if v[0] in s:
        s[v[0]]+=1
sum=0
for a in s.keys():
    for b in s.keys():
        for c in s.keys():
            if a==b or a==c or b==c:
                continue
            sum+=s[a]*s[b]*s[c]
           
print(sum)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
def main():
    N = int(input())
    s = []
    
    for i in range(N):
        tmp = input()
        s.append(tmp)
        
    m = 0
    a = 0
    r = 0
    c = 0
    h = 0
    for i in s:
        if s[0] == "M":
            m += 1
        elif s[0] == "A":
            a += 1
        elif s[0] == "R":
            r += 1
        elif s[0] == "C":
            c += 1
        elif s[0] == "H":
            h += 1
            
    ans = 0
    total = (a*m*c) + (a*m*r) + (a*m*h) + (a*c*r) + (a*c*h) + (a*r*h) + (m*c*r) + (m*c*h) + (m*r*h) + (c*r*h)
            
    print(total)
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
N = int(input())
dict = {
    "M":0,
    "A":0,
    "R":0,
    "C":0,
    "H":0
}
S = []
for _ in range(N):
    S = input()
    if S[0] == "M":
        dict[S[0]] += 1
    elif S[0] == "A":
        dict[S[0]] += 1
    elif S[0] == "R":
        dict[S[0]] += 1
    elif S[0] == "C":
        dict[S[0]] += 1
    elif S[0] == "H":
        dict[S[0]] += 1

ans = 0
ans += dict["M"] * dict["A"] * dict["R"]
ans += dict["M"] * dict["A"] * dict["C"]
ans += dict["M"] * dict["A"] * dict["H"]
ans += dict["M"] * dict["R"] * dict["C"]
ans += dict["M"] * dict["R"] * dict["H"]
ans += dict["M"] * dict["C"] * dict["H"]
ans += dict["A"] * dict["R"] * dict["C"]
ans += dict["A"] * dict["C"] * dict["H"]
ans += dict["A"] * dict["C"] * dict["H"]
ans += dict["R"] * dict["C"] * dict["H"]
print(ans)

Submission status: Wrong Answer

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

import math

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

x = ['M','A','R','C','H']
a = [0]*5

def c(n,r):
    return math.factorial(n)/(math.factorial(n-r)*math.factorial(r))
for i in s:
    if i[0] in x:
        a[x.index(i[0])] += 1
s = 0
t = 1
u = 0
for i in a:
    if i != 0:
        s += 1
    if i > 1:
        t *= i
        u += 1
if s <= 2:
    print(0)
else:
    ans = c(s,3)
    ans *= t
    if s > 3:
        ans -= u
    print(int(ans))

Submission status: Wrong Answer

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

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

ans = 0
print(num_dic)
for i, j, k in itertools.combinations(num_dic.keys(), 3):
    ans += num_dic[i] * num_dic[j] * num_dic[k]
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = "MARCH"
cnt = [0, 0, 0, 0, 0]
for i in range(n):
    name = input()
    for j in range(len(s)):
        if name[0] == s[j]:
            cnt[j] += 1
cnt = [c for c in cnt if c > 0]
if len(cnt) < 3:
    print(0)
elif len(cnt) == 3:
    print(cnt[0]*cnt[1]*cnt[2])
elif len(cnt) == 4:
    ans = 0
    for i in range(4):
        ans += cnt[0]*cnt[1]*cnt[2]*cnt[3]//cnt[i]
    print(ans)
else:
    ans = 0
    for i in range(5):
        cnt_4 =[cnt[_] for _ in range(5) if _ != i]
        for j in range(4):
            ans += cnt[0]*cnt[1]*cnt[2]*cnt[3]//cnt[j]
    print(ans//2)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = "MARCH"
cnt = [0, 0, 0, 0, 0]
for i in range(n):
    name = input()
    for j in range(len(s)):
        if name[0] == s[j]:
            cnt[j] += 1
cnt = [c for c in cnt if c > 0]
if len(cnt) < 3:
    print(0)
elif len(cnt) == 3:
    print(cnt[0]*cnt[1]*cnt[2])
elif len(cnt) == 4:
    ans = 0
    for i in range(4):
        ans += cnt[0]*cnt[1]*cnt[2]*cnt[3]//cnt[i]
    print(ans)
else:
    ans = 0
    for i in range(5):
        cnt_4 =[cnt[_] for _ in range(5) if _ != i]
        for j in range(4):
            ans += cnt[0]*cnt[1]*cnt[2]*cnt[3]//cnt[i]
    print(ans)

Submission status: Wrong Answer

Solution code:
def resolve():
	n=int(input())
	x=0
	s=[input() for __ in range(n)]
	m=[i for i in s if i[0]=='M']
	a=[i for i in s if i[0]=='A']
	r=[i for i in s if i[0]=='R']
	c=[i for i in s if i[0]=='C']
	h=[i for i in s if i[0]=='H']
	
	mm=len(m)
	aa=len(a)
	rr=len(r)
	cc=len(c)
	hh=len(h)
	
	print(mm*aa*(rr+cc+hh) + mm*rr*(cc+hh)+mm*cc*hh+aa*rr*(cc+hh)+rr*cc*hh)
resolve()

Submission status: Wrong Answer

Solution code:
n = int(input())
m = 0
a = 0
r = 0
c = 0
h = 0
cnt = 0
for i in range(n):
  p = input()
  if p[0] == "M":
    m += 1
  if p[0] == "A":
    a += 1
  if p[0] == "R":
    r += 1
  if p[0] == "C":
    c += 1
  if p[0] == "H":
    h += 1
if m > 0:
  cnt += 1
if a > 0:
  cnt += 1
if r > 0:
  cnt += 1
if c > 0:
  cnt += 1
if h > 0:
  cnt += 1
  
if cnt < 3:
  print(0)
else:
  print(m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*h + a*c*h + r*c*h)

Submission status: Wrong Answer

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

ans_list = [0 for i in range(5)]
carList = ['M', 'A', 'R', 'C', 'H']
for s in S:
    for i, c in enumerate(carList):
        if s[0] == c:
            ans_list[i] += 1

ans_list = [a for a in ans_list if a != 0]
ans = 1
for i, v in enumerate(ans_list):
    ans *= v

if len(ans_list) < 3:
    print(0)
elif len(ans_list) == 3:
    print(ans_list[0]*ans_list[1]*ans_list[2])
elif len(ans_list) == 4:
    tmp = 0
    for i, v in enumerate(ans_list):
        tmp += ans // v
    print(tmp)
else:
    tmp = 0
    for i in range(5):
        for j in range(5):
            if i != j:
                tmp += ans // (ans_list[i]*ans_list[j])
    print(tmp)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = [input()[0] for i in range(N)]
li = [S.count("M"),S.count("A"),S.count("R"),S.count("C"),S.count("H")]
li = list(filter(lambda x:x>0, li))
ans = 1
for i in li:
    ans *= i
print(0 if sum(li) < 3 else ans if len(li)==3 else ans*4 if len(li)==4 else ans*10)

Submission status: Wrong Answer

Solution code:
import itertools

n = int(input())
M=0
A=0
R=0
C=0
H=0
cnt=0
for _ in range(n):
    newstr = str(input())
    if newstr[0] == "M":
        M+=1
    elif  newstr[0] == "A":
        A+=1
    elif  newstr[0] == "R":
        R+=1
    elif  newstr[0] == "C":
        C+=1
    elif  newstr[0] == "H":
        H+=1
lis = [M,A,R,C,H]
#print(lis)
lis2 = [_ for _ in lis if _ != 0]
#print(lis2)
if len(lis2) < 3:
    print(0)
else:
    for i in itertools.combinations(lis2, r=3):
        cnt += i[0] * i[1] * i[2]
print(cnt)

Submission status: Wrong Answer

Solution code:
cnt = 0
N = int(input())
S = {'M':0,'A':0,'R':0,'C':0,'H':0}
march = ['M','A','R','C','H']
for i in range(N):
    s = input()[0]
    if s in march:
        S[s] += 1

for i in range(5**2):
    tmp = []
    for j in range(5):
        if (i >> j) & 1:
            tmp.append(S[march[j]])
    if len(tmp) == 3:
        cnt += tmp[0] * tmp[1] * tmp[2]

print(cnt)

Submission status: Wrong Answer

Solution code:
cnt = 0
N = int(input())
S = {'M':0,'A':0,'R':0,'C':0,'H':0}
march = ['M','A','R','C','H']
for i in range(N):
    s = input()[0]
    if s in march:
        S[s] += 1

for i in range(5**2):
    tmp = []
    for j in range(N):
        if (i >> j) & 1:
            tmp.append(S[march[j]])
    if len(tmp) == 3:
        cnt += tmp[0] * tmp[1] * tmp[2]

print(cnt)

Submission status: Wrong Answer

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)

N = len(S)
ret = []
for i in range(N**2):
    tmp = []
    for j in range(N):
        if (i >> j) & 1:
            tmp.append(S[j])
    if len(tmp) == 3:
        ret.append(tmp)

judge = True
cnt = 0
for r in ret:
    tmp = []
    for name in r:
        if not name[0] in tmp:
            tmp.append(name[0])
        else:
            judge = False
            break
    if judge:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
cnt=[0]*5
check='MARCH'
for i in range(n):
  s=input()
  for j in range(5):
    if s[0]==check[j]:
      cnt[j]+=1
      break
ans=0
for i in range(5):
  for j in range(i+1,5):
    for k in range(j+1,5):
      ans+=cnt[i]*cnt[j]*cnt[k]

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
s=[input() for i in range(n)]
c=[0,0,0,0,0]
cnt=0
ans=0
for i in s:
	if i[0] == 'M':
		c[0]+=1
	elif i[0] == 'A':
		c[1]+=1
	elif i[0] == 'R':
		c[2]+=1
	elif i[0] == 'C':
		c[3]+=1
	elif i[0] == 'H':
		c[4]+=1
	else:
		cnt+=1
if cnt > 2:
	print(ans)
	sys.exit()
for i in range(5):
	for j in range(i+1,5):
		for k in range(j+1,5):
			ans+=c[i]*c[j]*c[k]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
alphabets = ["M","A","R","C","H"]
names = list()
counter_dict = {"M":0,"A":0,"R":0,"C":0,"H":0}

for i in range(n):
    names.append(input())
    
for name in names:
    if list(name)[0] in alphabets:
        counter_dict[list(name)[0]] += 1
        
temp = 0
ans = 1
for value in counter_dict.values():
    if value != 0:
        ans *= value
        temp = 1
else:
    if temp == 0:
        print(0)
    else:
        print(ans)

Submission status: Wrong Answer

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-2):
    selected = [""] * 2
    selected[0] = S[i][0]
    for k in range(i+1, N-1):
        if S[k][0] in selected:
            continue
        selected[1] = S[k][0]
        for t in range(k+1, N):
            if S[t][0] in selected:
                continue
            cnt += 1
print(cnt)

Submission status: Wrong Answer

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

S1=[]
for i in S:
    if i[0] == "M":
        if i not in S1:
            S1.append(i)
    if i[0] == "A":
        if i not in S1:
            S1.append(i)
    if i[0] == "R":
        if i not in S1:
            S1.append(i)
    if i[0] == "C":
        if i not in S1:
            S1.append(i)
    if i[0] == "H":
        if i not in S1:
            S1.append(i)

dict={}
for i in range(len(S1)):
    x=S1[i]
    if x[0] in dict:
        dict[x[0]] += 1
    else:
        dict[x[0]] = 1

if len(dict) < 3:
    print("0")

if len(dict) == 3:
    list3 = list(dict.values())
    print(list3[0]*list3[1]*list3[2])

if len(dict) == 4:
    list4 = list(dict.values())
    print((list4[0]*list4[1]*list4[2])+(list4[0]*list4[2]*list4[3])+(list4[1]*list4[2]*list4[3])+(list4[0]*list4[1]*list4[3]))

if len(dict) == 5:
    a = list(dict.values())
    print((a[0]+a[1]+a[2])+(a[0]+a[2]+a[3])+(a[0]+a[3]+a[4])+(a[0]+a[1]+a[3])+(a[0]+a[1]+a[4])+(a[1]+a[2]+a[3])+(a[1]+a[2]+a[4])+(a[1]+a[3]+a[4])+(a[2]+a[3]+a[4])+(a[0]+a[2]+a[4]))

Submission status: Wrong Answer

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

S1=[]
for i in S:
    if i[0] == "M":
        S1.append(i)
    if i[0] == "A":
        S1.append(i)
    if i[0] == "R":
        S1.append(i)
    if i[0] == "C":
        S1.append(i)
    if i[0] == "H":
        S1.append(i)

dict={}
for i in range(len(S1)):
    x=S1[i]
    if x[0] in dict:
        dict[x[0]] += 1
    else:
        dict[x[0]] = 1

if len(dict) < 3:
    print("0")
    exit()

if len(dict) == 3:
    list3 = list(dict.values())#listって書かないとだめ
    print(list3[0]*list3[1]*list3[2])
    exit()

if len(dict) == 4:
    list4 = list(dict.values())
    print((list4[0]*list4[1]*list4[2])+(list4[0]*list4[2]*list4[3])+(list4[1]*list4[2]*list4[3])+(list4[0]*list4[1]*list4[3]))
    exit()

if len(dict) == 5:
    a = list(dict.values())
    print((a[0]+a[1]+a[2])+(a[0]+a[2]+a[3])+(a[0]+a[3]+a[4])+(a[0]+a[1]+a[3])+(a[0]+a[1]+a[4])+(a[1]+a[2]+a[3])+(a[1]+a[2]+a[4])+(a[1]+a[3]+a[4])+(a[2]+a[3]+a[4])+(a[0]+a[2]+a[4]))

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
ans=0
for i in range(3):
  for j in range(i,4):
    for k in range(j,5):
      ans+=m[i]*m[j]*m[k]
print(ans)

Submission status: Wrong Answer

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

s_list = [0, 0, 0, 0, 0]
for i in range(n):
    if s_[i][0] == 'M':
        s_list[0] += 1
    elif s_[i][0] == 'A':
        s_list[1] += 1
    elif s_[i][0] == 'R':
        s_list[2] += 1
    elif s_[i][0] == 'C':
        s_list[3] += 1
    elif s_[i][0] == 'H':
        s_list[4] += 1

import math
counter = 0
s_list_nonzero = []
for i in range(5):
    if s_list[i] != 0:
        counter += 1
        s_list_nonzero.append(s_list[i])

if counter < 3:
    print(0)
elif counter == 4:
    print(s_list_nonzero[0] * s_list_nonzero[1] * s_list_nonzero[2] +
            s_list_nonzero[0] * s_list_nonzero[1] * s_list_nonzero[3] +
            s_list_nonzero[0] * s_list_nonzero[2] * s_list_nonzero[3] +
            s_list_nonzero[1] * s_list_nonzero[2] * s_list_nonzero[3])
elif counter == 5:
    print(s_list_nonzero[0] * s_list_nonzero[1] * s_list_nonzero[2] +
            s_list_nonzero[0] * s_list_nonzero[1] * s_list_nonzero[3] +
            s_list_nonzero[0] * s_list_nonzero[1] * s_list_nonzero[4] +
            s_list_nonzero[0] * s_list_nonzero[2] * s_list_nonzero[3] +
            s_list_nonzero[0] * s_list_nonzero[2] * s_list_nonzero[4] +
            s_list_nonzero[0] * s_list_nonzero[3] * s_list_nonzero[4] +
            s_list_nonzero[1] * s_list_nonzero[2] * s_list_nonzero[3] +
            s_list_nonzero[1] * s_list_nonzero[2] * s_list_nonzero[4] +
            s_list_nonzero[1] * s_list_nonzero[3] * s_list_nonzero[4] +
            s_list_nonzero[2] * s_list_nonzero[3] * s_list_nonzero[4])

Submission status: Wrong Answer

Solution code:
N = int(input())

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

all = []
c0 = 0
count = 0
for name0 in S[c0:]:
    ans = [[],[],[]]
    cand = ['M','A','R','C','H']
    if cand.count(name0[0]):
        cand.remove(name0[0])
        ans[0] = name0
        c1 = c0 + 1
        for name1 in S[c1:]:
            if cand.count(name1[0]):
                cand.remove(name1[0])
                ans[1] = name1
                c2 = c1 + 1
                for name2 in S[c2:]:
                    if cand.count(name2[0]):
                        cand.remove(name2[0])
                        ans[2] = name2
                        count += 1
                        if set(ans) not in all:
                            all.append(set(ans))
                            
print(count+1)

Submission status: Wrong Answer

Solution code:
import math
def nCr(n,r):
    f = math.factorial
    return f(n) // f(r) // f(n-r)
dic = {}
check = set(list("MARCH"))
N = int(input())
for i in range(N):
    n = list(input())
    if n[0] in check:
        dic.setdefault(n[0], 0)
        dic[n[0]] += 1
if len(dic.keys()) < 3:
  print(0)
  exit()
ans = nCr(len(dic.keys()) , 3)
for k, v in dic.items():
    if v > 1:
      ans = ans * v - (len(dic.keys()) - 3)
print(ans)

Submission status: Wrong Answer

Solution code:
def solve(string):
    n, *s = string.split()
    num = [len([True for _s in s if _s[0] == _i]) for _i in "M A R C H".split()]
    ans = 0
    for i in range(5):
        for j in range(i + 1, 5):
            for k in range(j + 1, 5):
                ans += num[i] * num[j] * num[k]
    return str(ans)


if __name__ == '__main__':
    print(solve(input()))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=set()

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

L=len(S)

print(L*(L-1)*(L-2)//6)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from itertools import combinations
march = list("MARCH")
march = dict(zip(march, march))
N = int(input())
S = [march.get(input()[0], -1) for _ in range(N)]
cnt = Counter(S)
ans = 0
for comb in combinations("MARCH", 3):
    maxv = 0
    for c in comb:
        if cnt[c] == 0:
            break
        maxv = max(maxv, cnt[c])
    else:
        ans += maxv
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
S = [input() for i in range(n)]
a = 0
b = 0
c = 0
d = 0
e = 0
for s in S:
    if s[0]=='M':
        a += 1
    elif s[0]=='A':
        b += 1
    elif s[0]=='R':
        c += 1
    elif s[0]=='C':
        d += 1
    elif s[0]=='H':
        e += 1
print(a*b*c+a*b*d+a*b*e+b*c*d+b*c*e+c*d*e+a*c*d+a*c*e+c*d*e+b*d*e)

Submission status: Wrong Answer

Solution code:
l=[0]*5
n=int(input())
for i in range(n):
  s=input()
  a=s[0]
  if a=='M':
    l[0]+=1
  elif a=='A':
    l[1]+=1
  elif a=='R':
    l[2]+=1
  elif a=='C':
    l[3]+=1
  elif a=='H':
    l[4]+=1
if n==4 and sum(l)==0:
  exit()
print(l[0]*l[1]*l[2]
  +l[0]*l[1]*l[3]
  +l[0]*l[1]*l[4]
  +l[0]*l[2]*l[3]
  +l[0]*l[2]*l[4]
  +l[0]*l[3]*l[4]
  +l[1]*l[2]*l[3]
  +l[1]*l[2]*l[4]
  +l[1]*l[3]*l[4]
  +l[2]*l[3]*l[4])

Submission status: Wrong Answer

Solution code:
from itertools import*;print(sum(p*q*r for p,q,r in list(combinations([len(list(v))for k,v in groupby(sorted(s[0]for s in open(0).readlines()[1:]))],3))))