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

void main()
{
  auto n = readln.chomp.to!size_t;
  auto k = readln.chomp.to!int;
  auto x = readln.split.to!(int[]);

  auto ans = 0;
  foreach (xi; x)
    ans += min(xi, k-xi);

  writeln(ans*2);
}
