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 Ruby (2.3.3) (judge verdict: Time Limit Exceeded)

# when initialize get stdin
class StdinGetter
    
    # initialize
    #
    # @param [Boolean] has_header
    def initialize(has_header=false)
        @stdin = initialized_stdin(readlines)
        @header = initialized_header(has_header)
        @body = initialized_body(has_header)
    end
    
    # getter for header
    #
    # @return [String] header
    def header()
        @header
    end
    
    # getter for body
    #
    # @return [Array] body
    def body()
        @body
    end
    
    # get splited body
    #
    # @params [String] splitter
    # @return [Array] body's array
    def splited_body(splitter)
        @body.map { |line| line.split(splitter) }
    end
    
    private
    # initializer for stdin
    #
    # @param [Array] lines
    # @return [Array] 
    def initialized_stdin(lines)
        lines.nil? ? [] : lines.map{ |line| line.chomp }
    end
    
    # initializer for stdin header
    #
    # @param [Boolean] has_header
    # @return [String]
    def initialized_header(has_header)
        has_header ? @stdin[0] : []
    end
    
    # initializer for stdin header
    #
    # @param [Boolean] has_header?
    # @return [Array]    
    def initialized_body(has_header)
        has_header ? @stdin.slice(1..-1) : @stdin
    end
        
end

# March Class
class March
    
    @@initial_chars = ["M", "A", "R", "C", "H"]
    @@combination_number = 3
    
    # initialize
    #
    # @params [Array] names
    def initialize(names)
        @names = names
    end
    
    # get all variation of having initial
    #
    # @return [Array]
    def initials_variation()
        @names.select { |name| @@initial_chars.include?(name[0]) }.combination(@@combination_number).to_a
    end
    
    # get variation without duplicate initials_variation
    # 
    # @return [Array]
    def not_duplicate_initial_variation()
        initials_variation.map { |names| names.map { |name| name[0] }.uniq }.select { |variation| variation.length == @@combination_number }
    end
    
    # print how many valiation of march is exist
    def print_march_count()
        puts not_duplicate_initial_variation.length
    end
    
end

# execute
stdin_getter = StdinGetter.new(true)
names = stdin_getter.body

march = March.new(names)
march.print_march_count