function Main(input) {
  input = input.split("\n");
  var sum = 0;
  var arr = input[2].split(" ").map(Number);
  arr.forEach(function(val){
      sum += Math.min(val,input[1]-val);
      })
      console.log(sum*2);
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());