import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  (n : _ : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  xs <- sequence . replicate n $ map unsafeSignedDecimal . T.words <$> T.getLine :: IO [[Int]]
  let
    l = length . filter ((==) <$> id <*> (^ 2) . sq) . fst . f $ xs
  print l

f :: [[Int]] -> ([Int], [[Int]])
f = foldr step ([], [])
  where
    step x (ds, xs) = ((dist2 x <$> xs) ++ ds, x : xs)

dist2 :: [Int] -> [Int] -> Int
dist2 x y = sum $ (^ 2) . uncurry subtract <$> zip x y

sq :: Int -> Int
sq x = sq' 0 x
  where
    sq' y z | z == y + 1 = y
            | m ^ 2 >= x = sq' y m
            | otherwise = sq' m z
      where
        m = (y + z) `div` 2

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n
