import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    readint;
    int k = readint;
    auto xs = readints;

    int ans = 0;
    foreach (x; xs) {
        // (0, i) のロボットが回収する
        int a = x * 2;
        // (k, i) のロボットが拐取する
        int b = (k - x) * 2;
        ans += min(a, b);
    }
    writeln(ans);
}
