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 <stdio.h>
#include <algorithm>
using namespace std;
struct comb{
    int a, b, c;
    void ordenar(){
        int d=a, e=b, f=c;
        if(d > e){
            int aux = d;
            d = e;
            e = aux;
        }
        if(f < e){
            if(f > d){
                int aux = e;
                e = f;
                f = aux;
            } else {
                int aux = f;
                f = e;
                e = d;
                d = aux;

            }
        }
        a = d;
        b = e;
        c = f;
    }
};


int n, abc[6], cont = 0, com[4], values[6], idx = 0;
char word[20];
comb tot[200];

void f(int p, int v){
    if(p == 2){
        com[p] = v;
        tot[idx].a = com[0];
        tot[idx].b = com[1];
        tot[idx].c = com[2];
        tot[idx].ordenar();
        idx+=1;
        return;
    }
    com[p] = v;
    values[v] = 1;
    for(int i=1; i<=cont; i++){
        if(values[i] == 0){
            f(p+1, i);
        }
    }
    values[v] = 0;
}

bool compare(comb uno, comb dos){
    if(uno.a == dos.a){
        if(uno.b == dos.b){
            return uno.c < dos.c;
        } else {
            return uno.b < dos.b;
        }
    } else {
        return uno.a < dos.a;
    }
}

int main(){
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        scanf("%s", word);
        if(word[0] == 'M')
            abc[0] += 1;
        else if(word[0] == 'A')
            abc[1] += 1;
        else if(word[0] == 'R')
            abc[2] += 1;
        else if(word[0] == 'C')
            abc[3] += 1;
        else if(word[0] == 'H')
            abc[4] += 1;
    }
    int  x=1, y=1, m=1, id=0;
    for(int i=0; i<5; i++){
        if(abc[i] > 0){
            cont += 1;
            m*=abc[i];
            abc[id] = abc[i];
            id+=1;
        }
    }
    for(int i=1; i<=cont; i++)
        x = x*i;
    for(int i=1; i<=(cont - 3); i++)
        y = y*i;
    x = (x/(y*6));
    for(int i=1; i<=cont; i++){
        f(0, i);
    }
    sort(tot, tot+idx, compare);
    //values[0] = tot[0].a; values[1] = tot[0].b; values[2] = tot[0].c;
long long k=0;
    for(int i=0; i<idx; i++){
        if(tot[i].a == values[0] && tot[i].b== values[1] && tot[i].c == values[2]){

        } else {
            values[0] = tot[i].a; values[1] = tot[i].b; values[2] = tot[i].c;
            long long z=abc[values[0]-1]*abc[values[1]-1]*abc[values[2]-1];
            k += z;
            //printf("%d\n", z);
            //printf("%d %d %d\n", tot[i].a, tot[i].b, tot[i].c);
        }

    }
    printf("%lld\n", k);
}