'use strict'

function Main(input) {
  const inputs = input.split('\n');
  const n = inputs[0];
  const k = inputs[1];
  const balls = inputs[2].split(' ').map(n => parseInt(n, 10)).sort((a, b) => a-b);
  
  let sum = 0;
  balls.map(b => {
    const dist = Math.min(b, k - b);
    sum += dist * 2;
  });
  
  console.log(sum);
}

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