function main(s) {
	n = s.split("\n")[0];
	k = s.split("\n")[1];
	x = s.split("\n")[2].split(" ");
	z = 0;
	for (var i = 0; i < n; i++) {
		z += Math.min(k-x[i], x[i]) * 2;
	}
	console.log(z);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

