open System

let input = stdin.ReadLine().Split()|>Array.map int
let N =input.[0]
let D =input.[1]
let X = [|for i in [0..N-1] do yield (stdin.ReadLine().Split()|>Array.map int)|]
[<EntryPoint>]
let main argv =
    let dist i j = 
        [0..D-1]
        |> Seq.sumBy(fun c -> (X.[i].[c]-X.[j].[c])*(X.[i].[c]-X.[j].[c]))
        |>double
        |>sqrt
    let mutable ans = 0
    for i in [0..N-2] do
        for j in [i+1..N-1] do
            ans <- ans + if dist i j =(dist i j |>floor) then 1 else 0
    printfn "%d" ans
    0
   