let i_inp_list : unit -> int list = fun () ->
  let inp_split = Str.split (Str.regexp " ") (input_line stdin) in
  List.map (fun x -> int_of_string x) (inp_split)

let rec inp_loop : (unit -> 'a) -> int -> 'a list = fun inp_fun n ->
  if n = 0 then []
  else
    let x = inp_fun () in
    x :: inp_loop inp_fun (n - 1)
    
let rec d2 p q sum =
  match (p, q) with
    ([], []) -> sum
  | (x :: xs, y :: ys) ->
     d2 xs ys (sum + (x - y) * (x - y))
  | _ -> raise (Failure "Invalid input")
    
let check p q =
  let d2' = d2 p q 0 in
  let d = int_of_float (sqrt (float_of_int d2')) in
  d * d = d2'
    
let () =
  let (n, d) = Scanf.sscanf (input_line stdin) "%d %d" (fun a b -> (a, b)) in
  let l = inp_loop i_inp_list n in
  let rec pairs : 'a list -> int = function
      [] -> 0
    | x :: xs -> List.fold_left
                   (fun sum y ->
                     if check x y then
                       sum + 1
                     else
                       sum) 0 xs
                 + (pairs xs)
  in
  let ans = pairs l in
  print_int ans;
  print_newline ()
