import scala.io.StdIn

object Main extends App {
  val n = StdIn.readInt
  val k = StdIn.readInt

  val ans = StdIn.readLine.split(" ").map(_.toInt)
    .map( i => math.min(i<<1, math.abs(i-k)<<1) ).sum

  println(ans)
}