import Control.Monad(replicateM)
import Data.List

comb k ns = filter ((k==).length) (subsequences ns)

main = do
    n <- readLn :: IO Int
    ss <- replicateM n getLine :: IO [String]
    print $ length $ filter (==True) [sort (head s) == sort (last s) | s<- (sss ss)]
        where sss = comb 2