_ = eval(input())

k = int(eval(input()))

x = [int(x) for x in input().split()]



ans = 0

for i in x:

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

else:

    print(ans)
_ = eval(input())

k = int(eval(input()))

x = [int(x) for x in input().split()]



ans = 0

for i in x:

    ans += min(i, k - i)

else:

    print((ans * 2))
_ = eval(input())
k = int(eval(input()))
x = [int(x) for x in input().split()]
ans = 0
for i in x:
    ans += min(i, k - i) * 2
else:
    print(ans)

_ = eval(input())
k = int(eval(input()))
x = [int(x) for x in input().split()]
ans = 0
for i in x:
    ans += min(i, k - i)
else:
    print((ans * 2))

-    ans += min(i, k - i) * 2 +    ans += min(i, k - i) -    print(ans) +    print((ans * 2))