import Data.List
main = do
  [n,d] <- map (read::String->Int) . words <$> getLine
  x <- map (map (read::String->Int)) . map words . lines <$> getContents
  print $ length [d|a<-x, b<-(delete a . dropWhile(/=a)) x,
                  let d = sum $ map (^2) $ zipWith (-) a b,
                  is_square d]

is_square n = m * m == n
  where m = int_sqrt(n)
  
int_sqrt :: Int -> Int
int_sqrt n = floor (sqrt (fromIntegral n))