let is_integer xs ys =
  let dim = Array.length xs in
  let sq_dist = Array.fold_left ( + ) 0 @@
    Array.init dim @@ fun i -> (xs.(i) - ys.(i)) * (xs.(i) - ys.(i)) in
  let check = Array.exists (fun d -> d * d = sq_dist) (Array.init 44 @@ fun i -> (i + 1)) in
  if check then 1 else 0

let () = Scanf.scanf "%d %d\n" @@ fun n d ->
  let points =
    Array.init n @@ fun _ ->
      Array.init d @@ fun _ -> Scanf.scanf " %d" Fun.id in
  let check_boxes =
    Array.init (n - 1) @@ fun i ->
      Array.init (n - 1 - i) @@ fun j -> is_integer points.(i) points.(i + j) in
  let ans = 
    Array.fold_left (Array.fold_left ( + )) 0 check_boxes in
  Printf.printf "%d\n" ans 


(*
  Array.fold_left: ('a -> 'b -> 'a) -> 'a -> 'b array -> 'a
  1つ目の fold_left は (int -> int array -> int) -> int -> int array array -> int
  2つ目の fold_left は ( + ) を渡しているので ('a -> 'a array -> 'a) になる
  ここで期待するのは int -> int list -> int
*)

