import Control.Monad
import Data.List

toFloat = fromRational . toRational

distance :: [Int] -> [Int] -> Int
distance [] [] = 0
distance (x:xs) (y:ys) = ((x - y)^2) + (distance xs ys)

solveSub :: [[Int]] -> Int
solveSub [_] = 0
solveSub (x:y:z) = (if toFloat (floor sq) == sq then 1 else 0) + solveSub (x:z)
                where
                    sq = sqrt (toFloat (distance x y))

solve :: [[Int]] -> Int
solve [_] = 0
solve xz@(x:z) = solveSub xz + solve z

main = do
    [n,d] <- map read . words <$> getLine :: IO [Int]
    xnd <- replicateM n (map read . words <$> getLine) :: IO [[Int]]
    print $ solve xnd
