import std.stdio, std.string, std.conv, std.bigint, std.typecons, std.algorithm, std.array, std.math, std.range;
 
void main() {
    auto N = readln.chomp.to!int;
    auto K = readln.chomp.to!int;
    auto xs = readln.split.to!(int[]);
    xs.map!(x => 2 * min(x, K-x)).sum.writeln;
}

