import Control.Monad
import Data.List
import Control.Applicative

solver :: [[Int]] -> Int -> Int
solver [] c = c
solver (x:xs) c =
  let ys = permutations x
      ms = intersect xs ys
      n  = length ms
  in
      solver (xs \\ ms) (c + n)


main :: IO()
main = do
  n <- (read :: String -> Int) <$> getLine
  inputs <- map (map (read :: String -> Int) . words) <$> replicateM n getLine
  print $ solver inputs 0