import scala.math.abs

object Main extends App {
  
  val sc = new java.util.Scanner(System.in)
  sc.useDelimiter("\n")
  val N = sc.nextInt()
  val K = sc.nextInt()
  val X = sc.next().split(' ').map(_.toInt).toList
  val ans = for ((x, i) <- X.zipWithIndex) yield {
    if (x < abs(K - x)) {
      x * 2
    } else {
      abs(K - x) * 2
    }
  }
  println(ans.sum)

}