process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});

reader.on('close', () => {
 var n = Number(lines[0]);
 var k = Number(lines[1]);
 var x = lines[2].split(' ');
 x = x.map(function(str) { return Number(str)});
 var ans = 0;
 
 for(i=0; i<n; i++){
   var a = x[i] * 2;
   var b = (k - x[i]) * 2;
   if(a < b){
     ans += a;
   }else if(a >= b){
     ans += b;
   }
     
   }
 

 console.log(ans);
});