open System

let n = stdin.ReadLine() |> int
let k = stdin.ReadLine() |> int
let x = stdin.ReadLine().Split() |> Array.map int

let f x = 2 * min (abs x) (abs <| x - k)

printfn "%d" <| Array.sumBy f x