let id x = x
let n = Scanf.scanf "%d\n" id
let k = Scanf.scanf "%d\n" id

let slv k xs =
    List.map (fun x -> min x (abs (x-k))) xs
    |> (List.fold_left (+) 0)
    |> ( * ) 2

let rec inp n = match n with
    | 0 -> []
    | _ -> Scanf.scanf "%d " id :: (inp (n-1))

let () =
    slv k (inp n) |> Printf.printf "%d"