let N = stdin.ReadLine() |> int
let K = stdin.ReadLine() |> int
let xi = stdin.ReadLine().Split() |> Array.map int |> Array.indexed

xi |> Array.sumBy (fun (index,x) ->
  (min (abs (K-x)) x)*2
  ) |> stdout.WriteLine