from collections import Counter,defaultdict,deque

from heapq import heappop,heappush,heapify

import sys,bisect,math,itertools

sys.setrecursionlimit(10**8)

mod = 10**9+7

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))

def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))



n = inp()

k = inp()

x = inpl()

res = 0

for i in x:

    res += min(i,abs(i-k))*2

print(res)
from collections import Counter,defaultdict,deque

from heapq import heappop,heappush,heapify

import sys,bisect,math,itertools,fractions,pprint

sys.setrecursionlimit(10**8)

mod = 10**9+7

INF = float('inf')

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))



n = inp()

k = inp()

a = inpl()

res = 0

for i,x in enumerate(a):

    res += min(abs(k-x)*2, x*2)

print(res)
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys, bisect, math, itertools

sys.setrecursionlimit(10**8)
mod = 10**9 + 7


def inp():
    return int(sys.stdin.readline())


def inpl():
    return list(map(int, sys.stdin.readline().split()))


def inpln(n):
    return list(int(sys.stdin.readline()) for i in range(n))


n = inp()
k = inp()
x = inpl()
res = 0
for i in x:
    res += min(i, abs(i - k)) * 2
print(res)

from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys, bisect, math, itertools, fractions, pprint

sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")


def inp():
    return int(sys.stdin.readline())


def inpl():
    return list(map(int, sys.stdin.readline().split()))


n = inp()
k = inp()
a = inpl()
res = 0
for i, x in enumerate(a):
    res += min(abs(k - x) * 2, x * 2)
print(res)

-import sys, bisect, math, itertools +import sys, bisect, math, itertools, fractions, pprint +INF = float("inf") -def inpln(n): -    return list(int(sys.stdin.readline()) for i in range(n)) - - -x = inpl() +a = inpl() -for i in x: -    res += min(i, abs(i - k)) * 2 +for i, x in enumerate(a): +    res += min(abs(k - x) * 2, x * 2)