There are N balls in the xy-plane. The coordinates of the i-th of them is (x_i, i).
Thus, we have one ball on each of the N lines y = 1, y = 2, ..., y = N.
In order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B.
Then, he placed the i-th type-A robot at coordinates (0, i), and the i-th type-B robot at coordinates (K, i).
Thus, now we have one type-A robot and one type-B robot on each of the N lines y = 1, y = 2, ..., y = N.
When activated, each type of robot will operate as follows.
 - When a type-A robot is activated at coordinates (0, a), it will move to the position of the ball on the line y = a, collect the ball, move back to its original position (0, a) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything.
 - When a type-B robot is activated at coordinates (K, b), it will move to the position of the ball on the line y = b, collect the ball, move back to its original position (K, b) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything.
Snuke will activate some of the 2N robots to collect all of the balls. Find the minimum possible total distance covered by robots.

-----Constraints-----
 - 1 \leq N \leq 100
 - 1 \leq K \leq 100
 - 0 < x_i < K
 - All input values are integers.

-----Inputs-----
Input is given from Standard Input in the following format:
N
K
x_1 x_2 ... x_N

-----Outputs-----
Print the minimum possible total distance covered by robots.

-----Sample Input-----
1
10
2

-----Sample Output-----
4

There are just one ball, one type-A robot and one type-B robot.
If the type-A robot is used to collect the ball, the distance from the robot to the ball is 2, and the distance from the ball to the original position of the robot is also 2, for a total distance of 4.
Similarly, if the type-B robot is used, the total distance covered will be 16.
Thus, the total distance covered will be minimized when the type-A robot is used. The output should be 4.

Difficulty: EASY

Solutions:
N = int(input())
K = int(input())
X = list(map(int, input().split()))
sm = 0
for x in X:
	sm += min(x, K - x) * 2
print(sm)


n = int(input())
k = int(input())
x = list(map(int, input().split()))
res = 0
for i in x:
	res += min(i * 2, (k - i) * 2)
print(res)


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


n = int(input())
k = int(input())
x = list(map(int, input().split()))
ans = 0
for i in range(n):
	ans += 2 * min(x[i], k - x[i])
print(ans)


N = int(input())
K = int(input())
x = list(map(int, input().split()))
tot = 0
for i in range(N):
	if abs(x[i] - K) < x[i]:
		tot += 2 * abs(x[i] - K)
	else:
		tot += 2 * x[i]
print(tot)


n = int(input())
k = int(input())
X = list(map(int, input().split()))
ans = 0
for x in X:
	ans += min(x * 2, (k - x) * 2)
print(ans)


(N, K) = (int(input()), int(input()))
x = [int(i) for i in input().split()]
sum = 0
for i in x:
	sum += min(i * 2, (K - i) * 2)
print(sum)


N = int(input())
K = int(input())
x = list(map(int, input().split()))
ans = 0
for x in x:
	a = 2 * x
	b = abs(K - x) * 2
	ans += min(a, b)
print(ans)


(_, k, *x) = map(int, open(0).read().split())
print(sum((min(i, k - i) for i in x)) * 2)


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


N = int(input())
K = int(input())
x = list(map(int, input().split()))
total = 0
for i in range(N):
	if x[i] < K / 2:
		total += 2 * x[i]
	elif x[i] >= K / 2:
		total += 2 * (K - x[i])
print(total)


(N, K) = (int(input()), int(input()))
print(sum(map(lambda x: min(x, abs(x - K)) * 2, [int(x) for x in input().split()])))


N = int(input())
K = int(input())
L = list(map(int, input().split()))
print(2 * sum((min(l, abs(l - K)) for l in L)))


(N, K) = (int(input()) for T in range(0, 2))
X = [int(T) for T in input().split()]
print(sum((2 * min(TX, K - TX) for TX in X)))


input()
k = int(input())
(*x,) = map(int, input().split())
print(sum((min(i, abs(k - i)) for i in x)) * 2)


N = int(input())
K = int(input())
print(sum([min(int(a), K - int(a)) for a in input().split()]) * 2)


n = int(input())
k = int(input())
(*X,) = map(int, input().split())
s = 0
for x in X:
	s += min(x, k - x)
print(2 * s)


n = int(input())
k = int(input())
x_list = list(map(int, input().split()))
ans = 0
for i in x_list:
	if 2 * i < k:
		ans += 2 * i
	else:
		ans += (k - i) * 2
print(ans)


(N, K, *X) = map(int, open(0).read().split())
ans = 0
for i in range(N):
	ans += 2 * min(X[i], abs(X[i] - K))
print(ans)


N = int(input())
K = int(input())
X = map(int, input().split())
print(sum((2 * min(x, K - x) for x in X)))


(n, k, *x) = map(int, open(0).read().split())
d = 0
for c in x:
	d += min(2 * c, 2 * abs(c - k))
print(d)


N = int(input(''))
K = int(input(''))
a = input('').split(' ')
a = [int(aa) for aa in a]
ans = 0
for x in a:
	if K - x < x:
		ans += (K - x) * 2
	elif K - x >= x:
		ans += x * 2
print(ans)


N = int(input())
K = int(input())

def ans(s):
	n = int(s)
	return 2 * min(K - n, n)
x = list(map(ans, input().split()))
print(sum(x))


s = 0
input()
k = int(input())
for x in input().split():
	x = int(x)
	s += min(abs(k - x), x) * 2
print(s)


n = int(input())
k = int(input())
X = list(map(int, input().split()))
r = 0
for x in X:
	r += min(abs(k - x), x)
print(r * 2)


n = int(input())
k = int(input())
x = list(map(int, input().split()))
ans = 0
for xx in x:
	ans += min(xx, abs(k - xx)) * 2
print(ans)


n = int(input())
k = int(input())
x = list(map(int, input().split()))
c = 0
for i in range(len(x)):
	c += min(x[i], k - x[i]) * 2
print(c)


N = int(input())
K = int(input())
xn = list(map(int, input().split()))
print(sum((min(x * 2, abs(x - K) + (K - x)) for x in xn)))


import sys
input = sys.stdin.readline

def main():
	data = []
	n = int(input())
	k = int(input())
	data = list(map(int, input().split()))
	length = 0
	for ball in data:
		if ball < k - ball:
			length += 2 * ball
		else:
			length += 2 * (k - ball)
	print(length)

def __starting_point():
	main()
__starting_point()


n = int(input())
k = int(input())
x = list(map(int, input().split()))
print(sum([min(position, abs(k - position)) * 2 for position in x]))


n = int(input())
k = int(input())
x = list(map(int, input().split()))
a = 0
for i in range(n):
	a += min(abs(x[i] - k), x[i])
print(a * 2)


n = int(input())
k = int(input())
a = list(map(int, input().split()))
ans = 0
for i in a:
	ans += min(i, k - i)
print(ans * 2)


(_, k, *x) = map(int, open(0).read().split())
print(sum((i if k / 2 > i else k - i for i in x)) * 2)


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


(n, k, *a) = map(int, open(0).read().split())
ans = 0
for i in a:
	ans += 2 * min(i, k - i)
print(ans)


n = int(input())
k = int(input())
x = [int(i) for i in input().split()]
print(sum(map(lambda a: min(a, k - a), x)) * 2)


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


N = int(input())
K = int(input())
ans = 0
l_n = list(map(int, input().split()))
for i in l_n:
	ans += min(i, K - i) * 2
print(ans)


(N, K) = [int(input()) for _ in range(2)]
print(sum([2 * min(K - x, x) for x in map(int, input().split())]))


n = int(input())
k = int(input())
l = list(map(int, input().split()))
s = 0
for i in l:
	s += min(i, k - i)
print(2 * s)


import sys

def solve(N: int, K: int, x: 'List[int]'):
	return sum((min(xx, abs(xx - K)) for xx in x)) * 2

def main():

	def iterate_tokens():
		for line in sys.stdin:
			for word in line.split():
				yield word
	tokens = iterate_tokens()
	N = int(next(tokens))
	K = int(next(tokens))
	x = [int(next(tokens)) for _ in range(N)]
	print(solve(N, K, x))

def test():
	import doctest
	doctest.testmod()

def __starting_point():
	main()
__starting_point()


a = int(input())
b = int(input())
c = list(map(int, input().split()))
d = 0
for i in range(a):
	if c[i] < b - c[i]:
		d = d + c[i]
	else:
		d = d + b - c[i]
print(2 * d)


n = int(input())
k = int(input())
x = list(map(int, input().split()))
d = 0
for i in x:
	y = min(i, abs(k - i))
	d += 2 * y
print(d)


n = int(input())
k = int(input())
ans = [min(int(i), k - int(i)) for i in input().split()]
print(sum(ans) * 2)


N = int(input())
K = int(input())
X = list(map(int, input().split()))
ans = 0
for x in X:
	ans += 2 * (x if x <= K - x else K - x)
print(ans)


N = int(input().strip())
K = int(input().strip())
X = list(map(int, input().split()))
print(sum((min(x, abs(x - K)) * 2 for x in X)))


N = int(input())
K = int(input())
xs = list(map(int, input().split()))
dist_sum = 0
for i in range(N):
	y = i + 1
	x = xs[i]
	if x > K - x:
		dist_sum += (K - x) * 2
	else:
		dist_sum += x * 2
print(dist_sum)


n = int(input())
k = int(input())
xs = list(map(int, input().split()))
print(sum((min(x, k - x) * 2 for x in xs)))


from typing import List

def answer(n: int, k: int, xs: List[int]) -> int:
	moving_distance = 0
	reference_value = k / 2
	for x in xs:
		if x <= reference_value:
			moving_distance += x * 2
		else:
			moving_distance += (k - x) * 2
	return moving_distance

def main():
	n = int(input())
	k = int(input())
	xs = list(map(int, input().split()))
	print(answer(n, k, xs))

def __starting_point():
	main()
__starting_point()


(n, k, *x) = map(int, open(0).read().split())
print(sum(((2 * (k - i), 2 * i)[k - i > i] for i in x)))


n = int(input())
k = int(input())
l = list(map(int, input().split()))
ans = 0
for m in l:
	ans += min([k - m, m]) * 2
print(ans)


N = int(input())
K = int(input())
X = input().split()
cnt = 0
for x in X:
	cnt += min(int(x), K - int(x))
print(cnt * 2)


N = int(input())
K = int(input())
X = list([int(x) for x in input().split()])
result = 0
for pos in X:
	if pos <= abs(pos - K):
		result += 2 * pos
	else:
		result += 2 * abs(pos - K)
print(result)


n = int(input())
k = int(input())
x = list(map(int, input().split()))
l = []
for i in x:
	l.append(min(i, k - i))
print(sum(l) * 2)


import sys

def solve(N: int, K: int, x: 'List[int]'):
	res = 0
	for x_ in x:
		res += 2 * min(x_, abs(K - x_))
	print(res)
	return

def main():

	def iterate_tokens():
		for line in sys.stdin:
			for word in line.split():
				yield word
	tokens = iterate_tokens()
	N = int(next(tokens))
	K = int(next(tokens))
	x = [int(next(tokens)) for _ in range(N)]
	solve(N, K, x)

def __starting_point():
	main()
__starting_point()


n = int(input())
k = int(input())
xn = map(int, input().split())
print(sum([min(x, k - x) * 2 for x in xn]))


N = int(input())
K = int(input())
x = list(map(int, input().split()))
print(sum((2 * min(y, K - y) for y in x)))


N = int(input())
K = int(input())
A = map(int, input().split())
ans = [2 * min(a, K - a) for a in A]
print(sum(ans))


N = int(input())
K = int(input())
x = [int(i) for i in input().split()]
ans = 0
for i in range(N):
	xi = x[i]
	if xi <= K // 2:
		ans += 2 * xi
	else:
		ans += 2 * (K - xi)
print(ans)


def int_list(sepalate=' '):
	return list(map(int, input().split(sepalate)))

def solve1(n, k, x):
	ans = 0
	for i in range(n):
		ans += min(abs(k - x[i]), x[i]) * 2
	return ans
n = int(input())
k = int(input())
x = int_list()
print(solve1(n, k, x))


n = int(input())
k = int(input())
x = tuple(map(int, input().split()))
c = 0
for i in x:
	c += min(i, abs(i - k))
print(c * 2)


with open(0) as f:
	(N, K, *X) = map(int, f.read().split())
print(2 * sum((min(x, K - x) for x in X)))


import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce
rr = lambda : sys.stdin.readline().rstrip()
rs = lambda : sys.stdin.readline().split()
ri = lambda : int(sys.stdin.readline())
rm = lambda : list(map(int, sys.stdin.readline().split()))
rl = lambda : list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10 ** 9 + 7
n = ri()
k = ri()
ans = 0
for i in rl():
	ans += min(i, abs(k - i))
print(ans * 2)


N = int(input())
K = int(input())
X = list(map(int, input().split(' ')))
d = 0
for x in X:
	d += min(x * 2, abs(K - x) * 2)
print(d)


N = int(input())
K = int(input())
x = list(map(int, input().split()))
print(sum([min(x[i], abs(x[i] - K)) for i in range(N)]) * 2)


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


a = int(input())
b = int(input())
c = list(map(int, input().split()))
print(sum([min(i * 2, (b - i) * 2) for i in c]))


N = int(input())
K = int(input())
x = list(map(int, input().split()))
ans = [min(i, K - i) for i in x]
print(sum(ans) * 2)


N = int(input())
K = int(input())
print(sum([2 * min(int(xi), K - int(xi)) for xi in input().split()]))


N = int(input())
K = int(input())
ans = 0
for x in map(int, input().split()):
	ans += 2 * min(x, K - x)
print(ans)


N = int(input())
K = int(input())
X = [int(x) for x in input().split()]
ans = 0
for x in X:
	ans += min(x, abs(x - K))
ans *= 2
print(ans)


(N, K, *X) = map(int, open(0).read().split())
print(sum((2 * min(x, K - x) for x in X)))


N = int(input())
K = int(input())
X = [int(n) for n in input().split()]
ans = 0
for x in X:
	diff = abs(K - x)
	if diff < x:
		ans += diff
	else:
		ans += x
print(2 * ans)


N = int(input())
K = int(input())
X = list(map(int, input().split()))
Y = [i for i in range(1, N + 1)]
ans = 0
for x in X:
	distance_a = x
	distance_b = abs(K - x)
	if distance_a < distance_b:
		ans += distance_a
	else:
		ans += distance_b
print(ans * 2)


N = int(input())
K = int(input())
X = [int(i) for i in input().split(' ')]
print(sum([2 * min((x, abs(K - x))) for x in X]))


n = int(input())
k = int(input())
x = list(map(int, input().split()))
ans = 0
for i in range(n):
	if x[i] >= k - x[i]:
		ans += 2 * (k - x[i])
	else:
		ans += 2 * x[i]
print(ans)


n = int(input())
k = int(input())
x = [int(i) for i in input().split()]
cost = sum([min(i, k - i) * 2 for i in x])
print(cost)


n = int(input())
k = int(input())
v = list(map(int, input().split()))
ans = 0
for i in v:
	tmp = min(i, k - i)
	ans += tmp
print(ans * 2)


N = int(input())
K = int(input())
X = list(map(int, input().split()))
ans = 0
for i in range(N):
	if X[i] <= K - X[i]:
		ans += X[i] * 2
	else:
		ans += (K - X[i]) * 2
print(ans)


input()
k = int(input())
total = sum((min(int(tok), k - int(tok)) for tok in input().split()))
print(2 * total)


a = int(input())
b = int(input())
c = list(map(int, input().split()))
total = 0
for i in range(a):
	d = 2 * c[i]
	e = 2 * abs(b - c[i])
	total += min(d, e)
print(total)


n = int(input())
k = int(input())
xs = list(map(int, input().split()))
a = 0
for x in xs:
	a += 2 * min(x, k - x)
print(a)


N = int(input())
K = int(input())
x = list(map(int, input().split()))
s = 0
for i in x:
	s += min(i, K - i)
print(s * 2)


n = int(input())
k = int(input())
li = list(map(int, input().split()))
total = 0
for i in range(n):
	total += 2 * min(li[i], k - li[i])
print(total)


input()
K = int(input())
y = list(map(int, input().split()))
g = 0
for x in y:
	g += min(x, abs(x - K))
print(2 * g)


N = int(input())
K = int(input())
x = list(map(int, input().split()))
ans = 0
for i in x:
	if i <= K - i:
		ans += i
	if i > K - i:
		ans += K - i
print(2 * ans)


a = 0
n = int(input())
k = int(input())
l = list(map(int, input().split()))
for x in l:
	a += min(x, abs(x - k))
print(a * 2)


n = int(input())
k = int(input())
li = list(map(int, input().split()))
dis = 0
for i in range(n):
	dis += min(2 * li[i], 2 * abs(li[i] - k))
print(dis)


n = int(input())
k = int(input())
x = 0
a = list(map(int, input().split()))
for i in a:
	t = min(i, k - i)
	x += t
print(2 * x)


N = int(input())
K = int(input())
A = list(map(int, input().split()))
ans = 0
for a in A:
	ans += 2 * min(a, K - a)
print(ans)


import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):

	def assertIO(self, input, output):
		(stdout, stdin) = (sys.stdout, sys.stdin)
		(sys.stdout, sys.stdin) = (StringIO(), StringIO(input))
		resolve()
		sys.stdout.seek(0)
		out = sys.stdout.read()[:-1]
		(sys.stdout, sys.stdin) = (stdout, stdin)
		self.assertEqual(out, output)

	def test_入力例_1(self):
		input = '1\n10\n2'
		output = '4'
		self.assertIO(input, output)

	def test_入力例_2(self):
		input = '2\n9\n3 6'
		output = '12'
		self.assertIO(input, output)

	def test_入力例_3(self):
		input = '5\n20\n11 12 9 17 12'
		output = '74'
		self.assertIO(input, output)

def resolve():
	N = int(input())
	K = int(input())
	X = list(map(int, input().split()))
	ans = 0
	for x in X:
		ans += min(x * 2, abs(K - x) * 2)
	print(ans)

def __starting_point():
	resolve()
__starting_point()


n = int(input())
k = int(input())
p = 0
for i in list(map(int, input().split())):
	p += min(i, k - i) * 2
print(p)


input()
K = int(input())
ans = [min(x - 0, K - x) for x in list(map(int, input().split()))]
print(sum(ans) * 2)


import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20

def I():
	return int(input())

def F():
	return float(input())

def S():
	return input()

def LI():
	return [int(x) for x in input().split()]

def LI_():
	return [int(x) - 1 for x in input().split()]

def LF():
	return [float(x) for x in input().split()]

def LS():
	return input().split()

def resolve():
	N = I()
	K = I()
	x = LI()
	ans = sum([2 * min(x[i], K - x[i]) for i in range(N)])
	print(ans)

def __starting_point():
	resolve()
__starting_point()