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

main :: IO ()
main = do
    [n, d] <- getIntList
    xl <- getIntNList n
    putStrLn (show (length [x | x <- map (\a -> snd (properFraction (distance (a !! 0) (a !! 1)))) (combination 2 xl), x == 0.0]))


distance :: (Integral a, Show a) => [a] -> [a] -> Float
distance i j = sqrt (fromIntegral(sum (zipWith (\x y -> (x-y) * (x-y)) i j)))

combination :: Int -> [a] -> [[a]]
combination 0 _ = [[]]
combination _ [] = []
combination n (x:xs) = (zipWith (:) (repeat x) (combination (n - 1) xs)) ++ (combination n xs)

readInt = fst . fromJust . BS.readInteger
readIntList = map readInt . BS.words
getIntList = readIntList <$> BS.getLine
getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine
