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())
s = [input() for _ in range(N)]
count = [0]*5
for i in s:
    if i[0]=="M":
        count[0] += 1
    elif i[0]=="A":
        count[1] += 1
    elif i[0]=="R":
        count[2] += 1
    elif i[0]=="C":
        count[3] += 1
    elif i[0]=="H":
        count[4] += 1
ans = 1
i = 0
h = len(count)
while i < h:
    if count[i]==0:
        count.pop(i)
        h -= 1
        i = 0
    else:
        i += 1

if len(count)==0:
    ans = 0
elif len(count)<=3:
    ans = 1
    for i in count:
        ans *=  i
else:
    ans = 0
    for bit in range(1<<len(count)):
        a = []
        b = 1
        for i in range(len(count)):
            mask = 1<<i
            if mask&bit:
                a.append(count[i])
                b *= count[i] 
        if len(a)==3:
            ans +=b
    
print(ans)

Submission status: Wrong Answer

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

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


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


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

Submission status: Wrong Answer

Solution code:
mod = 10**9 + 7
def cmb(n,r,mod):
	a=1
	b=1
	r = min(r,n-r)
	for i in range(r):
		a = a*(n-i)%mod
		b = b*(i+1)%mod
	return a*pow(b,mod-2,mod)%mod

N = int(input())
march = []
for _ in range(N):
  H =str(input())
  if H[0] == 'M' or H[0] == 'A' or H[0] == 'R' or H[0] == 'C' or H[0] == 'H':
    march.append(H[0])
march = ''.join(march)
m = march.count('M')
a = march.count('A')
r = march.count('R')
c = march.count('C')
h = march.count('H')
l = [m,a,r,c,h]
L = []
for i in range(len(l)):
  if l[i] > 0:
    L.append(l[i])
if len(L) < 3:
  print(0)
  exit()
else:
  ans = cmb(len(L),3,mod)
  for i in range(len(L)):
    if L[i] > 1:
      ans = ans*L[i]-(len(L)-3)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

from collections import Counter


def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)


def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res


n = int(readline())
s = [input()[0] for i in range(n)]
memo = list(Counter(s).items())
check = ['M', 'A', 'R', 'C', 'H']
cnt = 0
ans = 0
cnt_v = 0
for x, y in memo:
    if x in check:
        ans += y
        if y > 1:
            cnt += 1
            cnt_v += y
if ans == 0:
    print(0)
else:
    print(combination(ans, 3) - (ans * cnt - cnt_v))

Submission status: Wrong Answer

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

from collections import Counter


def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)


def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res


n = int(readline())
s = [input()[0] for i in range(n)]
memo = list(Counter(s).items())
check = ['M', 'A', 'R', 'C', 'H']
cnt = 0
ans = 0
cnt_v = 0
for x, y in memo:
    if x in check:
        ans += y
        if y > 1:
            cnt += 1
            cnt_v += y
print(combination(ans, 3) - (ans * cnt - cnt_v))

Submission status: Wrong Answer

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

from collections import Counter
from scipy.misc import comb

n = int(readline())
s = [input()[0] for i in range(n)]
memo = list(Counter(s).items())
check = ['M', 'A', 'R', 'C', 'H']
cnt = 0
ans = 0
for x, y in memo:
    if x in check:
        ans += y
        if y > 1:
            cnt += n - y
print(comb(ans, 3) - cnt)

Submission status: Wrong Answer

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

march_cnt =  [i for i in march_l if i != 0]
ans = 0
prod = 1

for i in march_cnt:
    prod *= i

if len(march_cnt) > 3:
    for i in march_cnt:
        ans += prod//i
elif len(march_cnt) == 3:
    ans = prod
else:
    ans = 0
        
print(ans)

Submission status: Wrong Answer

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

march_cnt =  [i for i in march_l if i != 0]
ans = 0
prod = 1

for i in march_cnt:
    prod *= i

if len(march_cnt) > 3:
    for i in march_cnt:
        ans += prod//i
        print(ans)
elif len(march_cnt) == 3:
    ans = prod
else:
    ans = 0
        
print(ans)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
lst = [0,0,0,0,0]

for i in range(n):
    name = input()
    if name[0]=="M":
        lst[0]+=1
    elif name[0]=="A":
        lst[1]+=1
    elif name[0]=="R":
        lst[2]+=1
    elif name[0]=="C":
        lst[3]+=1
    elif name[0]=="H":
        lst[4]+=1
# print(lst)

P = [0,0,0,0,0,1,1,2]
Q = [1,1,1,2,2,2,2,3]
R = [2,3,4,3,4,3,4,4]

ans = 0
for i in range(8):
    ans += lst[P[i]]*lst[Q[i]]*lst[R[i]]
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
n=int(input())
s=[input()[0] for _ in range(n)]
a=[]
for i in ['M','A','R','C','H']:
  a+=[s.count(i)]
print(a)
ans=0
for i in combinations(a,3):
  ans+=i[0]*i[1]*i[2]
print(ans)

Submission status: Wrong Answer

Solution code:
# import bisect
from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():

    N=int(input())
    S=[str(input())[0] for i in range(N)]
    for i in S:
        if i != 'M' and i != 'A' and i != 'R' and i != 'C' and i != 'H':
            S.remove(i)

    SS=Counter(S)
    SSS=SS.items()

    ans=len(SSS)*(len(SSS)-1)*(len(SSS)-2)//6
    cnt=0
    temp=1
    for i in SSS:
        if i[1]!=1:
            temp*=i[1]
            ans*=i[1]
            cnt+=1
    minus=(len(SSS)-cnt)*(len(SSS)-1-cnt)*(len(SSS)-2-cnt)//6*(temp-1)
    ans-=minus
    print(ans)


resolve()

Submission status: Wrong Answer

Solution code:
# import bisect
from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():

    N=int(input())
    S=[str(input())[0] for i in range(N)]
    for i in S:
        if i != 'M' and i != 'A' and i != 'R' and i != 'C' and i != 'H':
            S.remove(i)

    SS=Counter(S)
    SSS=SS.items()
    from operator import mul
    from functools import reduce


    # 未読
    def comb(n, r):
        if n < r:
            return 0
        else:
            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


    ans=comb(len(SSS),3)
    cnt=0
    temp=1
    for i in SSS:
        if i[1]!=1:
            temp*=i[1]
            ans*=i[1]
            cnt+=1
    minus=comb(len(SSS)-cnt,3)*(temp-1)
    ans-=minus
    print(ans)


resolve()

Submission status: Wrong Answer

Solution code:
from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():

    N=int(input())
    S=[str(input())[0] for i in range(N)]
    for i in S:
        if i != 'M' and i != 'A' and i != 'R' and i != 'C' and i != 'H':
            S.remove(i)

    SS=Counter(S)
    SSS=SS.items()
    from operator import mul
    from functools import reduce


    # 未読
    def comb(n, r):
        if n < r:
            return 0
        else:
            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


    ans=comb(len(SSS),3)
    cnt=0
    for i in SSS:
        if i[1]!=1:
            ans*=i[1]
            cnt+=1
    minus=comb(len(SSS)-cnt,3)
    ans-=minus
    print(ans)


resolve()

Submission status: Wrong Answer

Solution code:
from itertools import (
    accumulate,  # 累積和のイテレータ
    groupby,  # 値をkey,同じ値の集まりをgroup
    permutations,  # 順列
    combinations,  # 組み合わせ
    product,  # 重複あり順列（直積）
)

n = int(input())
Sm, Sa, Sr, Sc, Sh = set(), set(), set(), set(), set()
for _ in range(n):
    s = input()
    if s[0]=='M':
        Sm.add(s)
    elif s[0]=='A':
        Sa.add(s)
    elif s[0]=='R':
        Sr.add(s)
    elif s[0]=='C':
        Sc.add(s)
    elif s[0]=='H':
        Sh.add(s)

ans = 0
S = [len(Sm), len(Sa), len(Sr), len(Sc), len(Sh)]

for v1, v2, v3 in combinations(S, 3):
    print(v1, v2, v3)
    ans += v1*v2*v3

print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
n, *S = open(0).read().split()
n = int(n)
march = []
for c in 'MARCH':
    march.append(len([s for s in S if s[0] == c]))
print(march)
ans = 0
for a, b, c in combinations(march, 3):
    ans += a*b*c
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
n, *S = open(0).read().split()
n = int(n)
march = []
for c in 'MARCH':
    march.append(len([s for s in S if s[0] == c]))
print(march)
ans = 0
for a, b, c in combinations(march, 3):
    if a*b*c != 0:
        print(a,b,c)
    ans += a*b*c
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
import collections

N = int(input()) 

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

AA = set(A)
C = collections.Counter(A)
print(sum(C[a]*C[b]*C[c] for a, b, c in combinations(AA, 3)))

Submission status: Wrong Answer

Solution code:
from itertools import combinations
import collections

N = int(input()) 
A = []
for i in range(N):
    A.append(input()[0])
c = collections.Counter(A)

if len(set(A)) >= 3:
    ans = 1
    for i in c.values():
        ans *= i
else:
    ans = 0

print(ans)

Submission status: Wrong Answer

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

import itertools


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

    result = []
    for comb in list(itertools.combinations(S, 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: Wrong Answer

Solution code:
n=int(input())
c=0
d=set()
for i in range(n):
    s=input()
    if s[0]==('M' or 'A' or 'C' or 'R' or 'H'):
        if s not in d:
            c+=1
            d.add(s)
ans=0
if c<3:
    print(ans)
else:
    ans=(c*(c-1)*(c-2))//6

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = [input() for i in range(N)]
s = set(S)
s = list(s)
ans = 0
import itertools

# seq = ('a', 'b', 'c', 'd', 'e')
# ptr = list(itertools.combinations(seq,3)) # 組み合わせ列挙 5C3
l = []
for i in range(len(s)):
    if s[i][0] in "MARCH":
        ans += 1
        l.append(s[i])
r = []
if ans == 0:
    print(ans)
else:
    ptr = list(itertools.combinations(l,3)) # 組み合わせ列挙 5C3
    for i in range(len(ptr)):
        if ptr[i][0][0] != ptr[i][1][0] and ptr[i][2][0] != ptr[i][1][0] and ptr[i][2][0] != ptr[i][0][0]:
            r.append(ptr[i])

        # for j in range(3):
        #     print(ptr[i][j][0])
        #     if ptr[i][j][0] != ptr[i][j][1] and ptr[i][j][0] != ptr[i][j][2] and ptr[i][j][1] != ptr[i][j][2]:
        #         # print(len(ptr))
        #         # print(ptr[i])
        #         r.append(ptr[i])
                # break
        # r.append(ptr[i])

print(len(r))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [input() for _ in range(N)]
B = list()
num_M=0
num_A=0
num_R=0
num_C=0
num_H=0
for i in A:
  if i[0]=='M':
    num_M+=1
    continue
  if i[0]=='A':
    num_A+=1
    continue
  if i[0]=='R':
    num_R+=1
    continue
  if i[0]=='C':
    num_C+=1
    continue
  if i[0]=='H':
    num_H+=1
    continue
print(num_M*num_A*num_R+num_M*num_A*num_C+num_M*num_A*num_H+num_M*num_R*num_C+num_M*num_R*num_H+num_M*num_C*num_H+num_A*num_R*num_C+num_A*num_R*num_H+num_R*num_C*num_H)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from scipy.misc import comb
#ID
b = defaultdict(lambda: len(b))
n = int(input())
hed = ["M","A","R","C","H"]
for i in hed:
    b[i] 
li = [0]*5
for _ in range(n):
    a = input()
    if a[0] in hed:
        li[b[a[0]]] += 1

c = [i for i in li if i != 0]
print(int(comb(len(c),3))*2 -int(comb(len(c)-1,3)))

Submission status: Wrong Answer

Solution code:
n=int(input())

l=[]
for i in range(n):
    l+=[input()[0]]

march=[0]*5
for j in range(n):
    if l[j]=='M':
        march[0]+=1
    elif l[j]=='A':
        march[1]+=1
    elif l[j]=='R':
        march[2]+=1
    elif l[j]=='C':
        march[3]+=1
    elif l[j]=='H':
        march[4]+=1
print(march)

from itertools import combinations
ans=0
for x,y,z in combinations(march, 3):
    ans+=x*y*z

print(ans)

Submission status: Wrong Answer

Solution code:
#pypyは内包表記使わない
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    N = int(input())
    M = 0
    A = 0
    R = 0
    C = 0
    H = 0
    for _ in range(N):
        s = input().rstrip()
        if s[0]=='M':
            M += 1
        elif s[0]=='A':
            A += 1
        elif s[0]=='R':
            R += 1
        elif s[0]=='C':
            C += 1
        else:
            H += 1
    res = 0
    l = [M, A, R, C, H]
    for a, b, c in combinations(l, 3):
        res += a*b*c
    print(res)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

result = 0
for i in range(5):
    result += name_count[i]*name_count[(i+1)%5]*name_count[(i+2)%5]
print(result)

Submission status: Wrong Answer

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

result = 0
for i in range(5):
    result += name_count[i]*name_count[(i+1)%5]*name_count[(i+1)%5]
print(result)

Submission status: Wrong Answer

Solution code:
n=int(input())
name=[]
lis=['M','A','R','C','H']
for i in range(n):
    s=input()
    if s[0] in lis and s not in name:
        name.append(s)
#純粋にnC3を計算すればおｋ
p=len(name)
print(p*(p-1)*(p-2)//6)

Submission status: Wrong Answer

Solution code:
import math

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

c=['M','A','R','C','H']
d={}
n=int(input())
for i in range(n):
  word=input()
  if word[0] in c: 
    if word[0] in d: d[word[0]]+=1
    else: d[word[0]]=1

m = sum(d.values())
max = combinations_count(m,3) if m>=3 else 0

sub = 0
for i in d.values():
  if i>=3: 
   	sub += combinations_count(i, 3)
  if i>=2: 
    sub += combinations_count(i, 2) *(len(d)-1)

print(max - sub)

Submission status: Wrong Answer

Solution code:
import math

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

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

m = sum(d.values())
max = combinations_count(m,3) if m>=3 else 0
sub = 0
for i in d.values():
  if i>2: sub += combinations_count(i, 3)
  elif i>1: sub += combinations_count(i, 2) * (m-2)

print(max - sub)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from itertools import combinations

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

con = []
for c in 'MARCH':
    if c in lc:
        con.append(lc[c])

ans = 0
for a, b, c in combinations(con, 3):
    ans += a * b * c

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=[input() for _ in range(n)]
#march="MARCH"
march=["M","A","R","C","H"]
count=[0]*5
for i in range(n):
    for j in range(5):
        if s[i][0]==march[j]:
            count[j]+=1
            
def f(a,b,c):
    return a*b*c

c0=count[0]
c1=count[1]
c2=count[2]
c3=count[3]
c4=count[4]
ans=f(c0,c1,(c2+c3+c4))+f((c0+c1),c2,(c3+c4))+f((c0+c2),c3,c4)+f(c1,c2,c4)
print(ans)

Submission status: Wrong Answer

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]])
    if len(se) <=2:
        break
    #print(master,se,master - se)
    if len(master - se) == 2:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import itertools
N=int(input())
S=list(str(input()) for i in range(N))
m,a,r,c,h=[0]*5
ans=0
if S[0]=="M":m+=1
if S[0]=="A":a+=1
if S[0]=="R":r+=1
if S[0]=="C":c+=1
if S[0]=="H":h+=1

x=[m,a,r,c,h]
for i in itertools.combinations(x,3):
  ans+=i[0]*i[1]*i[2]
print(ans)

Submission status: Wrong Answer

Solution code:

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

from collections import Counter
from itertools import combinations

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

for s in S:
  if s[0] in march:
    T.append(s[0])

counter = Counter(T)

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

base = len(list(combinations(counter.keys(), 3)))

for (key, value) in counter.most_common():
  base *= value
  if value > 1:
    keys = list(filter(lambda x: x != key, counter.keys()))
    base -= len(list(combinations(keys, 3)))

print(base)

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce


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


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

d = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
cnt = 0
for i in range(N):
    if Sn[i][0] not in {"M", "A", "R", "C", "H"}:
        continue
    d[Sn[i][0]] += 1
    cnt += 1

ans = cmb(cnt, 3) if cnt > 2 else 0
for k, v in d.items():
    if v >= 3:
        ans -= cmb(v, 3) + cnt-v
    elif v == 2:
        ans -= cnt-v

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N= int(input())
S = ['M','A','R','C','H']
C = [0]*5
for _ in range(N):
  X = (input())[0]
  if X in S:
    C[S.index(X)] += 1
print(C)

from itertools import permutations, combinations,combinations_with_replacement,product
L = list(combinations(range(5), 3))   #nCr
ans = 0
for i in L:
  ans += C[i[0]]*C[i[1]]*C[i[2]]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n=int(input())
S=[input().strip() for _ in range(n)]
a=[]

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


from collections import Counter
for s in S:
    if s[0] in ["M","A","R","C","H"]:
        a.append(s[0])

if len(a)==0:
    print(0)
    exit()

a=Counter(a)
#print(a)

asum=sum(a.values())
b=0
c=0
for i in a.values():
    if i ==1:
        continue
    if i==2:
        b+=asum-i
    if i>=3:
        b+=cmb(i,2)*(asum-i)
        c+=cmb(i,3)
print(cmb(asum,3)-b-c)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from itertools import combinations

n = int(input())
l = [input()[0] for _ in range(n)]
lc = Counter(l)
print(lc)

con = []
for c in "MARCH":
    if c in lc:
        con.append(lc[c])
ans = 0
for a, b, c in combinations(con, 3):
    ans += a * b * c
print(ans)

Submission status: Wrong Answer

Solution code:
def cmb(n, r):
    if n - r < r:
        r = n - r
    if r == 0:
        return 1
    if r == 1:
        return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


n = int(input())
s = [str(input()) for i in range(n)]
lists = []
for i in s:
    if i[0] == "M" or i[0] == "A" or i[0] == "R" or i[0] == "C" or i[0] == "H":
        lists.append(i[0])
if len(set(lists)) == 0:
    print(0)
    exit()
set_lists = list(set(lists))
ans = cmb(len(lists), 3)
sa = len(lists) - len(set_lists)
print(ans-(len(set_lists) - sa))

Submission status: Wrong Answer

Solution code:
def cmb(n, r):
    if n - r < r:
        r = n - r
    if r == 0:
        return 1
    if r == 1:
        return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


n = int(input())
s = [str(input()) for i in range(n)]
lists = []
for i in s:
    if i[0] == "M" or i[0] == "A" or i[0] == "R" or i[0] == "C" or i[0] == "H":
        lists.append(i[0])
if len(set(lists)) == 0:
    print(0)
    exit()
set_lists = list(set(lists))
ans = cmb(len(lists), 3)
print(ans-(len(set_lists) - 1))

Submission status: Wrong Answer

Solution code:
N = int(input())
cntM, cntA, cntR, cntC, cntH = 0, 0, 0, 0, 0
for i in range(N):
    s = input()
    if s[0] == "M":
        cntM += 1
    elif s[0] == "A":
        cntA += 1
    elif s[0] == "R":
        cntR += 1
    elif s[0] == "C":
        cntC += 1
    elif s[0] == "H":
        cntH += 1
Names = [cntM,cntA,cntR,cntC,cntH]
ans = 0
for i in range(3):
    for j in range(i+1,i+3):
        for k in range(j+1,j+3):
            if k <= 4:
                ans += Names[i]*Names[j]*Names[k]
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
N=int(input())
L = [str(input()) for i in range(N)]
count_M=0
count_A=0
count_R=0
count_C=0
count_H=0
for i in L:
    if i[0]=='M':count_M+=1
    elif i[0]=='A':count_A+=1
    elif i[0]=='R':count_R+=1
    elif i[0]=='C':count_C+=1
    elif i[0]=='H':count_H+=1
name_list=[count_M,count_A,count_R,count_C,count_H]
sum_list=list(combinations(name_list,3))
s_list=[i[0]*i[1]*i[2] for i in sum_list]
sum(s_list)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
S = [input() for i in range(N)]
print(S)
SI = [S[i][0] for i in range(N)]
cnt = collections.Counter(SI)
n = [cnt["M"],cnt["A"],cnt["R"],cnt["C"],cnt["H"]]
ans = 0
for i in range(3):
    for j in range(i+1,5):
        for k in range(j+1,5):
          ans += n[i]*n[j]*n[k]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N = int(input())
d = defaultdict(int)
for _ in range(N):
  s = input()
  if s[0] in 'MARCH':
    d[s[0]] += 1

if len(d.keys()) >= 3:
  ans = 1
  for c in d.values():
    ans *= c
else:
  ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N = int(input())
d = defaultdict(int)
for _ in range(N):
  s = input()
  if s[0] in 'MARCH':
    d[s[0]] += 1

if d:
  ans = 1
  for c in d.values():
    ans *= c
else:
  ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
#                         author:  kagemeka 
#                         created: 2019-11-06 16:52:04(JST)
import sys
# import collections
import math
# import string
# import bisect
# import re
# import itertools
# import statistics
import functools
import operator

def nCr(n, r):
    r = min(r, n - r)
    return functools.reduce(operator.mul, range(n, n-r, -1), 1) // math.factorial(r)

def main():
    n = int(sys.stdin.readline().rstrip())
    march = {l: 0 for l in 'MARCH'}

    for i in range(n):
        initial = sys.stdin.readline()[0]
        if initial in march:
            march[initial] += 1


    march = {k: v for k, v in march.items() if v != 0}
    
    if len(march) < 2:
        print(0)
        exit()

    s = sum(march.values())
    total_cmb = nCr(s, 3)

    for c in march.values():
        if c >= 2:
            total_cmb -= nCr(c, 2) * (len(march) - 1)
        if c >= 3:
            total_cmb -= nCr(c, 3)
    
    print(total_cmb)
        
if __name__ == "__main__":
    # execute only if run as a script
    main()

Submission status: Wrong Answer

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

print(M,A,R,C,H)

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())
M,A,R,C,H=0,0,0,0,0
for i in range(N):
    name=input()
    if name[0]=='M':
        M+=1
    elif name[0]=='A':
        A+=1
    elif name[0]=='R':
        R+=1
    elif name[0]=='C':
        C+=1
    elif name[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*C*H + A*C*H + R*C*H)

Submission status: Wrong Answer

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

ans=m*a*(r+c+h)+m*r*(c+h)+a*r*(c+h)+r*c*h
print(ans)