import Control.Monad

main :: IO ()
main = do
  [n,_] <- readInts
  ps    <- replicateM n readInts
  print $ solve ps

readInts :: IO [Int]
readInts = map read . words <$> getLine

solve :: [[Int]] -> Int
solve = length . filter good . map distance' . pairs
  where good d    = floor d == ceiling d
        distance' = uncurry distance

distance :: [Int] -> [Int] -> Double
distance p q = isqrt . sum $ zipWith f p q
  where isqrt = sqrt . fromIntegral
        f x y = (x - y) ^ 2

pairs :: [a] -> [(a,a)]
pairs []     = []
pairs (x:xs) = map ((,) x) xs ++ pairs xs
