object Main extends App{
    val n = scala.io.StdIn.readInt
    val k = scala.io.StdIn.readInt
    val x = scala.io.StdIn.readLine.split(" ").map(_.toInt)
    println(x.map(e => Array(e, k-e).min).sum * 2)
}