let id x = x
let n = Scanf.scanf "%d\n" id
let k = Scanf.scanf "%d\n" id
let array = Array.init n (fun _ -> Scanf.scanf "%d " id)
let list = Array.to_list array

let rec func l =
  match l with
  | [] -> 0
  | hd :: rest -> 2 * (min hd (k-hd)) + func rest

let ans = func list

let () =
  Printf.printf "%d\n" ans