fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val k = readLine()!!.toInt()
    val x = readLine()!!.split(" ").map{ it.toInt() }
    var sum = 0
    for(a in x) {
        sum += 2*Math.min(a, k-a)
    }
    println(sum)
}
