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)

#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(dead_code)]
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        cmp::max($x, max!($($y),+))
    };
}

macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        cmp::min($x, min!($($y),+))
    };
}

const MOD: usize = 1_000_000_007;
const MAX: usize = 510_000;

struct BinCoeff {
    fac: Vec<usize>,
    finv: Vec<usize>,
    inv: Vec<usize>,
}

impl BinCoeff {
    fn new() -> BinCoeff {
        let fac = vec![0; MAX];
        let finv = vec![0; MAX];
        let inv = vec![0; MAX];
        let mut bincoeff = BinCoeff { fac: fac, finv: finv, inv: inv };
        bincoeff.com_init();
        bincoeff
    }

    fn com_init(&mut self) {
        let fac = &mut self.fac;
        let finv = &mut self.finv;
        let inv = &mut self.inv;
        fac[0] = 1;
        fac[1] = 1;
        finv[0] = 1;
        finv[1] = 1;
        inv[1] = 1;
        for i in 2..MAX {
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }

    fn bin_coeff(&mut self, n: usize, k: usize) -> usize {
        if k > n/2 {
            self.bin_coeff(n-k, k)
        } else {
            self.fac[n] * (self.finv[k] * self.finv[n - k] % MOD) % MOD
        }
    }
}

// must input n <= m
fn gcd(n: usize, m: usize) -> usize {
    if n == 0 {
        m
    } else {
        gcd(m%n, n)
    }
}

use std::cmp;
use std::collections::{HashSet, BinaryHeap, VecDeque, HashMap};
use std::iter::FromIterator;
fn main() {
    input! {
        N: usize,
        S: [chars; N],
    }
    let mut counts = [0usize; 5];
    let chars = ['M', 'A', 'R', 'C', 'H'];
    for s in S.iter() {
        for ind in 0..5 {
            if s[0] == chars[ind] {
                counts[ind] += 1;
                break;
            }
        }
    }
    let mut ans = 0usize;
    for first in 0..5 {
        for second in first+1..5 {
            for third in second+1..5 {
                ans += counts[first] * counts[second] * counts[third];
            }
        }
    }
    println!("{}", ans);
}