let () = Scanf.scanf "%d\n%d\n" @@ fun n k ->
  let xs = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun x -> x in
  Array.map (fun x -> min x @@ abs @@ x - k) xs
  |> Array.map (( * ) 2)
  |> Array.fold_left ( + ) 0
  |> Printf.printf "%d\n"