'use strict'

function main(s) {

  s = s.split('\n');

  const k = Number(s[1]);
  const xs = s[2].split(' ').map(n => Number(n));

  let sum = 0;

  for (const x of xs) {
    sum += Math.min(2 * x, 2 * (k - x));
  }

  console.log(sum);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));
