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: Accepted

Solution code:
n = int(input())
data = []
init = [0, 0, 0, 0, 0]
ans=0
for i in range(0, n):
    data.append(input())
    if data[i][0] == "M":
        init[0] += 1
    elif data[i][0] == "A":
        init[1] += 1
    elif data[i][0] == "R":
        init[2] += 1
    elif data[i][0] == "C":
        init[3] += 1
    elif data[i][0] == "H":
        init[4] += 1
ans+=init[0]*init[1]*init[2]
ans+=init[0]*init[1]*init[3]
ans+=init[0]*init[1]*init[4]
ans+=init[0]*init[2]*init[3]
ans+=init[0]*init[2]*init[4]
ans+=init[0]*init[3]*init[4]
ans+=init[1]*init[2]*init[3]
ans+=init[1]*init[2]*init[4]
ans+=init[1]*init[3]*init[4]
ans+=init[2]*init[3]*init[4]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

march = 'MARCH'
c = [0]*5
for _ in range(N):
    s = input()
    for i in range(5):
        if s.startswith(march[i]):
            c[i] += 1
            break

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

print(s)

Submission status: Accepted

Solution code:
N = int(input())

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

cnt = {}
for c in 'MARCH':
    cnt[c] = 0
for s in S:
    c = s[0]
    if c not in 'MARCH':
        continue
    cnt[c] += 1

# print(cnt)
s = 'MARCH'
ans = 0
for i in range(3**5):
    a = i % 5
    b = i // 5 % 5
    c = i // 25 % 5
    if a == b or b == c or c == a:
        continue

    ans += cnt[s[a]] * cnt[s[b]] * cnt[s[c]]

print(ans // 12)

Submission status: Accepted

Solution code:
import itertools
N = int(input())
S = [input()[0] for i in range(N)]
march = ["M", "A", "R", "C", "H"]
sum = 0
for c in list(itertools.combinations(march,3)):
    sum += S.count(c[0]) * S.count(c[1]) * S.count(c[2])
print(sum)

Submission status: Accepted

Solution code:
n = int(input())
s = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
# M A R C H
for i in [0]*n:
  t = input()
  if t[0] in s:
    s[t[0]] += 1
print(s['M']*(s['A']*(s['R']+s['C']+s['H'])+s['R']*(s['C']+s['H'])+s['C']*s['H']) + s['A']*(s['R']*(s['C']+s['H'])+s['C']*s['H'])+s['R']*s['C']*s['H'])

Submission status: Accepted

Solution code:
from itertools import combinations
n = int(input())
name = [0 for i in range(5)]
for i in range(n):
    a = input()
    if a[0] in "MARCH":
        name[list("MARCH").index(a[0])] += 1
ans = 0
for h, j, k in combinations("01234", 3):
    ans += (name[int(h)] * name[int(j)] * name[int(k)])
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math
from collections import Counter
N = int(input())

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

S_cnt = Counter(S)

cond = [['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']]

ans = 0
for li in cond:
    ans += S_cnt[li[0]] * S_cnt[li[1]] * S_cnt[li[2]]
print(ans)

Submission status: Accepted

Solution code:
import itertools

n = int(input())

s_dict = {'M': 0,
          'A': 0,
          'R': 0,
          'C': 0,
          'H': 0}

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

candidate = []
for combi in itertools.combinations(s_dict.keys(), 3):
    if s_dict[combi[0]] != 0 and s_dict[combi[1]] != 0 and s_dict[combi[1]] != 0:
            candidate.append(combi)
            
cnt = 0
for x in candidate:
    cnt += s_dict[x[0]] * s_dict[x[1]] * s_dict[x[2]]
    
print(cnt)

Submission status: Accepted

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

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string

N = int(input())
S = Counter()
for n in range(N):
    s = input()
    if s[0] in 'MARCH':
        S[s[0]] += 1

if len(S) < 3:
    print(0)
else:
    keys = S.keys()
    ans = 0
    for comb in combinations(keys, 3):
        ans += S[comb[0]] * S[comb[1]] * S[comb[2]]
    print(ans)

Submission status: Accepted

Solution code:
N = input()
C = [0]*5
for _ in range(N):
  s = raw_input()[0]
  if s in "MARCH":
    C["MARCH".index(s)] += 1
ans = 0
for i in range(5):
  for j in range(i):
    for k in range(j):
      ans += C[i]*C[j]*C[k]
print ans

Submission status: Accepted

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

ans = 0
m = 'MARCH'
for i in range(5):
  mi = m[i]
  for j in range(i+1, 5):
    mj = m[j]
    for k in range(j+1, 5):
      mk = m[k]
      ans += count.get(mi, 0) * count.get(mj, 0) * count.get(mk, 0)

print(ans)

Submission status: Accepted

Solution code:
import itertools

n = int(input())
names = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
for i in range(n):
    initial = input()[0]
    names[initial] = names.get(initial, 0) + 1

ans = 0
for a, b, c in itertools.combinations('MARCH', 3):
    ans += names[a] * names[b] * names[c]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
d = {'M':0,'A':0,'R':0,'C':0,'H':0}
march = 'MARCH'
for _ in range(n):
    s = input()
    if s[0] in march:
        d[s[0]] += 1
s = 0
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            s += d[march[i]]*d[march[j]]*d[march[k]]
print(s)

Submission status: Accepted

Solution code:
import itertools
n = int(input())
dic = {"M":0, "A":0, "R":0, "C":0, "H": 0}
R = ["M", "A", "R", "C", "H"]
for i in range(n):
    s = input()
    if s[0] in R:
        dic[s[0]] += 1

num = 0
for i, j, k in itertools.combinations(R, 3):
    num += dic[i]* dic[j] * dic[k]

print(num)

Submission status: Accepted

Solution code:
from collections import Counter
import itertools

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

ctr = Counter()
for s in src:
    ctr.update(s[0])

ans = 0
for ptn in itertools.combinations('MARCH',3):
    a,b,c = ptn
    ans += ctr[a] * ctr[b] * ctr[c]
print(ans)

Submission status: Accepted

Solution code:
n = int(raw_input())

d = [0]*5

for a in range(n):
  s = raw_input()
  if s[0] == "M":
    d[0] += 1
  elif s[0] == "A":
    d[1] += 1
  elif s[0] == "R":
    d[2] += 1
  elif s[0] == "C":
    d[3] += 1
  elif s[0] == "H":
    d[4] += 1

ans = 0
for a in range(0,3):
  for b in range(a+1,4):
    for c in range(b+1,5):
      ans += d[a]*d[b]*d[c]
print ans

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict
from itertools import combinations

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

con = []
for c in ('M', 'A', 'R', 'C', 'H'):
    k = d[c]
    if k:
        con.append(k)

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

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
from itertools import combinations

N = int(raw_input())
c = Counter(raw_input()[0] for _ in range(N))

ans = 0
for (l1, l2, l3) in combinations("MARCH", 3):
  ans += c[l1] * c[l2] * c[l3]

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
M, A, R, C, H = 0, 0, 0, 0 ,0
for i in range(N):
  s = input()
  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
ans = 0
ans += M*A*R
ans += M*A*C
ans += M*A*H
ans += M*R*C
ans += M*R*H
ans += M*C*H

ans += A*R*C
ans += A*R*H
ans += A*C*H

ans += R*C*H

print(ans)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    a = [S() for _ in range(n)]
    c = collections.defaultdict(int)
    for s in a:
        if s[0] in 'MARCH':
            c[s[0]] += 1

    r = 0
    t = 'MARCH'
    for i in range(5):
        for j in range(i+1,5):
            for k in range(j+1,5):
                r += c[t[i]] * c[t[j]] * c[t[k]]

    return r


print(main())

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
dic = [0] * 128
for i in range(n):
    s = ns()
    dic[ord(s[0])] += 1

x = [
    ord("M"),
    ord("A"),
    ord("R"),
    ord("C"),
    ord("H"),
]

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

Submission status: Runtime Error

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)
        
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: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
Mnum = 0
Anum = 0
Rnum = 0
Cnum = 0
Hnum = 0
for i in range(n):
  a = input()
  if a[0] == "M":Mnum+=1
  elif a[0] == "A":Anum+=1
  elif a[0] == "R":Rnum+=1
  elif a[0] == "C":Cnum+=1
  elif a[0] == "H":Hnum+=1
alist = [Mnum,Anum,Rnum,Cnum,Hnum]
from itertools import combinations
blist =list(combinations(alist,3))
from functools import reduce
sum = 0
for i in range(len(blist)):
  sum+=reduce(mul,blist)
print(sum)

Submission status: Runtime Error

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

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

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

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

print(ans)

Submission status: Runtime Error

Solution code:
import sys
import itertools

input = sys.stdin.readline

def main():
    common = common_function()
    N = int(input())
    l = ['M', 'A', 'R', 'C', 'H']
    m = [0]*5
    for _ in range(N):
        S = input()[:-1]
        Shead = S[0]
        for i, s0 in enumerate(l):
            if Shead == s0:
                m[i] += 1
                break
    ll = []
    for i, n in enumerate(m):
        if n >= 1:
            ll.append(l[i])
    if len(ll) <= 2:
        print(0)
        return
    ans = 0
    for i, j, k in itertools.combinations(ll, 3):
        ans += m[l.index(i)] * m[l.index(j)] * m[l.index(k)]

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
n=int(input())

march=[0]*5

march_dic={"M":0,"A":1,"R":2,"C":3,"H":4}

for i in range(n):
    name=input()
    if name[0] in "MARCH":
        march[march_dic[name[0]]]+=1

def count_type(march):
    ans=[]
    for i in march:
        if i!=0:
            ans.append(i)
    ans.sort()
    return n-march.count(0),ans

type_num,each_num=count_type(march)
if type_num<3:
    print(0)
else:
    ans=0
    for i in range(type_num-2):
        for j in range(i+1,type_num-1):
            for k in range(j+1,type_num):
                ans+=each_num[i]*each_num[j]*each_num[k]

    print(ans)

Submission status: Runtime Error

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

ans=0
for i,j,k in combinations('MARCH',3):
  ans+=d[i]*d[j]*d[k]

print(ans)

Submission status: Runtime Error

Solution code:
using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
      int n = int.Parse(ReadLine());
      List<string> s = new List<string>();
      
      for (int i=0;i<n;i++)
      {
        s.Add(ReadLine());
      }
      var hashSet = new HashSet<string>(s);
      s = hashSet.ToList();
      List<int> ans = new List<int>();
      
      for (int i=0;i<5;i++)
      {
        ans.Add(0);
      }
      
      for (int i=0;i<s.Count;i++)
      {
        if (s[i].Substring(0,1)=="M")
        {
          ans[0]+=1;
        }
        else if (s[i].Substring(0,1)=="A")
        {
          ans[1]+=1;
        }
        else if (s[i].Substring(0,1)=="R")
        {
          ans[2]+=1;
        }
        else if (s[i].Substring(0,1)=="C")
        {
          ans[3]+=1;
        }
        else if (s[i].Substring(0,1)=="H")
        {
          ans[4]+=1;
        }
      }
      int answ=0;
      for (int i=0;i<5;i++)
      {
        for (int j=i+1;j<5;j++)
        {
          for (int k=j+1;k<5;k++)
          {
            if (i!=j && j!=k && i!=k)
            {
              answ+=ans[i]*ans[j]*ans[k];
            }
          }
        }
      }
      WriteLine(answ);
    }
}

Submission status: Runtime Error

Solution code:
import itertools
n = int(input())
name = [0]*n
s = []
for i in range(n):
    st = input()
    if st[0] == 'M':
        name[0] += 1
    elif st[0] == 'A':
        name[1] += 1
    elif st[0] == 'R':
        name[2] += 1
    elif st[0] == 'C':
        name[3] += 1
    elif st[0] == 'H':
        name[4] += 1
    s.append(st)

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

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
md = {'M':0, 'A':0 , 'R':0, 'C':0, 'H':0}
for _ in range(n):
    s = input()
    if s[0] in md:
        md[s[0]] += 1

vs = []
for v in md.values():
    vs.append(v)

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

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
M_Dict = {"M":0,"A":0,"R":0,"C":0,"H":0}
for i in range(N):
    moji = str(input())
    if moji[0] in M_Dict.keys():
        M_Dict[moji[0]] += 1
M_Dict = {k: v for k, v in M_Dict.items() if v != 0}    
if len(M_Dict) < 3:
    ans = 0
else:
    ans = 0
    for k in itertools.combinations(list(M_Dict.keys()),3):
        ans += M_Dict[k[0]]*M_Dict[k[1]]*M_Dict[[2]]
    
print(ans)

Submission status: Runtime Error

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 N[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
kazu=!
if M==0:
  M+=1
if A==0:
  A+=1
if C==0:
  C+=1
if R==0:
  R+=1
if H==0:
  H+=1
print(M*A*C*R*H)

Submission status: Runtime Error

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]
else:    
    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: Runtime Error

Solution code:
import itertools

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

cnt = [0 for _ in range(5)]
for s in S:
    if s[0] == "M":
        cnt[0] += 1
    elif s[1] == "A":
        cnt[1] += 1
    elif s[2] == "R":
        cnt[2] += 1
    elif s[3] == "C":
        cnt[3] += 1
    elif s[4] == "H":
        cnt[4] += 1

ans = 0
for i, j, k in itertools.permutations(cnt, r=3):
    ans += i * j * k

print(ans)

Submission status: Runtime Error

Solution code:
import sys
import math
n = int(input())
s = [input() for m in range(n)]
march = ['M','A','R','C','H']
ans = []

for i in range(n):
	if s[i][0] in march:
		ans.append(s[i][0])
s_set = set(ans)
sl = len(s_set)
if sl == 0:
	print(0)
	sys.exit()
double_num = len(ans) - len(s_set)
factorial_num = math.factorial(sl) // (math.factorial(sl - 3) * math.factorial(3))
if sl <= 2:
	print(0)
	sys.exit()
elif sl == 3:
	print(factorial_num + 2*double_num)
	sys.exit()
elif sl == 4:
	print(factorial_num + 2*(double_num) -(1*double_num))
	sys.exit()
else:
	print(factorial_num + 2*double_num -(4 *double_num))
	sys.exit()

Submission status: Runtime Error

Solution code:
import sys
import math
n = int(input())
s = [input() for m in range(n)]
march = ['M','A','R','C','H']
ans = []

for i in range(n):
	if s[i][0] in march:
		ans.append(s[i][0])
s_set = set(ans)
sl = len(s_set)
if sl == 0:
	print(0)
	sys.exit()
double_num = len(ans) - len(s_set)
factorial_num = math.factorial(sl) // (math.factorial(sl - 3) * math.factorial(3))
if sl <= 2:
	print(0)
	sys.exit()
elif sl == 3:
	print(factorial_num * 2*double_num)
	sys.exit()
elif sl == 4:
	print(factorial_num *2*(double_num) -(1*double_num))
	sys.exit()
else:
	print(factorial_num + 2*double_num -(4 *double_num))
	sys.exit()

Submission status: Runtime Error

Solution code:
import sys
import math
n = int(input())
s = [input() for m in range(n)]
march = ['M','A','R','C','H']
ans = []

for i in range(n):
	if s[i][0] in march:
		ans.append(s[i][0])
s_set = set(ans)
sl = len(s_set)
double_num = len(ans) - len(s_set)
factorial_num = math.factorial(sl) // (math.factorial(sl - 3) * math.factorial(3))
if sl <= 2:
	print(0)
	sys.exit()
elif sl == 3:
	print(factorial_num + factorial_num*double_num)
	sys.exit()
elif sl == 4:
	print(factorial_num + factorial_num*(double_num) -(1*double_num))
	sys.exit()
else:
	print(factorial_num + factorial_num*double_num -(4 *double_num))
	sys.exit()

Submission status: Runtime Error

Solution code:
import itertools
n = int(input())
names = [input() for i in range(n)]
names = [i for i in names if i[0] in "MARCH"]


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

Submission status: Runtime Error

Solution code:
N = int(input())
name = [0]*5
ans = 0
for i in range(N):
    a = input()
    if a[0] == 'M': name[0] += 1
    elif a[0] == 'A': name[1] += 1
    elif a[0] == 'R': name[2] += 1
    elif a[0] == 'C': name[3] += 1
    elif a[0] == 'H': name[4] += 1
if sum(name) < 3:
    print(0)
else:
    for i in combinations(name, 3):
        ans += i[0]*i[1]*i[2]
    print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
dic = {}
for c in "MARCH":
    dic[c] = 0
myset = set(list("MARCH"))
for _ in range(N):
    c = input()[0]
    if c in myset:
        dic[c] += 1

res = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            res += dic["MARCH"[i]] * dic["MARCH"[j]] * dic["MARCH"[k]]
print(res)

Submission status: Runtime Error

Solution code:
n = int(input())
# M,A,R,C,H
num = [0] * 5
check_list = ['M','A','R','C','H']
for _ in range(n):
    s = input()
    for i, c in enumerate(check_list):
        if s[0] == c:
            num[i]+=1
            break
ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            ans += num[i]*num[j]*num[k]
print(ans)

Submission status: Runtime Error

Solution code:
from math import factorial

def convination(n, r):
    a = factorial(n) / factorial(r) / factorial(n - r)
    return int(a)

n = int(input())
march = [0]*5

for i in range(n):
  temp = input()
  if temp[0] == "M":
    march[0] += 1
  elif temp[0] == "A":
    march[1] += 1 
  elif temp[0] == "R":
    march[2] += 1 
  elif temp[0] == "C":
    march[3] += 1 
  elif temp[0] == "H":
    march[4] += 1
    
total = sum(march)

if total <= 2:
  print(0)
  quit()
else:
  ans = convination(total, 3)
  for i in range(5):
    if march[i] >= 2:
      ans -= (total-march[i])*convination(march[i], 2)
      if march[i] >= 3:
        ans -= convination(march[i], 3)
print(ans)

Submission status: Runtime Error

Solution code:
from math import factorial

def convination(n, r):
    a = factorial(n) / factorial(r) / factorial(n - r)
    return int(a)

n = int(input())
march = [0]*5

for i in range(n):
  temp = input()
  if temp[0] == "M":
    march[0] += 1
  elif temp[0] == "A":
    march[1] += 1 
  elif temp[0] == "R":
    march[2] += 1 
  elif temp[0] == "C":
    march[3] += 1 
  elif temp[0] == "H":
    march[4] += 1
    
total = sum(march)

if total <= 2:
  print(0)
  quit()
else:
  ans = convination(total, 3)
  for i in range(5):
    if march[i] >= 2:
      ans -= (total-march[i])*convination(march[i], 2)
      if march[i] >= 3:
        ans -= convination(matrch[i], 3)
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())

march = 'MARCH'
mdict = {s:0 for s in march}

for i in range(N):
  S = input()
  mdict[S[0]] += 1
  
lst = [mdict[key] for key in mdict]
ans = 0
for i in range(3):
  for j in range(i+1, 4):
    for k in range(j+1, 5):
      ans += lst[i] * lst[j] * lst[k]
      
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
from scipy.special import comb

n = int(input())
a = []
for _ in range(n):
    b = list(map(str,input()))
    a.append(b)

ans = [0]*5

for i in range(n):
    tmp = a[i][0]
    if tmp == "M":
        ans[0] += 1
    elif tmp == "A":
        ans[1] += 1
    elif tmp == "R":
        ans[2] += 1
    elif tmp == "C":
        ans[3] += 1
    elif tmp == "H":
        ans[4] += 1
    else:
        continue

cnt = []
for j in range(len(ans)):
    if ans[j] == 0:
        continue
    else:
        cnt.append(ans[j])
l = 0
for k in range(len(cnt)):
    if cnt[k] > 1:
        l += cnt[k] - 1

cnt.sort()
print(cnt)
if len(cnt) <= 2:
    print(0)
elif len(cnt) == 3:
    print(np.prod(cnt))
elif len(cnt) == 4:
    print((cnt[0]*cnt[1]*cnt[2])+(3*cnt[3]))
else:
    print((cnt[0]*cnt[1]*cnt[2])+(3*cnt[3])+(6*cnt[4]))

Submission status: Runtime Error

Solution code:
import itertools

n = int(input())

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

ans = 0
for a,b,c in list(itertools.combinations(l,3)):
    ans += a*b*c

print(ans)

Submission status: Runtime Error

Solution code:
import itertools

n = int(input())

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

ans = 0
for a in list(itertools.combinations(l,3)):
    c = 1
    for i in a:
        c *=i
    ans += c

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
from itertools
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:
    ans = 0
    for l in list(itertools.combinations(d.values(), 3)):
        ans += reduce(np.multiply, l)
    print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
S=[list(map(int,input().split())) for i in range(N)]
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: Runtime Error

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(s)
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: Runtime Error

Solution code:
from math import factorial
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(s)
while i < h:
    if count[i]==0:
        count.pop(i)
        h -= 1
    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: Runtime Error

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

ans = 0
for x in range(3):
  for y in range(x+1, N-1):
    for z in range(y+1, N):
      ans += S[x] * S[y] * S[z]
print(ans)

Submission status: Runtime Error

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 L == []:
  print(0)
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: Runtime Error

Solution code:
from collections import Counter

n = int(input())
c = Counter()
for i in range(n):
    tmp = input().strip()
    if tmp[0] in ['M', 'A', 'R', 'C', 'H']:
        c[tmp[0]] += 1

result = 0
for v in itertools.permutations(c.values(), 3):
    result += v[0] * v[1] * v[2]

print(result // 6)

Submission status: Runtime Error

Solution code:
from itertools import combinations as c
n=int(input())
s=[input() for _ in range(n)]
m=[m1 for m1 in s if s.startswith('M')]
a=[a1 for a1 in s if s.startswith('A')]
r=[r1 for r1 in s if s.startswith('R')]
c=[c1 for c1 in s if s.startswith('C')]
h=[h1 for h1 in s if s.startswith('H')]
march=[len(m),len(a),len(r),len(c),len(h)]
print(sum(i*j*k for i, j, k in c(march, 3)))