import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)

  val n  = sc.nextInt
  val k  = sc.nextInt
  val xl = List.fill(n)(sc.nextInt)


  val res = xl.foldLeft(0){(sum, x) =>
    sum + Math.min(x, k - x) * 2
  }

  println(res)
}