type ABC(stream:System.IO.TextReader) =
  member this.Scan1 f = stream.ReadLine() |> f
  member this.Scan2 f = stream.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1]))
  member this.Scan3 f = stream.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1], a.[2]))
  member this.Scan4 f = stream.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1], a.[2], a.[3]))
  member this.ScanVecH f = stream.ReadLine().Split() |> Array.map f
  member this.ScanVecV n f = [| for i in 1..n -> stream.ReadLine() |> f |]
  member this.ScanMatrix n f  = [| for i in 1..n -> stream.ReadLine().Split() |> Array.map f |]
  member this.ScanCharMatrix n = [| for i in 1..n -> stream.ReadLine().ToCharArray() |]
  member this.Close () = stream.Close()

let util = ABC(stdin)

let n,d = util.Scan2 int

let M = util.ScanMatrix n int

let isOK xs ys =
  let zs = Array.map2 (fun x -> fun y -> x - y) xs ys
  let s2 = Array.fold (fun a -> fun x -> a + x * x) 0 zs
  let t = s2 |> float |> sqrt |> int |> fun x -> x * x
  t = s2


[
  for i in 0..n-1 do
  for j in i+1..n-1 do
    yield (i,j)
]
|> List.filter (fun (i,j) -> isOK M.[i] M.[j])
|> List.length
|> printfn "%d"

util.Close()
