unittest
{
	assert( [ "1", "10", "2" ].parse.expand.solve == 4 );
	assert( [ "2", "9", "3 6" ].parse.expand.solve == 12 );
	assert( [ "5", "20", "11 12 9 17 12" ].parse.expand.solve == 74 );
}



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

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.strip.to!( long );
	input.popFront;
	auto k = input.front.strip.to!( long );
	input.popFront;
	auto xs = input.front.split.to!( long[] );
	return tuple( k, xs );
}

auto solve( long k, long[] xs )
{
	auto r = 0L;
	
	foreach( x; xs )
	{
		r += min( x, k - x ) * 2;
	}
	
	return r;
}
