function main(input) {
  var N = input[0]-0;
  var K = input[1]-0;
  var list = input[2].split(" ").map(v=>v-0);
  var ans = 0;
  list.forEach(v=>{
    ans += Math.min(v,K-v)*2;
  });
  console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))
