fun main(args: Array<String>) {
    val n = readLine()?.toInt() ?: return
    val k = readLine()?.toInt() ?: return
    val x = readLine()?.split(" ")?.map(String::toInt) ?: return
    x.sumBy {
        Math.min(it * 2, (k - it) * 2)
    }.let {
        println(it.toString())
    }
}