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.fold_left (+) 0 @@ Array.init d @@ fun i -> g @@ ys.(i) - zs.(i)
let ans = ref 0
let _ =
  for i = 0 to n - 1 do
    for j = i + 1 to n - 1 do
      let x = ref 0 in
      let b = f xss.(i) xss.(j) in
      while !x * !x < b do incr x done;
      if !x * !x = b then incr ans done done;
  Printf.printf "%d\n" !ans