import kotlin.math.abs
import kotlin.math.min

fun solver(n: Int, k: Int, xs: List<Int>): Int {
    var sum = 0

    xs.forEach { x ->
        sum += min(x, abs(x - k)) * 2
    }

    return sum
}

fun main(args: Array<String>) {
    
    val n = readLine()!!.toInt()
    val k = readLine()!!.toInt()
    val xs = readLine()!!.split(" ").map { it.toInt() }
     
/*
    val n = 5
    val k = 20
    val xs = listOf(11, 12, 9, 17, 12)
*/
    val result = solver(n, k, xs)

    println(result)
}
