let n, k = Scanf.scanf " %d %d" @@ fun a b -> a, b
let xs = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let ans = ref 0
let _ =
  for i = 0 to n - 1 do ans := !ans + min (xs.(i) * 2) (abs (xs.(i) - k) * 2) done;
  Printf.printf "%d\n" !ans