import Data.List (tails)

main = do
  li <- getLine
  let [n,d] = map read $ words li
  vs <- getVecs n
  let answer = compute vs
  print answer

getVecs :: IO [[Int]]
getVecs 0 = return []
getVecs n = do
  li <- getLine
  let v = map read $ words li
  vs <- getVecs (pred n)
  retrun (v:vs)

squares = [ k*k | k <- [1..] ]
isSquare x = inner squares where
  inner (kk:kks) = case compare x kk of
    LT -> False
    EQ -> True
    GT -> inner kks

compute vs = length
  [ ()
  | v1:vs1 <- tails vs
  , v2 <- vs1
  , isSquare $ sum $ map (^ 2) $ zipWith (-) v1 v2
  ]
