import Control.Monad

chekans::Float -> Bool
chekans x = x - y  == 0.0
    where 
        y = fromIntegral $ truncate x

powm::Float->Float->Float
powm y z = (y-z) * (y-z)

dis::[[Float]] -> [Float]
dis xxs = [sqrt $ sum $ zipWith (powm) xs ys| xs<-xxs,ys<-xxs]

main:: IO ()
main = do
    [n,d] <- map read . words <$> getLine
    xs <- map (map read . words) <$> replicateM n getLine
    let dist = dis xs
    let ans = length $ filter (chekans) dist
    print (div (ans-n) 2)