import Data.List
import Control.Monad

dist2 :: [Integer] -> [Integer] -> Integer
dist2 x y = foldl (+) 0 (zipWith (\a b -> (a-b)^2) x y)

dist :: [Integer] -> [Integer] -> Integer
dist x y = floor $ sqrt . fromIntegral $ dist2 x y

count :: [[Integer]] -> Int
count [] = 0
count (x:xs) = countStep x xs + count xs
    where countStep x [] = 0
          countStep x (y:ys) = (if (dist x y)^2 == dist2 x y then 1 else 0) + countStep x ys

main = do
  n:d:_ <- map read . words <$> getLine :: IO [Int]
  xs <- replicateM n (map read . words <$> getLine) :: IO [[Integer]]
  putStrLn . show $ count xs
