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: Wrong Answer)

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 m_vec: Vec<char> =
        vec!['M', 'A', 'R', 'C', 'H'];
    let mut removed_vec: Vec<String> = Vec::new();
    for s in vec.iter() {
        let char_vec: Vec<char> =  s.chars().collect();
        let first_letter = char_vec[0].clone();

        if m_vec.contains(&first_letter) {
            removed_vec.push(s.clone());
        }
    }

//    println!("{:?}", removed_vec);

    let mut count = 0;

    for i in 0..i64::pow(2, removed_vec.len() as u32) {

        let mut each_vec: Vec<String> = Vec::new();
        for j in 0..n {
            if (1 & i >> j) == 1 {
                each_vec.push(vec[j as usize].clone());
            }
        }

        let mut march_vec: Vec<char> =
            vec!['M', 'A', 'R', 'C', 'H'];

        if each_vec.len() == 3 {
            for s in each_vec.iter() {
                let char_vec: Vec<char> =  s.chars().collect();
                let first_letter = char_vec[0].clone();

                if march_vec.contains(&first_letter) {
                    let index = march_vec.iter().position(|&r| r==first_letter).unwrap();
                    march_vec.remove(index);

                    if march_vec.len() == 2 {
                        count+=1;
                        break;
                    }
                } else {
                    break;
                }
            }
        }
    }
    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);
}