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

let () =
    Scanf.scanf "%d %d\n%s\n" (fun n k str ->
        let xs = Str.split (Str.regexp " ") str
            |> List.map int_of_string in
        slv k xs
        |> Printf.printf "%d")