import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.List
import qualified Data.Set as S

toInts :: IO [Int]
toInts = unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

able_dist :: S.Set Int
able_dist = S.fromList [i ^ 2 | i <- [0 .. 130]]

is_good :: Int -> Bool
is_good x = S.member x able_dist

dist_2 :: [Int] -> [Int] -> Int
dist_2 xs ys = sum [(x - y) ^ 2 | (x, y) <- zip xs ys]

solver :: [[Int]] -> Int
solver lss =
  let n = length lss
   in let m = length $ filter is_good [dist_2 a b | a <- lss, b <- lss]
       in div (m - n) 2

main :: IO ()
main = do
  n:d:[] <- toInts
  dat <- forM [1 .. n] (\_ -> toInts)
  print $ solver dat
