function Main(input) {
input = input.split("\n");
tmp = input[2].split(" ");
var a = parseInt(input[0], 10);
var b = parseInt(input[1], 10);
var c = 0;
for (i=0; i<a; i++){
  if(parseInt(tmp[i], 10) <= b/2){
    c = c + parseInt(tmp[i], 10)*2;
  } else {
    c = c + (b - parseInt(tmp[i], 10))*2;
  }
}
  console.log('%s', c);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));