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

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

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