n,k=int(eval(input())),int(eval(input()));print((sum([min(i*2,(k-i)*2) for i in list(map(int,input().split()))])))
_,k=eval(input()),int(eval(input()));print((sum([min(i*2,(k-i)*2) for i in list(map(int,input().split()))])))
n, k = int(eval(input())), int(eval(input()))
print((sum([min(i * 2, (k - i) * 2) for i in list(map(int, input().split()))])))

_, k = eval(input()), int(eval(input()))
print((sum([min(i * 2, (k - i) * 2) for i in list(map(int, input().split()))])))

-n, k = int(eval(input())), int(eval(input())) +_, k = eval(input()), int(eval(input()))