fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val K = readLine()!!.toInt()
    val X = readLine()!!.split(" ").map(String::toInt)

    var sum = 0
    for (x in X) {
        val calc = Math.abs(K - x)
        if (x < calc) {
            sum += x * 2
        } else {
            sum += calc * 2
        }
    }
    println(sum)
}

