import Data.Bits
import Data.List
import Control.Monad
import qualified Data.Vector.Unboxed as V
import Control.Monad.ST
import Data.Maybe (fromMaybe)
import qualified Data.ByteString.Lazy.Char8 as B
import Debug.Trace

check :: [Int] -> [Int] -> Bool
check xs ys = (foldl (\x (y,y') -> x + (y-y')^2) 0 (zip xs ys)) == (((^2) . floor . sqrt . fromIntegral) $ foldl (\x (y,y') -> x + (y-y')^2) 0 (zip xs ys))

main :: IO ()
main = do
  [n,d] <- map read.words <$> getLine :: IO [Int]
  xss <- replicateM n $ map read.words <$> getLine
  print $ length [1 | xs <- xss, xs' <- xss, xs < xs', check xs xs']
