# Author: cr4zjh0bp

# Created: Sat Mar 14 11:48:11 UTC 2020

import sys

 

stdin = sys.stdin

inf = 1 << 60

mod = 1000000007

 

ni = lambda: int(ns())

nin = lambda y: [ni() for _ in range(y)]

na = lambda: list(map(int, stdin.readline().split()))

nan = lambda y: [na() for _ in range(y)]

nf = lambda: float(ns())

nfn = lambda y: [nf() for _ in range(y)]

nfa = lambda: list(map(float, stdin.readline().split()))

nfan = lambda y: [nfa() for _ in range(y)]

ns = lambda: stdin.readline().rstrip()

nsn = lambda y: [ns() for _ in range(y)]

ncl = lambda y: [list(ns()) for _ in range(y)]

nas = lambda: stdin.readline().split()



n, k = nin(2)

x = na()



ans = 0

for i in range(n):

    ans += min(abs(x[i] - k) * 2, abs(x[i]) * 2)



print(ans)
import sys



stdin = sys.stdin

inf = 1 << 60

mod = 1000000007



ni      = lambda: int(ns())

nin     = lambda y: [ni() for _ in range(y)]

na      = lambda: list(map(int, stdin.readline().split()))

nan     = lambda y: [na() for _ in range(y)]

nf      = lambda: float(ns())

nfn     = lambda y: [nf() for _ in range(y)]

nfa     = lambda: list(map(float, stdin.readline().split()))

nfan    = lambda y: [nfa() for _ in range(y)]

ns      = lambda: stdin.readline().rstrip()

nsn     = lambda y: [ns() for _ in range(y)]

ncl     = lambda y: [list(ns()) for _ in range(y)]

nas     = lambda: stdin.readline().split()



n = ni()

k = ni()

x = na()



ans = 0

for i in range(n):

    ans += min(abs(x[i]) * 2, abs(x[i] - k) * 2)

print(ans)
# Author: cr4zjh0bp
# Created: Sat Mar 14 11:48:11 UTC 2020
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()
n, k = nin(2)
x = na()
ans = 0
for i in range(n):
    ans += min(abs(x[i] - k) * 2, abs(x[i]) * 2)
print(ans)

import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()
n = ni()
k = ni()
x = na()
ans = 0
for i in range(n):
    ans += min(abs(x[i]) * 2, abs(x[i] - k) * 2)
print(ans)

-# Author: cr4zjh0bp -# Created: Sat Mar 14 11:48:11 UTC 2020 -n, k = nin(2) +n = ni() +k = ni() -    ans += min(abs(x[i] - k) * 2, abs(x[i]) * 2) +    ans += min(abs(x[i]) * 2, abs(x[i] - k) * 2)