N = int(eval(input()))

K = int(eval(input()))

X = list(map(int,input().split()))



ans = 0

k = int(K/2)

for x in X:

  if(x > k):

    ans += (K-x) * 2

  else:

    ans += x * 2

print(ans)
N = int(eval(input()))

K = int(eval(input()))

X = list(map(int,input().split()))

cnt = 0

for x in X:

  if(x > K//2):

    cnt += (K-x)*2

  else:

    cnt += x*2

print(cnt)
N = int(eval(input()))
K = int(eval(input()))
X = list(map(int, input().split()))
ans = 0
k = int(K / 2)
for x in X:
    if x > k:
        ans += (K - x) * 2
    else:
        ans += x * 2
print(ans)

N = int(eval(input()))
K = int(eval(input()))
X = list(map(int, input().split()))
cnt = 0
for x in X:
    if x > K // 2:
        cnt += (K - x) * 2
    else:
        cnt += x * 2
print(cnt)

-ans = 0 -k = int(K / 2) +cnt = 0 -    if x > k: -        ans += (K - x) * 2 +    if x > K // 2: +        cnt += (K - x) * 2 -        ans += x * 2 -print(ans) +        cnt += x * 2 +print(cnt)