import Data.List
import Control.Monad

solver::[Char]->Int
solver [] = 1
solver (c:rest) = solver rest + sum (map solver (fun c rest))
                  where fun d re = let drpd = (dropWhile (d/=) re) in
                                        if [] == drpd
                                          then []
                                          else (tail drpd):(fun d (tail drpd))

press::[Char]->[Char]
press=map head.group

main::IO()
main=do
  n<-return.read=<<getLine
  dat<-forM [1..n] (\_->getLine)
  (print.solver.press) (concat dat)