import scala.io.StdIn

object Main extends App {
  
   val n = StdIn.readLine().toInt
   val k = StdIn.readLine().toInt
   val i = StdIn.readLine().split(' ').map(_.toInt)
   val r = (0 until n).foldLeft(0){ (acc, h) =>
      acc + scala.math.min((i(h) - 0)*2, scala.math.abs((k - i(h))*2))
   }
   
   println(r)
}