import Control.Monad
type Coord= [Int]
main = do
    [n, d] <- map read . words <$> getLine
    a <- comb . map (map read . words) <$> replicateM n getLine
    print $ length $ filter isInt $ map sub2 $ a

sub2 :: (Coord, Coord) -> Float
sub2 (a, b) = sqrt $ realToFrac $ sum $ zipWith (\a b -> (a - b) ^ 2) a b

isInt :: Float -> Bool
isInt n = n == fromInteger (round n)

comb :: [Coord] -> [(Coord, Coord)]
comb [] = []
comb (x:xs) = [(x, y) | y <- xs] ++ comb xs
