let n, d = Scanf.scanf " %d %d" @@ fun a b -> a, b
let xss = Array.init n @@ fun _ -> Array.init d @@ fun _ -> Scanf.scanf " %d" (+) 0
let g x = x * x
let f ys zs = Array.mapi (fun i y -> g @@ y - zs.(i)) ys |> Array.fold_left (+) 0
let h n = let rec f i = if i * i >= n then i * i = n else f (i + 1) in f 0
let ans = ref 0
let _ = Array.iteri (fun i xs -> for j = i + 1 to n - 1 do if h @@ f xs xss.(j) then incr ans done) xss; Printf.printf "%d\n" !ans