main = getContents >>= print.solve.tail.words
    where
        solve [] = 0
        solve (a:as) = solve as + map (g a) [(m,n,l) | m <- ["M","A","R","C","H"], n<- ["M","A","R","C","H"], l <- ["M","A","R","C","H"], m /= n, n /= l, l /= m] 
        f [] b = []
        f (a:as) b | head a == b = a:(f as b) 
              | otherwise = f as b
        g n (x,y,z) = length [(a,b,c) | a <- (f n x), b <- (f n y), c <- (f n z)]
-- 型が駄目って言われてるけれど何がおかしくてどうしたら治るのかさっぱり
