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

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});

process.stdin.on('end', function() {
    Main(g_input.split(/\r?\n/));
});

function Main(input) {
    var n = parseInt(input[0], 10);
    var k = parseInt(input[1], 10);
    var xstrs = input[2].split(' ');
    var x = new Array(n);
    for (var i = 0; i < n; i++) {
        x[i] = parseInt(xstrs[i], 10);
    }

    var total = 0;
    for (var i = 0; i < n; i++) {
        var move = Math.min(x[i], k - x[i]);
        total += move * 2;
    }

    console.log(total);
    return 0;
}
