fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val k = readLine()!!.toInt()
    val sum_min = readLine()!!.split(Regex("""\s+""")).map { it.toInt() }
            .fold(0) { sum, x -> sum + (minOf(x, k - x) * 2) }

    println(sum_min)
}

fun minOf(a: Int, b: Int) = if (a < b) a else b