import java.util
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n, k = sc.nextInt()
    var x = new Array[Int](n)
    var ans = 0
    for(i <- 0 until n) {
      x(i) = sc.nextInt()
      ans += Math.min(x(i), k-x(i))
    }
    println(ans*2)
  }
}
