import java.util.*

fun main(args: Array<String>) {
    var inp = Scanner(System.`in`)
    var n = inp.nextInt()
    var k = inp.nextInt()
    var sum: Int = 0
    for (i in 1..n) {
        var x = inp.nextInt()
        sum += Math.min(x, Math.abs(x - k)) * 2
    }
    println(sum)
}