import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n, k = sc.nextInt()

    var ans = 0
    for (i <- 0 until n) {
      val x = sc.nextInt()
      ans += 2 * (math.min(x, k - x))
    }

    println(ans)
  }
}