import Data.List
main = do
  [n,_] <- map read . words <$> getLine :: IO [Int]
  ds <- map (map read . words) . lines <$> getContents :: IO [[Int]]
  let solve = [() | i <- [0..(n-1)],
                    j <- [0..(n-1)],
                    let x = sum $ map (\[a,b] -> (abs (a-b))^2) $ transpose [(ds !! i), (ds !! j)],
                    (sqrt $ realToFrac x) - realToFrac (floor $ sqrt $ realToFrac x) == 0.0,
                    i /= j]
  print $ (length solve) `div` 2