import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n, d] <- getIntList
    xss <- replicateM n getIntList
    print $ length [() | i <- [0..n-2], j <- [i+1..n-1], isN (dist (xss !! i) (xss !! j))]
    
dist xs ys = sum $ zipWith (\x y -> (x - y) ^2) xs ys

isN a = or $ map (\x -> x ^ 2 == a) [1..a]