import Control.Monad

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

solve :: [[Float]] -> Int
solve [] = 0
solve (_:[]) = 0
solve (x:rest) = g x rest + solve rest
  where
    g x [] = 0
    g x (y:rest) = h x y + g x rest

    h xs ys =
      if any (\m -> n == m**2) [1..n] then 1 else 0
      where
        n = sum $ zipWith (\x y -> (abs (x - y))**2) xs ys