/+ dub.sdl:
	name "hello"
+/
import std.array;
import std.algorithm;
import std.conv;
import std.stdio;
import std.string;

void main()
{
    auto N = readln.chomp.to!int;
    auto K = readln.chomp.to!int;
    auto x = readln.chomp.split(' ').map!(to!int).array;

    x.map!(n => min(n * 2, (K - n) * 2)).sum.writeln();
}
