object Main extends App {
  val Array(n, k) = Array(io.StdIn.readLine().toInt, io.StdIn.readLine().toInt)
  val arr = io.StdIn.readLine().split(" ").map(_.toInt)
  def abs(x: Int) = Math.abs(x)
  def min(x: Int, y: Int) = Math.min(x, y)
  val res = arr.map(x => min(abs(x), abs(x - k)) * 2).sum
  println(res)
}
