object Main extends App {
	import scala.math._

	val N = scala.io.StdIn.readInt
	val K = scala.io.StdIn.readInt

	val x = scala.io.StdIn.readLine.split(" ").map(z => min(z.toInt, K-z.toInt))

	println(x.sum * 2)

}