"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = ~~arg[0];
    const K = ~~arg[1];
    const X = arg[2].split(" ");
    
    let answer = 0;
    
    for(let i in X) {
        let temp = Math.min(X[i], K - X[i]);
        answer += temp;
    }

    console.log(answer * 2);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));