_,k,*x=list(map(int,open(0).read().split()));print((sum(min(t,k-t)*2for t in x)))
_,k,t=open(0);print((sum(min(x,int(k)-x)*2for x in map(int,t.split()))))
_, k, *x = list(map(int, open(0).read().split()))
print((sum(min(t, k - t) * 2 for t in x)))

_, k, t = open(0)
print((sum(min(x, int(k) - x) * 2 for x in map(int, t.split()))))

-_, k, *x = list(map(int, open(0).read().split())) -print((sum(min(t, k - t) * 2 for t in x))) +_, k, t = open(0) +print((sum(min(x, int(k) - x) * 2 for x in map(int, t.split()))))