import Control.Monad

main :: IO ()
main = do
  [n,d] <- map (read :: String -> Int) . words <$> getLine
  xnd <- map (map (read :: String -> Int) . words) <$> getNLine_ n
  print $ (\x -> div (x-n) 2) . length . filter id $ distance <$> xnd <*> xnd

distance :: [Int] -> [Int] -> Bool
distance xs ys = isSquare . sum $ zipWith (\x y -> (x-y)^2) xs ys
  where isSquare n = ((^2) . floor . sqrt . fromIntegral) n == n

getNLine_ :: Int -> IO [String]
getNLine_ n = replicateM n getLine
