[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

let dist2 xs ys =
    List.zip xs ys
    |> List.sumBy (fun (x, y) -> pown (abs (x - y)) 2)

let isInt x =
    Seq.ofList [1..x]
    |> Seq.tryFind (fun y -> y * y = x)
    |> Option.isSome

[<EntryPoint>]
let main _ =
    let [n;d] = reads int
    let xss = Array.map (fun _ -> reads int) [|1..n|]
    seq {
        for i = 0 to n - 2 do
            for j = i + 1 to n - 1 do
                if isInt (dist2 xss.[i] xss.[j]) then yield ()
    }
    |> Seq.length
    |> printfn "%i"
    0