Scanf.scanf "%d" (fun n ->
    let calc m a r c h =
        m * a * r         +
        m * a *     c     +
        m * a *         h +
        m *     r * c     + 
        m *     r *     h +
        m *         c * h +
            a * r * c     +
            a * r *     h +
            a *     c * h +
                r * c * h
    in
    let rec loop i m a r c h =
        if i = n then calc m a r c h else
        let s = Scanf.scanf " %s" (fun s -> s) in
        match s.[0] with
        | 'M' -> loop (i + 1) (m + 1) a r c h
        | 'A' -> loop (i + 1) m (a + 1) r c h
        | 'R' -> loop (i + 1) m a (r + 1) c h
        | 'C' -> loop (i + 1) m a r (c + 1) h
        | 'H' -> loop (i + 1) m a r c (h + 1)
        | _   -> loop (i + 1) m a r c h
    in
    loop 0 0 0 0 0 0 |> Printf.printf "%d\n"
)