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 Rust (1.15.1) (judge verdict: Accepted)

use std::io::*;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::HashSet;
use std::cmp;
use std::f64::consts;

fn main() {
    let n: i64 = read();
    let mut vec: Vec<String> = (0..n).map(|_| read()).collect();
    let mut map: HashMap<char, i64> = HashMap::new();

    let march_vec = vec!['M', 'A', 'R', 'C', 'H'];

    map.insert('M', 0);
    map.insert('A', 0);
    map.insert('R', 0);
    map.insert('C', 0);
    map.insert('H', 0);

    for s in vec.iter() {
        let char_vec: Vec<char> = s.chars().collect();
        let first_letter = char_vec[0];

        *map.entry(first_letter).or_insert(0) += 1;
    }

    let mut count = 0;

    for i in 0..i64::pow(2, march_vec.len() as u32) {
        let mut each_vec: Vec<char> = Vec::new();
        for j in 0..march_vec.len() {
            if (1 & i >> j) == 1 {
                each_vec.push(march_vec[j].clone());
            }
        }

        let mut each_count = 1;

        if each_vec.len() == 3 {
            for s in each_vec.iter() {
                let val = map.get(s).unwrap().clone();
                each_count *= val;
            }
            count+=each_count;
        }
    }

    println!("{:?}", count);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// 最大公約数
fn gcd(a: i32, b: i32) -> i32 {
    match b {
        0 => a,
        _ => gcd(b, a % b)
    }
}

// 最小公倍数
fn lcm(a: i32, b: i32) -> i32 {
    a * b / gcd(a, b)
}

// 階乗
fn kaijou(n: i32)->i32 {
    if n == 1 {
        return n;
    }
    return n * kaijou(n-1);
}