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

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define tr(container, it) \
        for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define ill(_x)  ll _x;scanf("%lld",&_x);
#define idb(_x)  double _x;scanf("%lf",&_x);i
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vs vector<string>
#define in0(x, a, b)((x)>=a && (x)<=b    )
#define in1(x, a, b)((x)>a && (x)<b)
#define  rep(i, begin, end) for (__typeof(end) i = (begin); i != (end); i += 1 - 2 * ((begin) > (end)))
//#define int int_64
#define endl '\n'
const double pi = 3.14159265358979323846;
const int INF = 0x3f3f3f3f;
const int X10 = 1024, X11 = 2048, X12 = 4096, X13 = 8196, X14 = 16392, X15 = 32786, X16 = 65536, X17 = 131072, X18 = 262144, X19 = 524288, X20 = 1048576;

const int MOD = (int) (1e9 + 7);

template<typename FI>
void parted_rotate(FI first1, FI last1, FI first2, FI last2)
{
    if(first1 == last1 || first2 == last2) return;
    FI next = first2;
    while (first1 != next) {
        std::iter_swap(first1++, next++);
        if(first1 == last1) first1 = first2;
        if (next == last2) {
            next = first2;
        } else if (first1 == first2) {
            first2 = next;
        }
    }
}

template<typename BI>
bool next_combination_imp(BI first1, BI last1, BI first2, BI last2)
{
    if(first1 == last1 || first2 == last2) return false;
    auto target = last1; --target;
    auto last_elem = last2; --last_elem;
    // find right-most incrementable element: target
    while(target != first1 && !(*target < *last_elem)) --target;
    if(target == first1 && !(*target < *last_elem)) {
        parted_rotate(first1, last1, first2, last2);
        return false;
    }
    // find the next value to be incremented: *next
    auto next = first2;
    while(!(*target < *next)) ++next;
    std::iter_swap(target++, next++);
    parted_rotate(target, last1, next, last2);
    return true;
}

// INVARIANT: is_sorted(first, mid) && is_sorted(mid, last)
template<typename BI>
inline bool next_combination(BI first, BI mid, BI last)
{
    return next_combination_imp(first, mid, mid, last);
}

// INVARIANT: is_sorted(first, mid) && is_sorted(mid, last)
template<typename BI>
inline bool prev_combination(BI first, BI mid, BI last)
{
    return next_combination_imp(mid, last, first, mid);
}

bool isPrime(int n)
{
    // Corner cases
    if (n <= 1)  return false;
    if (n <= 3)  return true;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n%2 == 0 || n%3 == 0) return false;

    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
            return false;

    return true;
}

int A[5];
void _() {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        if(s[0] == 'M')A[0] ++;
        if(s[0] == 'A')A[1] ++;
        if(s[0] == 'R')A[2] ++;
        if(s[0] == 'C')A[3] ++;
        if(s[0] == 'H')A[4] ++;
    }
    ll sum = 0;
    rep(i,0,5)rep(j,i+1,5)rep(k,j+1,5)sum += A[i]*A[j]*A[k];
    cout << sum <<endl;



}

#undef int
int main() {
#ifdef Debug
    freopen("/home/hiroo/Desktop/competitive-programming/IO/Input.txt", "r", stdin);
    freopen("/home/hiroo/Desktop/competitive-programming/IO/Output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    _();
    return 0;

}