n = int(eval(input()))

k = int(eval(input()))

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

ans = 0

for xi in x:

    ans += min(xi, k - xi) * 2

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

k = int(eval(input()))

ans = 0

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

for v in x:

    ans += min(v, k - v) * 2

print(ans)
n = int(eval(input()))
k = int(eval(input()))
x = list(map(int, input().split()))
ans = 0
for xi in x:
    ans += min(xi, k - xi) * 2
print(ans)

n = int(eval(input()))
k = int(eval(input()))
ans = 0
x = list(map(int, input().split()))
for v in x:
    ans += min(v, k - v) * 2
print(ans)

+ans = 0 -ans = 0 -for xi in x: -    ans += min(xi, k - xi) * 2 +for v in x: +    ans += min(v, k - v) * 2