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 _ = Array.iter (fun x -> ans := !ans + 2 * min x (k - x)) xs; Printf.printf "%d\n" !ans