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

Solution code:
import math
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 = list(len(m),len(a),len(r),len(c),len(h))
    ans = ans*lis[i] for i in range(5)
    print(ans)

Submission status: Runtime Error

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:
        li4 = []
        for i in dic.values():
            li4.append(i)
        ans = li4[0]*li4[1]*li4[2]+li4[0]*li4[1]*li4[3]+li4[0]*li4[2]*li4[3]+li4[1]*li4[2]*li4[3]
    else:
        li4 = []
        for i in dic.values():
            li5.append(i)
        ans =li5[0]*li5[1]*li5[2]+li5[0]*li5[1]*li5[3]+li5[0]*li5[1]*li5[4]+li5[0]*li5[2]*li5[3]+li5[0]*li5[2]*li5[4]+li5[0]*li5[3]*li5[4]+li5[1]*li5[2]*li5[3]+li5[1]*li5[2]*li5[4]+li5[1]*li5[3]*li5[4]+li5[2]*li5[3]*li5[4]
print(ans)

Submission status: Runtime Error

Solution code:
# ABC109 C - Skip
n,k = map(int,input().split())
x = list(map(int,input().split()))
ans = 0
t = 0
 
def gcd(a,b):
  while b:
    a,b = b,a%b
  return abs(a)
 
for i in range(n):
    t = abs(x[i]-k)
    ans = gcd(ans,t)
print(ans)

Submission status: Runtime Error

Solution code:
from itertools import*;N,*S=open(0);print(sum(a*b*c for a,b,c in combinations(sum(1for s in S if s[0]==c)for c in"MARCH",3)))

Submission status: Runtime Error

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())
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')

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

Solution code:
from collections import Counter
from itertools import combinations, reduce

import operator

GOOD_LETTERS = "MARCH"
PEOPLE = 3

n = int(input())
c = Counter()

for _ in range(n):
  first = input()[0]
  if first in GOOD_LETTERS:
    c.update(first)
    
ways = 0
for tup in combinations(GOOD_LETTERS, PEOPLE):
  ways += reduce(operator.mul, [c[ch] for ch in tup], 1)

print(ways)

Submission status: Runtime Error

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

march = [0] * 5

for i in range(n):
    if s[i][0] == 'M':
        march[0] += 1
    elif s[i][0] == 'A':
        march[1] += 1
    elif s[i][0] == 'R':
        march[2] += 1
    elif s[i][0] == 'C':
        march[3] += 1
    elif s[i][0] == 'H':
        march[4] += 1
        
ans = 0
        
for i in range(n):
    for j in range(n):
        for k in range(n):
            if i >= j or i >= k or j >= k:
                continue
            ans += march[i] * march[j] * march[k]
            
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
march = {'m': 0, 'a': 0, 'r': 0, 'c': 0, 'h': 0}
for i in range(n):
  s = input()[0]
  try:
    march[s] += 1
  except:
    pass
ans = 0

for key1 in march.keys():
  for key2 in march.keys():
    if key1 != key2:
      for key3 in march.keys():
        if key3 != key1 and key3 != key2:
          ans += key1 * key2 * key3
print(ans)

Submission status: Runtime Error

Solution code:
import sys
input=sys.stdin.readline

h = {}
for c in "MARCH":
    h[c] = 0

n = int(input())
for i in range(n):
    s = input().strip()
    h[s[0]] += 1
#print(h)

import itertools
ans = 0
for i,j,k in itertools.combinations("MARCH", 3):
    ans += h[i]*h[j]*h[k]
print(ans)

Submission status: Runtime Error

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

Solution code:
N = int(input())
names_dic = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
FIRST = ('M', 'A', 'R', 'C', 'H')
for _ in range(N):
  nams = input()
  if name[0] in FIRST:
    names_dic[name[0]] += 1
ans = 0
for i in range(5):
  for j in range(i+1, 5):
    for k in range(j+1, 5):
      ans += names_dic[FIRST[i]]*names_dic[FIRST[j]]*names_dic[FIRST[k]]
print(ans)

Submission status: Runtime Error

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*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)
            
    print(total)
	
if __name__ == "__main__":
	main()

Submission status: Runtime Error

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 += 1e
            
    ans = 0
    total = (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)
            
    print(total)
	
if __name__ == "__main__":
	main()

Submission status: Runtime Error

Solution code:
N=int(input())
S=[]
for _ in range(N):
    S.append(list(input()))
# print(S)

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

for s in S:
    if s[0] in ['M','A','R','C','H']:
        count[s[0]] += 1

# print(count)

H=['M','A','R','C','H']
res = 0
for i in range(0,N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            cnt = count[H[i]] * count[H[j]] * count[H[k]]
            # print(i,j,k,cnt)
            res += cnt

print(res)

Submission status: Runtime Error

Solution code:
# 人数を入力する
N = int(input())
# 名前を入力する
S = [input() for _ in range(N)]
# 単語をwordとする
word = "MARCH"
# 単語の文字数をsとする
n = len(word)
# 単語の各文字を頭文字とする人数を格納する辞書を初期化する
dic_initial = dict()
for letter in word:
    dic_initial[letter] = 0
# 単語の各文字を頭文字とする人数を調べる
for i in range(N):
    # 頭文字が単語の各文字のいずれかである場合
    if S[i][0] in dic_initial:
        # dic_initial内の人数を更新する
        dic_initial[S[i][0]] += 1
# 人の選び方の組み合わせの数を初期化する
ans = 0
# 3つの文字の組み合わせ全てについて、人の選び方の組み合わせの数を調べる
for p in range(n - 2):
    # 単語の頭からp番目の文字を頭文字とする人の数をnum_pとする
    num_p = dic_initial[word[p]]
    # num_pが0の場合、以降の処理は行わず、次の繰り返しに移る
    if num_p == 0:
        continue
    for q in range(p + 1, n - 1):
        num_q = dic_initial[word[q]]
        if num_q == 0:
            continue
        for r in range(q + 1, n):
            ans += num_p * num_q *num_r
# 出力する
print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
lines = []
for i in range(N):
    tmp = input()[0]
    if tmp in ["M","A","R","C","H"]:lines.append(tmp)

def recl(persons, tmp, count):
    if len(tmp) == 3 and len(list(set(tmp))) == 3:
        count[0] += 1
        return

    for idx, person in enumerate(persons):
        if len(persons) < 1:break
        recl( persons[idx+1:len(persons)] , tmp + [person], count)
        
count = [0]
recl(lines ,[] , count)
print(count[0])

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
lines = []
for i in range(N):
    lines.append(input())

def recl(persons, tmp, count):
    if len(tmp) == 3 and len(list(set(tmp))) == 3:
        count[0] += 1
        return

    for idx, person in enumerate(persons):
        if len(persons) < 1:break
        recl( persons[idx+1:len(persons)] , tmp + [person], count)
        
count = [0]
recl(list(filter(lambda a:a in ["M","A","R","C","H"], map(lambda a:a[0] ,lines))) ,[] , count)
print(count[0])

Submission status: Runtime Error

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

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

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

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

Submission status: Runtime Error

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

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

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

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

Submission status: Runtime Error

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

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

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

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

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;


int main()
{
    int n; cin >> n;
    int count[5] = {0};//[0]:M, [1]:A, [2]:R, [3]:C, [4]:H

    for(int i = 0; i < n; i++){
        string s; cin >> s;
        if(s[0] == 'M') count[0]++;
        if(s[0] == 'A') count[1]++;
        if(s[0] == 'R') count[2]++;
        if(s[0] == 'C') count[3]++;
        if(s[0] == 'H') count[4]++;
    }

    ll ans = 0;
    for (int i = 0; i < 5; i++){
        for(int j = i + 1; j < 5; j++){
            for(int k = j + 1; k < 5; k++){
                ans += count[i] * count[j] * count[k];
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Submission status: Runtime Error

Solution code:
from itertools import combinations

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

m = []
a = []
r = []
c = []
h = []
for i in range(N):
    if S[i][0] == 'M':
        m.append(S[i])
    elif S[i][0] == 'A':
        a.append(S[i])
    elif S[i][0] == 'R':
        r.append(S[i])
    elif S[i][0] == 'C':
        c.append(S[i])
    elif S[i][0] == 'H':
        h.append(S[i])

cnt = []
cnt.append(m.count)
cnt.append(a.count)
cnt.append(r.count)
cnt.append(c.count)
cnt.append(h.count)

com = list(combinations(range(5), 3))

ans = 0
for i in com:
    ans += cnt[i[0]]*cnt[i[1]]*cnt[i[2]]
print(ans)

Submission status: Runtime Error

Solution code:
import itertools as ite
N=int(input())
C=[0]*(N+1)
J="MARCH"
for i in range(N):
    C[J.find(input()[0])]+=1
ans=0
for i,j,k in list(ite.combinations(range(5),3)):
    ans+=C[i]*C[j]*C[k]
print(ans)

Submission status: Runtime Error

Solution code:
import itertools as ite
N=int(input())
C=[0]*N
J="MARCH"
for i in range(N):
    C[J.find(input()[0])]+=1
ans=0
for i,j,k in list(ite.combinations(range(5),3)):
    ans+=C[i]*C[j]*C[k]
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
m = 0
a = 0
r = 0
c = 0
h = 0
cnt = 0
for i in range(s):
  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: Runtime Error

Solution code:
n = int(input())
s = []
m = 0
a = 0
r = 0
c = 0
h = 0
cnt = 0
for i in range(s):
  a = input()
  if a[0] == "M":
    m += 1
  if a[0] == "A":
    a += 1
  if a[0] == "R":
    r += 1
  if a[0] == "C":
    c += 1
  if a[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: Runtime Error

Solution code:
from collections import combinations

n = int(input())

count = {x:0 for x in "MARCH"}

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

sum_count = 0
for a, b, c in combinations("MARCH", 3):
  sum_count += count[a] * count[b] * count[c]

print(sum_count)

Submission status: Runtime Error

Solution code:
#https://atcoder.jp/contests/abc089/tasks/abc089_c
import itertools
N = int(input())
S = [input() for _ in range(N)]
march = [0]*N
ans = 0
for s in S:
    if s[0] == "M":
        march[0] +=1
    if s[0] == "A":
        march[1] +=1
    if s[0] == "R":
        march[2] +=1
    if s[0] == "C":
        march[3] +=1
    if s[0] == "H":
        march[4] +=1

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

Submission status: Runtime Error

Solution code:
from collections import Counter
N = int(input())
S = [input() for i in range(N)]
S = [s[0] for s in S if s[0] in 'MARCH']
counter = Counter(S)
if len(counter) < 3:
  print(0)
else:
  cnt = 0
  mar = 'MARCH'
  for a in range(0,3):
    if mar[a] not in counter:
      continue
    for b in range(a+1, min(a+1+3, N-1)):
      if mar[b] not in counter:
        continue
      for c in range(b+1, min(b+1+3, N)):
        if mar[c] not in counter:
          continue
        # print(mar[a], mar[b], mar[c])
        cnt += counter[mar[a]] * counter[mar[b]] * counter[mar[c]]
  print(cnt)

Submission status: Runtime Error

Solution code:
from collections import Counter
N = int(input())
S = [input() for i in range(N)]
S = [s[0] for s in S if s[0] in 'MARCH']
counter = Counter(S)
if len(counter) < 3:
  print(0)
else:
  cnt = 0
  mar = 'MARCH'
  for a in range(0,3):
    if mar[a] not in counter:
      continue
    for b in range(a+1, min(a+1+3, N)):
      if mar[b] not in counter:
        continue
      for c in range(b+1, min(b+1+3, N)):
        if mar[c] not in counter:
          continue
        cnt += counter[mar[a]] * counter[mar[b]] * counter[mar[c]]
  print(cnt)

Submission status: Runtime Error

Solution code:
N = int(input())
S = [input() for i in range(N)]
march = {"M":0, "A":0, "R":0, "C":0, "H":0}

for i in S:
    if i[0] in march:
        march[i[0]] += 1

ans = 0
for first, second, third in combinations(march.values(), 3):
    ans += first * second * third

print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
m=a=r=c=h=0
ls
for i in range(n):
    s=input()
    if s[0]=='M':
        m+=1
    elif a[0]=='A':
        a+=1
    elif a[0]=='R':
        r+=1
    elif a[0]=='C':
        c+=1
    elif a[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:
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 100000000
#define MOD 1000000007

typedef  long long ll;

using namespace std;

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

int gcd(long long int a,long long int b){
    long long int r;
    if(a < b){
        int tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r != 0){
        r = a % b;
        a = b;
        b = r;
    }
    return r;
}

void Integer_factorization(ll factor[],ll n){
    ll a = 2;
    bool flag = false;
    for(int p = 2;p*p <= n;p++){
        while(n%p == 0){
            n/=p;
            factor[p]++;
        }
    }
    if(n!=1)  factor[n]++; //prime num
}

void ys(){
    cout << "Yes" << endl;
}

void yb(){
    cout << "YES" << endl;
}

void ns(){
    cout << "No" << endl;
}

void nb(){
    cout << "NO" << endl;
}


void solve(void){
   ll n;
   cin >> n;
   ll d[5] = {0};
   int a[10] = {0,0,0,0,0,0,1,1,1,2};
   int b[10] = {1,1,1,2,2,3,2,2,3,3};
   int c[10] = {2,3,4,3,4,4,3,4,4,4};

   rep(i,0,n){
       string s;
       cin >> s;
       if(s[0] == 'M') d[0]++;
       if(s[0] == 'A') d[1]++;
       if(s[0] == 'R') d[2]++;
       if(s[0] == 'C') d[3]++;
       if(s[0] == 'H') d[4]++;
   }
   ll ans = 0;
   rep(i,0,10){
       ans += d[a[i]]*d[b[i]]*d[c[i]]; 
   }
   
   cout << ans <<endl;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}

Submission status: Runtime Error

Solution code:
N = int(input())
l = [0] * N
march = 'MARCH'
for i in range(N):
    S = input()
    for j in range(len(march)):
        if S[0] == march[j]:
            l[j] += 1

tmp = []
lenl = len(l)
for i in range(lenl):
    for j in range(i + 1, lenl):
        for k in range(j + 1, lenl):
           tmp.append(l[i]*l[j]*l[k])

print(sum(tmp))

Submission status: Runtime Error

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

Solution code:
one = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
n=int(input())
for i in range(n):
  one[input()[0]] += 1
m,a,r,c,h=one['M'],one['A'],one['R'],one['C'],one['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: Runtime Error

Solution code:
from itertools import*;print(sum(p*q*r for p,q,r in combinations([list(s[0]for s in open(0).readlines()).count(s)for s in"MARCH"],3)))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def is_tasai(S):
    appare_set = set([])
    for s in S:
        if s in appare_set:
            return False
        appare_set.add(s)
    return True

table = {}
def comb(n, r):
    if (n, r) in table:
        return table[(n, r)]
    if n == r:
        table[(n, r)] = 1L
        return 1L
    if r == 0:
        table[(n, r)] = 1L
        return 1L
    if n == 0:
        return 0L
    table[(n, r)] = comb(n-1, r-1)+ comb(n-1, r)
    return table[(n, r)]


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    initial_dict = {}
    initial_dict["M"] = 0
    initial_dict["A"] = 0
    initial_dict["R"] = 0
    initial_dict["C"] = 0
    initial_dict["H"] = 0

    for i in range(N):
        input_raw = read_func().strip().split()
        if input_raw[0][0] in initial_dict:
            initial_dict[input_raw[0][0]] += 1
    M = 0
    for s in initial_dict:
        M += initial_dict[s]
    remove_num = 0L
    for s in initial_dict:
        remove_num += comb(initial_dict[s], 2) * (M - initial_dict[s])
        remove_num += comb(initial_dict[s], 3)
    print comb(M, 3) - remove_num


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def is_tasai(S):
    appare_set = set([])
    for s in S:
        if s in appare_set:
            return False
        appare_set.add(s)
    return True

table = {}
def comb(n, r):
    if (n, r) in table:
        return table[(n, r)]
    if n == r:
        table[(n, r)] = 1L
        return 1L
    if r == 0:
        table[(n, r)] = 1L
        return 1L
    if n == 0:
        return 0L
    table[(n, r)] = comb(n-1, r-1)+ comb(n-1, r)
    return table[(n, r)]


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    initial_dict = {}
    initial_dict["M"] = 0
    initial_dict["A"] = 0
    initial_dict["R"] = 0
    initial_dict["C"] = 0
    initial_dict["H"] = 0

    for i in range(N):
        input_raw = read_func().strip().split()
        if input_raw[0][0] in initial_dict:
            initial_dict[input_raw[0][0]] += 1
    M = 0
    for s in initial_dict:
        M += initial_dict[s]
    remove_num = 0
    for s in initial_dict:
        remove_num += comb(initial_dict[s], 2) * (M - 2)
    print comb(M, 3) - remove_num



if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#encoding:utf-8

import math
import itertools

n = int(input())
s = []
for i in range(n):
    s.append(str(input()))

chosen_names = {"m":0,"a":0,"r":0,"c":0,"h":0}

for name in s:
    if name[0] == "M":
        chosen_names["m"] += 1
    elif name[0] == "A":
        chosen_names["a"] += 1
    elif name[0] == "R":
        chosen_names["r"] += 1
    elif name[0] == "C":
        chosen_names["c"] += 1
    elif name[0] == "H":
        chosen_names["h"] += 1

answer = 0
capitals = list("march")
capital_set = itertools.com
binations(capitals,3)
for capital in capital_set:
    answer += chosen_names[capital[0]] * chosen_names[capital[1]] * chosen_names[capital[2]]


print(answer)



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

Submission status: Runtime Error

Solution code:
import sys, math, itertools
input = sys.stdin.readline

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


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

m_set = len({cand for cand in S if ((cand[0] == 'M')) })
a_set = len({cand for cand in S if ((cand[0] == 'A')) })
r_set = len({cand for cand in S if ((cand[0] == 'R')) })
c_set = len({cand for cand in S if ((cand[0] == 'C')) })
h_set = len({cand for cand in S if ((cand[0] == 'H')) })
set_elements_num = [m_set,a_set,r_set,c_set,h_set]
set_elements_num.remove(0)

# print(set_elements_num)
comb = 0
for i, elements_num in enumerate(set_elements_num):
    last_elements = set_elements_num[i+1:]
    # print(last_elements)
    last_elements_comb = list(itertools.combinations(last_elements,2))
    for elements in last_elements_comb:
        local_comb = elements_num
        for x in elements:
            local_comb *= x
        comb += local_comb

print(comb)

Submission status: Runtime Error

Solution code:
from itertools import combinations
N = int(input())
names = {}
for _ in range(N):
    S = input()
    if S[0] in 'MARCH':
        if S[0] not in names:
            names[S[0]] = 1
        else:
            names[S[0]] += 1
comb = len(names)
if comb <= 2:
    print(0)
elif comb == 3:
    ret = 1
    for v in names.values():
        ret *= v
    print(ret)
elif comb == 4:
    tmp = 1
    for v in names.values():
        tmp *= v
    ret = 0
    for v in names.values():
        ret += tmp // v
    print(ret)
else:
    ret = 0
    for comb in combinations('MARCH', 3):
        tmp = 1
        for c in comb:
            tmp *= names[c]
        ret += comb
    print(ret)

Submission status: Runtime Error

Solution code:
from itertools import combinations
N = int(input())
names = {}
for _ in range(N):
    S = input()
    if S[0] in 'MARCH':
        if S[0] not in names:
            names[S[0]] = 1
        else:
            names[S[0]] += 1
comb = len(names)
if comb <= 2:
    print(0)
elif comb == 3:
    ret = 1
    for v in names.values():
        ret *= v
    print(ret)
elif comb == 4:
    tmp = 1
    for v in names.values():
        tmp *= v
    ret = 0
    for v in names.values():
        ret += tmp // v
    print(ret)
else:
    ret = 0
    for comb in combinations('MARCH', 3):
        tmp = 1
        for c in comb:
            tmp *= c
        ret += comb
    print(ret)

Submission status: Runtime Error

Solution code:
def kaijo(a):
    if a==0:
        return 1
    else:
        return a*kaijo(a-1)

def combination(a,b):
    if a<b:
        return 0
    else:
        return kaijo(a)//(kaijo(b)*kaijo(a-b))

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

M,A,R,C,H,MARCH = 0,0,0,0,0,0

for i in range(N):
    if names[i][0]=='M':
        M+=1
    elif names[i][0]=='A':
        A+=1
    elif names[i][0]=='R':
        R+=1
    elif names[i][0]=='C':
        C+=1
    elif names[i][0]=='H':
        H+=1
MARCH = M + A + R + C + H
Num = [M,A,R,C,H]
ans = combination(MARCH,3)-sum([combination(i,3)+combination(i,2)*(MARCH-i) for i in Num])
print(ans)

Submission status: Runtime Error

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

M,A,R,C,H = 0,0,0,0,0

for i in range(N):
    if names[i][0]=='M':
        M += 1
    elif names[i][0]=='A':
        A += 1
    elif names[i][0]=='R':
        R += 1
    elif names[i][0]=='C':
        C += 1
    elif names[i][0]=='H':
        H += 1

ALL = M + A + R + C + H

def kaijo(a):
    if a==0:
        return 1
    return a*kaijo(a-1)

def permitation(a,b):
    return kaijo(a)//kaijo(a-b)

def combination(a,b):
    if a==0 or b==0:
        return 0
    elif a<b:
        return 0
    else:
        return permitation(a,b)//kaijo(b)

m2 = combination(M,2)*(ALL-M)
a2 = combination(A,2)*(ALL-A)
r2 = combination(R,2)*(ALL-R)
c2 = combination(C,2)*(ALL-C)
h2 = combination(H,2)*(ALL-H)

mC3 = combination(M,3)
aC3 = combination(A,3)
rC3 = combination(R,3)
cC3 = combination(C,3)
hC3 = combination(H,3)

ALLC3 = combination(ALL,3)

print(ALLC3-m2-a2-r2-c2-h2-mC3-aC3-rC3-cC3-hC3)

Submission status: Runtime Error

Solution code:
from scipy.special import comb
import itertools
N=int(input())
S=[input() for _ in range(N)]
M=0
A=0
R=0
C=0
H=0
alives=0
march=['M','A','R','C','H']
for i in S:
    if i.startswith('M'):
        M+=1
    elif i.startswith('A'):
        A+=1
    elif i.startswith('R'):
        R+=1
    elif i.startswith('C'):
        C+=1
    elif i.startswith('H'):
        H+=1

if M==0:
    march.pop(march.index('M'))
if A==0:
    march.pop(march.index('A'))
if R==0:
    march.pop(march.index('R'))
if C==0:
    march.pop(march.index('C'))
if H==0:
    march.pop(march.index('H'))

if len(march)<3:
    print(0)

seq=list(itertools.combinations(march,3))

ans=0
for i in seq:
    temp=1
    for ch in i:
        if ch=='M':
            temp*=M
        if ch=='A':
            temp*=A
        if ch=='R':
            temp*=R
        if ch=='C':
            temp*=C
        if ch=='H':
            temp*=H
    ans+=temp

print(ans)