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