(*
ocamlfind ocamlopt -package batteries -linkpkg main.ml -o a.out
*)
open Batteries

let n = Scanf.sscanf (read_line ()) "%d" (
fun n -> 
        n
)

let k = Scanf.sscanf (read_line ()) "%d" (
fun k -> 
        k
)

let lst = 
        Str.split (Str.regexp " ") (read_line ())
      |> List.map int_of_string


let rec f l =
        match l with
                [] -> 0
                | first :: rest -> 
                        let a = first in
                        let b = abs (first - k) in
                                if a < b then
                                        (a * 2) + (f rest)
                                else
                                        (b * 2) + (f rest)

let () =
        f lst
      |> Printf.printf "%d\n"
