import Control.Applicative
import Data.List
import Control.Monad

isSquare x = let x' = (floor $ sqrt x) in x' ^ 2 == floor x

len xs ys = sum $ zipWith (\x y -> (abs $ x - y) ^ 2) xs ys

solve [] a = a
solve (x:[]) a = a
solve (x:xs) a = solve xs (a + b)
  where
  b = sum $ map (\t -> if t then 1 else 0) l
  l = map (isSquare.(len x)) xs

main = do
  [n, d] <- (map read).words <$> getLine
  xs <- replicateM n $ (map read).words <$> getLine
  print $ solve xs 0
