import Control.Monad(replicateM)
import Data.List(sort)

comb :: Int -> [a] -> [[a]]
comb 0 xs = [[]]
comb _ [] = []
comb n (x:xs) = [x:y | y <- comb (n-1) xs] ++ comb n xs

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