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 itertools

N = int(input())
S = [0] * N
ans = 0
for i in range(N):
    s = input()
    if s[0] in ['M', 'A', 'R', 'C', 'H']:
        S[i] = s
S = list(set(S))
S.remove(0)
march = [0] * 5
for i in S:
    if i[0] == 'M':
        march[0] += 1
    elif i[0] == 'A':
        march[1] += 1
    elif i[0] == 'R':
        march[2] += 1
    elif i[0] == 'C':
        march[3] += 1
    else:
        march[4] += 1

for i, j, k in list(itertools.combinations([0, 1, 2, 3, 4], 3)):
    ans += march[i] * march[j] * march[k]
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
s = []
for i in range(n):
    s.append(input())
tmp_nums = {"M":0, "A":0, "R":0, "C":0, "H":0}
for i in range(n):
    tmp_nums[s[i][0]] += 1
nums=[]
for i in tmp_nums.values():
    nums.append(i)
p = [0,0,0,0,0,0,1,1,1,2]
q = [1,1,1,2,2,3,2,2,3,3]
r = [2,3,4,3,4,4,3,4,4,4]
sum = 0
for i in range(10):
    sum += nums[p[i]]*nums[q[i]]*nums[r[i]]
print(sum)

Submission status: Runtime Error

Solution code:
N = int(input())
Sdic = {}
L = ["M","A","R","C","H"]
for i in L:
    Sdic[i] = []

tN = N
for i in range(N):
    s = input()
    if s[0] in L:
        Sdic[s[0]].append(s)
    else:
        tN -= 1


zen = tN*(tN-1)*(tN-2) / 6

one = 0
for i in ["M","A","R","C","H"]:
    c = len(Sdic[i])
    if c >= 3:
        one += c * (c-1) * (c-2)  / 6


lis = []
for i in range(N):
    for j in range(N):
        if i < j:
            lis.append(len(Sdic[L[i]]) + len(Sdic[L[j]]))

two = 0
for c in lis:
    if c >= 3:
        two += c * (c-1) * (c-2)  / 6

print(int(zen - one - two))

Submission status: Runtime Error

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
    elif s[0]=='A':
        a+=1
    elif s[0]=='R':
        r+=1
    elif s[0]=='C':
        c+=1
    elif s[0]=='H':
        h+=1
x=del ([m,a,r,c,h],0)
x.sort()
l=len(x)
if l<3:
    print(0)
elif l==3:
    print(x[0]*x[1]*x[2])
elif l==4:
    print()
else:
    print()

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):
    str = input()
    if str[0] in march:
        march[str[0]] += 1
for i in list(march):
    if march[i] == 0:
        march.pop(i)
c = 0
if len(march) == 3:
    tmpc = 1
    for chr in march:
        tmpc *= march[chr]
    c += tmpc
elif len(march) == 4:
    for i in march:
        tmpm = march.copy()
        tmpm.pop(i)
        tmpc = 1
        for chr in tmpm:
            tmpc *= tmpm[chr]
        c += tmpc
elif len(march) == 5:
    for i in march:
        tmpm1 = march.copy()
        tmpm1.pop(i)
        for j in tmpm1:
            tmpm2 = tmpm1.copy()
            tmpm2.pop(j)
            tmpc = 1
            for chr in tmpm:
                tmpc *= tmpm[chr]
            c += tmpc
print(c)

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):
    str = input()
    if str[0] in march:
        march[str[0]] += 1

for i in list(march):
    if march[i] == 0:
        march.pop(i)

c = 0
if len(march) == 3:
    tmpc = 1
    for chr in march:
        tmpc *= march[chr]
    c += tmpc
elif len(march) == 4:
    for i in march:
        tmpm = march.copy()
        tmpm.pop(i)
        tmpc = 1
        for chr in tmpm:
            tmpc *= tmpm[chr]
        c += tmpc
elif len(march) == 5:
    for i in march:
        tmpm1 = march.copy()
        tmpm1.pop(i)
        for j in tmpm1:
            tmpm2 = tmpm1.copy()
            tmpm2.pop(j)
            tmpc = 1
            for chr in tmpm:
                tmpc *= tmpm[chr]
            c += tmpc
print(c)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
import itertools

N = int(sys.stdin.readline().strip())
dct = {}
dct["M"] = 0
dct["A"] = 0
dct["R"] = 0
dct["C"] = 0
dct["H"] = 0
char_list = ["M", "A", "R", "C", "H"]

for _ in range(N):
    name = sys.stdin.readline().strip()
    first = name[0]
    dct[first] += 1

count = 0
for a, b, c in list(itertools.combinations(char_list, 3)):
    count += dct[a] * dct[b] * dct[c]
print(count)

Submission status: Runtime Error

Solution code:
import itertools
N = int(input())
MARCH = [0, 0, 0, 0, 0]
final_ans = 0
for i in range(N):
    a = input()
    if a[0] =='M':
        MARCH[0] += 1
    elif a[0] =='A':
        MARCH[1] += 1
    elif a[0] =='R':
        MARCH[2] += 1
    elif a[0] =='C':
        MARCH[3] += 1
    elif a[0] =='H':
        MARCH[4] += 1

MARCH = list(itertools.combinations(MARCH,3))

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

Submission status: Runtime Error

Solution code:
n = int(input())
m = 0
a = 0
r = 0
c = 0
h = 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 = m * a * r +m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+r*c*h+a*c*h
print(ans)

Submission status: Runtime Error

Solution code:
from itertools import combinations
N = int(input())
d = [0]*128
for _ in range(N): dic[ord(input()[0])] += 1
print(sum([d[ord(p0)]*d[ord(p1)]*d[ord(p2)] for p0,p1,p2 in combinations('MARCH', 3)]))

Submission status: Runtime Error

Solution code:
from itertools import combinations
N = int(input())
S = Counter()
for _ in range(N):
  S[input()[0]] += 1
print(sum([S[p0]*S[p1]*S[p2] for p0,p1,p2 in combinations('MARCH', 3)]))

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
	long long int n, m = 0, a = 0, r = 0, c = 0, h = 0, ans = 0;
	cin >> n;
	string s;
	for (int i = 0; i < n; ++i) {
		cin >> s;
		if (s[0] == 'M') m++;
		else if (s[0] == 'A') a++;
		else if (s[0] == 'R') r++;
		else if (s[0] == 'C') c++;
		else if (s[0] == 'H') h++;
	}
	ans += m * a*r + m * a*c + m * a*h + a * r*c + a * r*h + r * c*h + m * r*c + m * r*h + m * c*h + a * c*h;
	cout << ans << endl;
}
//1 1 2 0 0

Submission status: Runtime Error

Solution code:
n=int(input())
march=[0,0,0,0,0]
s=0
for i in range (n):
    name=input()
    if name[0]=="M":
        march[0]+=1
    if name[0]=="A":
        march[1]+=1
    if name[0]=="R":
        march[2]+=1
    if name[0]=="C":
        march[3]+=1
    if name[0]=="H":
        march[4]+=1
def fact(n):
	if n==0:
		return 1
	else:
		return n*(fact(n-1))
def choose(a,b):
	return fact(a)/(fact(a-b)*fact(b))
s=sum(march)
def excase(n):
	if n<2:
		return 0
	elif n==2:
		return (s-2)*choose(n,2)
	else:
		return (s-2)*choose(n,2)+(s-3)*choose(n,3)	
print(int((choose(s,3)-excase(march[0])-excase(march[1])-excase(march[2])-excase(march[3])-excase(march[4]))//1))

Submission status: Runtime Error

Solution code:
n = int(input())

arr = []
for i in range(n):
	arr.append(raw_input())

count = 0

def dfs(rest_str,person_count,i):
	global count
	if person_count == 3:
		count += 1

	elif i < n:
		if arr[i][0] in rest_str :
			dfs(rest_str.replace(arr[i][0],''),person_count+1,i+1)

		dfs(rest_str,person_count,i+1)

dfs('MARCH',0,0)
print count

Submission status: Runtime Error

Solution code:
from functools import reduce
from itertools import combinations
N = int(input())
S = {"M": [], "A": [], "R": [], "C": [], "H": []}
for _ in range(N):
    i = input()
    head = i[0]
    if head == "M":
        S["M"].append(i)
    elif head == "A":
        S["A"].append(i)
    elif head == "R":
        S["R"].append(i)
    elif head == "C":
        S["C"].append(i)
    elif head == "H":
        S["H"].append(i)
result = [len(S[head]) for head in list("MARCH") if len(S[head]) != 0]

ans = sum([reduce(lambda x, y: x * y, list(combinations(result, 3))[i])
           for i in range(len(result))])
print(ans)

Submission status: Runtime Error

Solution code:
from functools import reduce
from itertools import combinations
N = int(input())
S = {"M": set([]), "A": set([]), "R": set([]), "C": set([]), "H": set([])}
for _ in range(N):
    i = input()
    head = i[0]
    if head == "M":
        S["M"].add(i)
    elif head == "A":
        S["A"].add(i)
    elif head == "R":
        S["R"].add(i)
    elif head == "C":
        S["C"].add(i)
    elif head == "H":
        S["H"].add(i)
result = [len(S[head]) for head in list("MARCH") if len(S[head]) != 0]

ans = sum([reduce(lambda x, y: x * y, list(combinations(result, 3))[i])
           for i in range(len(result))])
print(ans)

Submission status: Runtime Error

Solution code:
#!C:\Users\daichi\Anaconda3/python.exe
# -*- coding: utf-8 -*-
import math

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


N = int(input())
a = []
T = [0,0,0,0,0]

for i in range(N):
    a.append(input())

i=0
for i in range(N):
    if( a[i].startswith('M') ):
        T[0] = T[0]+1
    if( a[i].startswith('A') ):
        T[1] = T[1]+1
    if( a[i].startswith('R') ):
        T[2] = T[2]+1
    if( a[i].startswith('C') ):
        T[3] = T[3]+1
    if( a[i].startswith('H') ):
        T[4] = T[4]+1
        
n = T[0]+T[1]+T[2]+T[3]+T[4]
#print(combinations_count(SUM, 3) )
r=3
com = math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
print(com)

Submission status: Runtime Error

Solution code:
#!C:\Users\daichi\Anaconda3/python.exe
# -*- coding: utf-8 -*-
import math

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


N = int(input())
a = []
T = [0,0,0,0,0]

for i in range(N):
    a.append(input())

i=0
for i in range(N):
    if( a[i].startswith('M') ):
        T[0] = T[0]+1
    if( a[i].startswith('A') ):
        T[1] = T[1]+1
    if( a[i].startswith('R') ):
        T[2] = T[2]+1
    if( a[i].startswith('C') ):
        T[3] = T[3]+1
    if( a[i].startswith('H') ):
        T[4] = T[4]+1
        
SUM = T[0]+T[1]+T[2]+T[3]+T[4]
print(combinations_count(SUM, 3) )

Submission status: Runtime Error

Solution code:
import itertools

N = int(input())

S = []
for _ in range(N):
    S.append(input())
    
M, A, R, C, H = [], [], [], [], []

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

for s in S:
    top = s[0]
    if top in march:
        if top == "M":
            M.append(s)
        elif top == "A":
            A.append(s)
        elif top == "R":
            R.append(s)
        elif top == "C":
            C.append(s)
        elif top == "H":
            H.append(s)

MARCH = [len(M), len(A), len(R), len(C), len(H)]

for i in range(len(MARCH)):
    if MARCH[i] == 0:
        del march[i]

if len(march) <= 2:
    print(0)

else:
    x = 0
    pattern = list(itertools.combinations(MARCH, 3))
    for i in pattern:
        x += i[0]*i[1]*i[2]
    print(x)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
S = [None]*5
for i in range(N):
    S[i] = input()

S_M = [S[i] for i in range(N) if S[i][0] == 'M']
S_A = [S[i] for i in range(N) if S[i][0] == 'A']
S_R = [S[i] for i in range(N) if S[i][0] == 'R']
S_C = [S[i] for i in range(N) if S[i][0] == 'C']
S_H = [S[i] for i in range(N) if S[i][0] == 'H']

souwa = 0
kahi = [0]*5
kahi[0] = len(S_M)
kahi[1] = len(S_A)
kahi[2] = len(S_R)
kahi[3] = len(S_C)
kahi[4] = len(S_H)

for i in range(len(kahi)-2):
    for j in range(i+1, len(kahi)-1):
        for k in range(j+1, len(kahi)):
            souwa += kahi[i]*kahi[j]*kahi[k]
print(souwa)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
S = [None]*5
for i in range(N):
    S[i] = input()

S_M = [S[i] for i in range(N) if S[i][0] == 'M']
S_A = [S[i] for i in range(N) if S[i][0] == 'A']
S_R = [S[i] for i in range(N) if S[i][0] == 'R']
S_C = [S[i] for i in range(N) if S[i][0] == 'C']
S_H = [S[i] for i in range(N) if S[i][0] == 'H']

souwa = 0
kahi = [0]*5
kahi[0] = len(S_M)
kahi[1] = len(S_A)
kahi[2] = len(S_R)
kahi[3] = len(S_C)
kahi[4] = len(S_H)

kahi_not0 = kahi[kahi != 0]
if len(kahi_not0) <= 2:
    print(0)
else:
    for i in range(len(kahi_not0)-2):
        for j in range(i+1, len(kahi_not0)-1):
            for k in range(j+1, len(kahi_not0)):
                souwa += kahi_not0[i]*kahi_not0[j]*kahi_not0[k]

    print(souwa)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
S = [None]*5
for i in range(N):
    S[i] = input()

S_M = [S[i] for i in range(N) if S[i][0] == 'M']
S_A = [S[i] for i in range(N) if S[i][0] == 'A']
S_R = [S[i] for i in range(N) if S[i][0] == 'R']
S_C = [S[i] for i in range(N) if S[i][0] == 'C']
S_H = [S[i] for i in range(N) if S[i][0] == 'H']

souwa = 0
kahi = [0]*5
kahi[0] = len(S_M)
kahi[1] = len(S_A)
kahi[2] = len(S_R)
kahi[3] = len(S_C)
kahi[4] = len(S_H)

kahi_not0 = kahi[kahi != 0]
if len(kahi_not0) <= 2:
    print(0)
else:
    for i in range(len(kahi_not0)-2):
        for j in range(i+1, len(kahi_not0)-1):
            for k in range(j+1, len(kahi_not0)):
                souwa += kahi_not0[i]*kahi_not0[j]*kahi_not0[k]

    if souwa >= 2**32:
        print(souwa/(2**32), end='')
        print(souwa-(souwa/(2**32))*(2**32))
    else:
        print(souwa)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
S = np.empty(5, dtype=str)
for i in range(N):
    S[i] = input()

S_M = np.array([S[i] for i in range(N) if S[i][0] == 'M'])
S_A = np.array([S[i] for i in range(N) if S[i][0] == 'A'])
S_R = np.array([S[i] for i in range(N) if S[i][0] == 'R'])
S_C = np.array([S[i] for i in range(N) if S[i][0] == 'C'])
S_H = np.array([S[i] for i in range(N) if S[i][0] == 'H'])

souwa = 0
kahi = np.array([0, 0, 0, 0, 0])
kahi[0] = len(S_M)
kahi[1] = len(S_A)
kahi[2] = len(S_R)
kahi[3] = len(S_C)
kahi[4] = len(S_H)

kahi_not0 = kahi[kahi != 0]
if len(kahi_not0) <= 2:
    print(0)
else:
    for i in range(len(kahi_not0)-2):
        for j in range(i+1, len(kahi_not0)-1):
            for k in range(j+1, len(kahi_not0)):
                souwa += kahi_not0[i]*kahi_not0[j]*kahi_not0[k]

    if souwa >= 2**32:
        print(souwa/(2**32), end='')
        print(souwa-(souwa/(2**32))*(2**32))
    else:
        print(souwa)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
S = np.empty(5, dtype=str)
for i in range(N):
    S[i] = input()

S_M = np.array([S[i] for i in range(N) if S[i][0] == 'M'])
S_A = np.array([S[i] for i in range(N) if S[i][0] == 'A'])
S_R = np.array([S[i] for i in range(N) if S[i][0] == 'R'])
S_C = np.array([S[i] for i in range(N) if S[i][0] == 'C'])
S_H = np.array([S[i] for i in range(N) if S[i][0] == 'H'])

souwa = 0
kahi = np.array([0, 0, 0, 0, 0])
kahi[0] = len(S_M)
kahi[1] = len(S_A)
kahi[2] = len(S_R)
kahi[3] = len(S_C)
kahi[4] = len(S_H)

kahi_not0 = kahi[kahi != 0]
if len(kahi_not0) <= 2:
    print(0)
else:
    for i in range(len(kahi_not0)-2):
        for j in range(i+1, len(kahi_not0)-1):
            for k in range(j+1, len(kahi_not0)):
                souwa += kahi_not0[i]*kahi_not0[j]*kahi_not0[k]

    if souwa >= 2**32:
        print(souwa/(2**32), end='')
        print(souwa-(souwa/(2**32))*2**32)
    else:
        print(souwa)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
S = np.empty(5, dtype=str)
for i in range(N):
    S[i] = input()

S_M = np.array([S[i] for i in range(N) if S[i][0] == 'M'])
S_A = np.array([S[i] for i in range(N) if S[i][0] == 'A'])
S_R = np.array([S[i] for i in range(N) if S[i][0] == 'R'])
S_C = np.array([S[i] for i in range(N) if S[i][0] == 'C'])
S_H = np.array([S[i] for i in range(N) if S[i][0] == 'H'])

souwa = 0
kahi = np.array([0, 0, 0, 0, 0])
kahi[0] = len(S_M)
kahi[1] = len(S_A)
kahi[2] = len(S_R)
kahi[3] = len(S_C)
kahi[4] = len(S_H)

kahi_not0 = kahi[kahi != 0]
if len(kahi_not0) <= 2:
    print(0)
else:
    for i in range(len(kahi_not0)-2):
        for j in range(i+1, len(kahi_not0)-1):
            for k in range(j+1, len(kahi_not0)):
                souwa += kahi_not0[i]*kahi_not0[j]*kahi_not0[k]

    print(souwa)

Submission status: Runtime Error

Solution code:
def combi(n,k):
    if n<k:
        return 0
    if k==0 or n==k:
        return 1
    elif k==1:
        return n
    else:
        return combi(n-1, k) + combi(n-1,k-1)
n=int(input())
s=[input() for _ in range(n)]
march=list(map(lambda i:"MARCH"[i], range(5)))
march_names={}
for x in march:
    march_names[x]=[]

all_len=0

for x in s:
    if x[0] in march:
        all_len+=1
        march_names[x[0]].append(x)
c=combi(all_len, 3)
for k in march_names.keys():
    kl=len(march_names[k])
    if kl<2:
        continue
    else:
        c-=combi(kl,3)+combi(kl,2)*(all_len-kl)
print(c)

Submission status: Runtime Error

Solution code:
def combi(n,k):
    if n<k:
        return 0
    if k==0 or n==k:
        return 1
    elif k==1:
        return n
    else:
        return combi(n-1, k) + combi(n-1,k-1)
n=int(input())
s=[input() for _ in range(n)]
march=list(map(lambda i:"MARCH"[i], range(5)))
march_names={}
for x in march:
    march_names[x]=[]
all_len=0
for x in s:
    if x[0] in march:
	all_len+=1
        march_names[x[0]].append(x)
c=combi(all_len, 3)
for k in march_names.keys():
    kl=len(march_names[k])
    if kl<2:
        continue
    else:
        c-=combi(kl,3)+combi(kl,2)*(all_len-kl)
print(c)

Submission status: Runtime Error

Solution code:
def combi(n,k):
    if n<k:
        return 0
    if k==0 or n==k:
        return 1
    elif k==1:
        return n
    else:
        return combi(n-1, k) + combi(n-1,k-1)

n=int(input())
s=[input() for _ in range(n)]
march=list(map(lambda i:"MARCH"[i], range(5)))
march_names={}
for x in march:
    march_names[x]=[]
all_len=0
for x in s:
    if x[0] in march:
	all_len+=1
	march_names[x[0]].append(x)
c=combi(all_len, 3)
for k in march_names.keys():
    kl=len(march_names[k])
    if kl<2:
	continue
    else:
        c-=combi(kl,3)+combi(kl,2)*(all_len-kl)
print(c)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10000)

def combi(n,k):
    if n<k:
        return 0
    if k==0 or n==k:
        return 1
    elif k==1:
        return n
    else:
        return combi(n-1, k) + combi(n-1,k-1)

n=int(input())
s=[input() for _ in range(n)]
march=list(map(lambda i:"MARCH"[i], range(5)))
march_names={}
for x in march:
    march_names[x]=[]
all_len=0
for x in s:
    if x[0] in march:
	all_len+=1
	march_names[x[0]].append(x)
c=combi(all_len, 3)
for k in march_names.keys():
    kl=len(march_names[k])
    if kl<2:
	continue
    else:
        c-=combi(kl,3)+combi(kl,2)*(all_len-kl)
print(c)

Submission status: Runtime Error

Solution code:
n = int(input())
s =[input() for i in range(n)]
m,a,r,c,h=0,0,0,0,0
for A in s:
    if A[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
x = []
for i in [m,a,r,c,h]:
    if i != 0:
        x.append(i)
if len(x)<3:
    print(0)
elif len(x)==3:
    print(x[0]*x[1]*x[2])
elif len(x)==4:
    print(x[0]*x[1]*x[2]+x[0]*x[1]*x[3]+x[0]*x[2]*x[3]+x[1]*x[2]*x[3])
else:
    print(x[0]*x[1]*x[2]+x[0]*x[1]*x[3]+x[0]*x[2]*x[3]+x[1]*x[2]*x[3]
         +x[0]*x[1]*x[4]+x[0]*x[2]*x[4]+x[1]*x[2]*x[4]
         +x[3]*x[4]*x[5]+x[2]*x[4]*x[5]+x[1]*x[4]*x[5])

Submission status: Runtime Error

Solution code:
N = int(input())
A = [i for i in range(N) input()]
k = 0
c = [ 0,0,0,0,0]
for i in A:
  if i[0] == m:
    c[0] += 1
  if i[0] == a:
    c[1] += 1
  if i[0] == r:
    c[2] += 1
  if i[0] == c:
    c[3] += 1
  if i[0] == h:
    c[4] += 1

if c.count(0) >= 3:
  k += 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(k)

Submission status: Runtime Error

Solution code:
n = int(input())
names = []
for i in range(n):
  names.appen(input())
names = [i[0] for i in names]
nm = ["M","A","R","C","H"]
ks = [names.count(nm[i]) for i in range(5)]
ans = 0
for i in range(3):
  for j in range(i+1,4):
    for k in range(j+1,5):
      ans += i*j*k
print(ans)

Submission status: Runtime Error

Solution code:
import itertools
n=int(raw_input())
first_char=["M","A","R","C","H"]
name={}
for i in range(n):
  s=raw_input()
  if not name.has_key(s[0]):
    name[s[0]]=0
  name[s[0]]+=1

ans=0
  
for st in list(itertools.combinations(first_char,3)):
  ans+=name[st[0]]*name[st[1]]*name[st[2]]

print ans

Submission status: Runtime Error

Solution code:
import itertools
n=int(raw_input())
first_char=["M","A","R","C","H"]
name={}
for i in range(n):
  s=raw_input()
  if !name.has_key(s[0]):
    name[s[0]]=0
  name[s[0]]+=1

ans=0
  
for s in list(itertools.combinations(first_char,3)):
  ans+=name[s[0]]*name[s[1]]*name[s[2]]

print ans

Submission status: Runtime Error

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

ans=0
  
for s in list(itertools.combinations(first_char,3)):
  ans+=name[s[0]]*name[s[1]]*name[s[2]]

print ans

Submission status: Runtime Error

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


for i in range(N):
    name = input()
    if name[0] in dic:
        dic[name[0]]=dic[name[0]]+1

for i,v in dic.items():
    li.append(v)



count = 0
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            count += li[i]*li[j]*li[k]
print(count)

Submission status: Runtime Error

Solution code:
import itertools
letters = ['M','A','R','C','H']
N = int(input())
a = []
com_s = []

for i in range(N):
    x = input()
    if x[0] in letters:
        a.append(x)

coms = list(itertools.combinations(a,3))
for com in coms:
    if com[0][0] != com[1][0] and com[1][0] != com[2][0] and com[2][0] != com[0]com[0]:
        com_s.append(com)

print(len(com_s))

Submission status: Runtime Error

Solution code:
n = int(input())

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

order = "MARCH"

initial_arary = [name[0] for name in s]
nums = [initial_array.count(order[i]) for i in range(len(order))]

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

Submission status: Runtime Error

Solution code:
#include <iostream>

using namespace std;

int N;
long long NM, NA, NR, NC, NH;

int main() {
	cin >> N;
	for(int i=0; i<N; i++) {
	    char s[12];
	    scanf("%s", s);
	    if(s[0] == 'M')
	        NM += 1;
	    else if(s[0] == 'A')
	        NA += 1;
	    else if(s[0] == 'R')
	        NR += 1;
	    else if(s[0] == 'C')
	        NC += 1;
	    else if(s[0] == 'H')
	        NH += 1;
	}
	NM = (NM == 0)? 1 : NM;
	NA = (NA == 0)? 1 : NA;
	NR = (NR == 0)? 1 : NR;
	NC = (NC == 0)? 1 : NC;
	NH = (NH == 0)? 1 : NH;
	cout << NM * NA * NR * NC * NH << endl;
}

Submission status: Runtime Error

Solution code:
#include <iostream>

using namespace std;

int N;
long long NM, NA, NR, NC, NH;

int main() {
	cin >> N;
	for(int i=0; i<N; i++) {
	    char s[10];
	    scanf("%s", s);
	    if(s[0] == 'M')
	        NM += 1;
	    else if(s[0] == 'A')
	        NA += 1;
	    else if(s[0] == 'R')
	        NR += 1;
	    else if(s[0] == 'C')
	        NC += 1;
	    else if(s[0] == 'H')
	        NH += 1;
	}
	NM = (NM == 0)? 1 : NM;
	NA = (NA == 0)? 1 : NA;
	NR = (NR == 0)? 1 : NR;
	NC = (NC == 0)? 1 : NC;
	NH = (NH == 0)? 1 : NH;
	cout << NM * NA * NR * NC * NH << endl;
}

Submission status: Runtime Error

Solution code:
N = int(input())
member = [0,0,0,0,0]
ans = 0
for _ in range(N):
    a = input().split()
    if a[0] == "M":
        member[0] += 1
    elif a[1] == "A":
        member[1] += 1
    elif a[2] == "R":
        member[2] += 1
    elif a[3] == "C":
        member[3] += 1
    elif a[4] == "H":
        member[4] += 1
 
for i in range(3):
    for j in range(i+1, 4):
        for k in range(j+2, 5):
            ans += member[i]*member[j]*member[k]

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
member = [0,0,0,0,0]
ans = 0
for _ in range(N):
    a = input().split()
    if a[0] == "M":
        member[0] += 1
    elif a[1] == "A":
        member[1] += 1
    elif a[2] == "R":
        member[2] += 1
    elif a[3] == "C":
        member[3] += 1
    elif a[4] == "H":
        member[4] += 1
 
for i in range(3):
    for j in range(i+1, 4):
        for k in range(i+2, 5):
            ans += member[i]*member[j]*member[k]

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
name_list = [input() for name in range(N)]
char_list = ['M', 'A', 'R', 'C', 'H']
count_list = [0 for _ in range(N)]

flag = False

for name in name_list:
    if name[0] in char_list:
        count_list[char_list.index(name[0])] += 1
score=0
for x in range(5):
    for y in range(x+1,5):
        for z in range(y+1,5):
            try:
                score+=count_list[x]*count_list[y]*count_list[z]
            except:
                print("0")
                exit()



print(score)

Submission status: Runtime Error

Solution code:
N = int(input())
name_list = [input() for name in range(N)]
char_list = ['M', 'A', 'R', 'C', 'H']
count_list = [0 for _ in range(N)]

for name in name_list:
    if name[0] in char_list:
        count_list[char_list.index(name[0])] += 1
score=0
for x in range(5):
    for y in range(x+1,5):
        for z in range(y+1,5):
            score+=count_list[x]*count_list[y]*count_list[z]

print(score)

Submission status: Runtime Error

Solution code:
N = int(input())
name_list = [input() for name in range(N)]
char_list = ['M', 'A', 'R', 'C', 'H']
count_list = [0 for _ in range(N)]

for name in name_list:
    if name[0] in char_list:
        count_list[char_list.index(name[0])] += 1
score=0
for x in range(len(count_list)):
    for y in range(x+1,len(count_list)):
        for z in range(y+1,len(count_list)):
            score+=count_list[x]*count_list[y]*count_list[z]

print(score)

Submission status: Runtime Error

Solution code:
N = int(input())
name_list = [input() for name in range(N)]
char_list = ['M', 'A', 'R', 'C', 'H']
count_list = [0 for _ in range(N)]

for name in name_list:
    if name[0] in char_list:
        count_list[char_list.index(name[0])] += 1
score = 1
flag= False
for x in count_list:
    if x != 0:
        flag = True
        score *= x
if flag is True:
    print(score)
else:
    print("0")

Submission status: Runtime Error

Solution code:
N = int(input())
name_list = [input() for name in range(N)]
char_list = ['M', 'A', 'R', 'C', 'H']
count_list = [0 for _ in range(N)]

for name in name_list:
    if name[0] in char_list:
        count_list[char_list.index(name[0])] += 1
score = 1

for x in count_list:
    if x != 0:
        score *= x

print(score)

Submission status: Runtime Error

Solution code:
N = int(input())
S ="MARCH"
S2 = [0]*len(S)
n=0

for i in range(N):
    s = input()
    for k, j in enumerate(S1):
        if s[0] == j:
            S2[k]+=1
            
for i in range(len(S2)):
    for j in range(i+1,len(S2)):
        for k in range(j+1,len(S2)):
            n +=S2[i]*S2[j]*S2[k]
    
print(n)

Submission status: Runtime Error

Solution code:
m,a,r,c,h = [0,0,0,0,0]
N = int(input())

for i in range(N):

Submission status: Runtime Error

Solution code:
n = int(input().strip())
s = [input().strip() for _ in range(n)]
num = [0 for _ in range(5)]
num[0] = len([True for _s in s if _s[0] == "M"])
num[1] = len([True for _s in s if _s[0] == "A"])
num[2] = len([True for _s in s if _s[0] == "R"])
num[3] = len([True for _s in s if _s[0] == "C"])
num[4] = len([True for _s in s if _s[0] == "H"])
ans = 0
for i in range(5):
    for j in range(i, 5):
        for k in range(j, 5):
            ans += num[i] * num[j] * num[k]
print(ans

Submission status: Runtime Error

Solution code:
s = ["M", "A", "R", "C", "H"]
n = int(raw_input())
li = list()
for m in range(0,n):
    li.append(raw_input())
re = list()

for st1 in li:
    temp = list()
    if st1[0] in s:
        temp.append(st1)

    for st2 in li:
        if st2[0] in s and len(filter(lambda e:e[0]==st2[0], temp)) == 0:
            temp.append(st2)
        for st3 in li:
            if st3[0] in s and len(filter(lambda e:e[0]==st3[0], temp)) == 0:
                temp.append(st3)
                if sorted(temp) not in re and len(temp) == 3:
                    re.append(sorted(temp))
                    temp.pop()
        temp = [temp[0]]
print re
print len(re)

Submission status: Runtime Error

Solution code:
    n = int(input())
     
    M = 0
    A = 0
    R = 0
    C = 0
    H = 0
     
    res = 0
     
    for i in range(n):
        char = input()[0]
        if char == "M":
            M += 1
        elif char == "A":
            A += 1
        elif char == "R":
            R += 1
        elif char == "C":
            C += 1
        elif char == "H":
            H += 1
     
    res += M * A * R;
    res += M * A * C;
    res += M * A * H;
    res += M * R * C;
    res += M * R * H;
    res += M * C * H;
     
    res += A * R * C;
    res += A * R * H;
    res += A * C * H;
     
    res += R * C * H;
     
    print(res)

Submission status: Runtime Error

Solution code:
N = int(input())
num = [0,0,0,0,0]
for i in range(N):
  a = input()
  if a[0]=='M':
    num[0] += 1
  if a[0]=='A':
    num[1] += 1
  if a[0]=='R':
	num[2] += 1
  if a[0]=='C':
	num[3] += 1
  if a[0]=='H':
	num[4] += 1


num_1 = num[0]*num[1]*num[2]
num_2 = num[0]*num[1]*num[3]
num_3 = num[0]*num[1]*num[4]
num_4 = num[1]*num[2]*num[3]
num_5 = num[1]*num[2]*num[4]
num_6 = num[2]*num[3]*num[4]
num_7 = num[0]*num[2]*num[3]
num_8 = num[0]*num[2]*num[4]
num_9 = num[0]*num[3]*num[4]
num_10 = num[1]*num[3]*num[4]

answer = num_1 + num_2 + num_3 + num_4 + num_5 + num_6 + num_7 + num_8 + num_9 + num_10

print(answer)

Submission status: Runtime Error

Solution code:
 math

N = int(input())

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

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

cont1=0
cont2=0
cont3=0
cont4=0
cont5=0
count=0

for i in range(N):
    if S[i] == 'M':
        M+=1
    elif S[i] == 'A':    
        A+=1    
    elif S[i] == 'C':
        C+=1
    elif S[i] == 'R':
        R+=1
    elif S[i] == 'H':
        H+=1
#print(M,A,R,C,H)
num = M+A+R+C+H
if num>3:
    num1 = math.factorial(num)
    num11=math.factorial(num-3)*3*2
    num2= num1//num11
    
    if M>1:
        cont1=M
    elif A>1:
        cont2=A
    elif R>1:
        cont3=R
    elif C>1:
        cont4=C
    elif H>1:
        cont5=H
        
    cont =cont1+cont2+cont3+cont4+cont5
    count=num-cont
    print(num2-count)
 #   print(num2,num,cont)
else:
    print(0)