Problem:
 Score : 200 points    Problem Statement 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 1
10
2      Sample Output 1 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 .       Sample Input 2 2
9
3 6      Sample Output 2 12  The total distance covered will be minimized when the first ball is collected by the type-A robot, and the second ball by the type-B robot.       Sample Input 3 5
20
11 12 9 17 12      Sample Output 3 74

Solution (Python):
n = int(input())
k = int(input())
bList = list(map(int,input().split()))

result = 0
for i in range(n):
  if bList[i] >= k/2:
    result += abs(bList[i]-k)*2
  else:
    result += bList[i]*2

print(result)

Solution (Python):
N = int(input())
K = int(input())
positions = [int(x) for x in input().split()]

ans = 0
for x in positions:
    ans += min(x, abs(K-x)) * 2
print(ans)

Solution (Python):


import numpy as np

n=int(input())
k=int(input())

x=[int(p) for p in input().split()]

ans=0
for y in x:
    ans+=min(y,k-y)*2

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
K = int(input())
x = [int(i) for i in input().split()]
sum = 0
for i in range(N) :
    l = min(x[i],K -x[i])
    sum+=2 * l
print(sum)

Solution (Python):
n = int(input())
k = int(input())

l = [int(i) for i in input().split()]
s = 0

for i in range(n):
  if k - l[i] >= l[i]:
    s += l[i]  * 2
 
  elif k - l[i] < l[i]:
    s += 2 * (k - l[i])
    
print(s)

Solution (Python):
n = int(input())
k = int(input())
x = [int(i) for i in input().split()]

d = []
for ball in x:
   robot_a = 2 * ball
   robot_b = 2 * (k - ball)
   if(robot_a <= robot_b):
      d.append(robot_a)
   else:
      d.append(robot_b)
print(sum(d))

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

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

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

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

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

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

Solution (Python):
n = int(input())
k = int(input())
x = list(map(int, input().split()))

res = 0

for i in range(n):
    res += min(x[i], k-x[i])*2
print(res)

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
K = int(input())
x = [int(x) for x in input().split()]
total = 0
for i in range(N):
    total += 2 * min(abs(K - x[i]), x[i])
print(total)

Solution (Python):
N = int(input())
K = int(input())
mylist=[]
count=0
x = list(map(int, input().split()))

for i in range(N):
    if K-x[i]>=x[i]:
        count=count+x[i]*2
    else:
        count=count+(K-x[i])*2
print(count)

Solution (Python):


n = int(input())
k = int(input())
x = list(map(int, input().split()))

d = 0
for i in range(n):
    d += min(x[i], k-x[i])*2

print(d)

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

Solution (Python):

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

Solution (Python):
N = int(input())
K = int(input())
A = list(map(int, input().split()))

ans = 0
for a in A:
  _min = min(a, K-a)
  ans += _min*2
print(ans)

Solution (Python):
n = int(input())
k = int(input())
x = list(map(int, input().split()))
dis = 0

for i in range(n):
    if x[i]<k-x[i]:
        dis += 2*x[i]
    else:
        dis += 2*(k-x[i])

print(dis)

Solution (Python):
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)

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

Solution (Python):

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)

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

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

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

Solution (Python):
N=int(input())
K=int(input())
A=map(int,input().split())


ans=0
for a in A:
    ans+=2*(min(a,K-a))
print(ans)

Solution (Python):
N = int(input())
K = int(input())
k = K / 2

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

Solution (Python):
n=int(input())
k=int(input())
X=list(map(int,input().split()))
print(sum(min(abs(x-k),x)*2 for x in X))

Solution (Python):
N = int(input())
K = int(input())
X = map(int, input().split())

ans=0
for x in X:
    ans += min(x, abs(x - K)) * 2
print(ans)

Solution (Python):
n=int(input())
k=int(input())
x=map(int,input().split())
count=0
for i in x:
  if i<(k-i):
    count+=i*2
  else:
    count+=(k-i)*2
print(count)

Solution (Python):
N = int(input())
K = int(input())
A = [int(x) for x in input().split()]

ans = 0
for a in A:
	ans += min(a, abs(K-a))*2
print(ans)

Solution (Python):
N = int(input())
K = int(input())
x = list(map(int, input().split()))
ans = 0
for i in range(N): ans += min(abs(x[i] - 0,), abs(x[i] - K))
print(ans * 2)

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

Solution (Python):
import sys
import numpy as np 

I = np.array(sys.stdin.read().split(), dtype=np.int64)
n, k = I[:2]
x = I[2:]

def main():
    d = np.minimum(x, k - x)
    return np.sum(d) * 2

if __name__ == '__main__':
    ans = main()
    print(ans)

Solution (Python):
n=int(input())
k=int(input())
a= [int(i) for i in input().split()]
kyori=0
for i in range(n):
    kyori+=min(2*a[i],2*(k-a[i]))
print(kyori)

Solution (Python):
import sys

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))  
rs = lambda: stdin.readline().rstrip()  

N = ri()
K = ri()
X = rl()
answer = 0
for i in range(N):
    answer += min(X[i], abs(X[i]-K))
print(answer * 2)

Solution (Python):
n = int(input())
k = int(input())
x = list(map(int, input().split()))

cnt = 0

for i in range(n):
    cnt += min(x[i] * 2, (k - x[i]) * 2)

print(cnt)

Solution (Python):
import sys
n = int(input())
k = int(input())

x = list(map(int, sys.stdin.readline().split()))

sum = 0
for i in range(n):
    sum += 2 * min(x[i], k - x[i])

print(sum)

Solution (Python):
n = int(input())
k = int(input())
x = list(map(int, input().split()))

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

Solution (Python):
n=int(input())
k=int(input())
x=[int(i) for i in input().split()]
ans=0
for i in x:
    if(abs(i-0)<abs(i-k)):
        ans+=abs(i-0)*2
    else:
        ans+=abs(i-k)*2
print(ans)

Solution (Python):
n = int(input())
k = int(input())
b = list(map(int, input().split())) 

sum = 0
for ball in b:
  sum += ball - 0 if (ball - 0) < k - ball else k - ball
  
print(sum*2)

Solution (Python):
N = int(input())
K = int(input())
x = list(map(int, input().split()))

ans = 0
for i in range(N):
    ans += min(x[i]*2, abs(x[i]-K)*2)

print(ans)

Solution (Python):
N = int(input())
K = int(input())
X = list(map(int, input().split()))
print(2*sum([min(x, K-x) for x in X]))

Solution (Python):
n = int(input())
k = int(input())

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

Solution (Python):
n = int(input())
k = int(input())
x = list(map(int, input().split()))

ans = 0

for _x in x:
    ans += min(k-_x, _x)
print(ans * 2)

Solution (Python):
n = int(input())
k = int(input())
X = list(map(int, input().split()))

K_X = [abs(x-k) for x in X]

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)

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

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

Solution (Python):
n = int(input())
k = int(input())
*x, = map(int, input().split())

ans = 0
for _x in x:
    ans += 2*min(_x, k-_x)

print(ans)

Solution (Python):
n = int(input())
k = int(input())
X = list(map(int,input().split()))
dist = []
for x in X:
  dist.append(min(abs(k - x) * 2,abs(0 - x) * 2))
print(sum(dist))

Solution (Python):
n = int(input())
k = int(input())
xl = list(map(int,input().split()))

ans = 0
for x in xl:
    ans += min(2*x, 2*(k-x))

print(ans)

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

Solution (Python):
N = int(input())
K = int(input()) 
X = list(map(int, input().split()))

len_X = len(X)

ans = 0

for i in range(len_X):
    if abs(K-X[i])*2 <= abs(X[i])*2:
        ans = ans + (abs(K-X[i])*2)
    else:
        ans = ans + (abs((X[i])*2))

print(ans)

Solution (Python):
n=int(input())
k=int(input())
l=input().split()
m=0
for x in range(len(l)):
    m+=2*min(int(l[x]),k-int(l[x]))
else:
    print(m)

Solution (Python):
N= int(input())
K = int(input())
X= list(map(int, input().split()))
Answer = 0
for i in range(N):
  Answer += min(K-X[i],X[i])*2
print(Answer)

Solution (Python):
N=int(input())
K=int(input())
A=[int(x) for x in input().split()]
result=0
for i in range(N):
  result +=min(abs(A[i]),abs(A[i]-K))
print(result*2)

Solution (Python):
N = int(input())
K = int(input())
x = list(map(int,input().split()))
ans = 0
for i in range(N):
    distance = min(x[i] , K - x[i])
    ans += distance * 2
print(ans)

Solution (Python):
n = int(input())
k = int(input())
ls_x = list(map(int, input().split()))

d = 0 

for i in range(n):
    d += min(2 * ls_x[i], 2 * abs(k - ls_x[i]))

print(d)

Solution (Python):
n = int(input())
b = int(input())
d = list(map(int, input().split()))
c = 0
for i in d:
    if i < b - i:
        c += i
    else:
        c += b-i
print(c*2)

Solution (Python):
n, k = int(input()), int(input())
lst = [int(i) for i in input().split()]
d = 0
for i in lst:
    d += min(i, k - i) * 2
print(d)

Solution (Python):
N=int(input())
K=int(input())
x=list(map(int,input().split()))
summary=0
for i in x:
    if i>abs(i-K):
        summary=summary+2*(abs(i-K))
    else:
        summary=summary+2*(i)

print(summary)

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

Solution (Python):
n = int(input())
k = int(input())
xs = list(map(int,input().split()))
ans = 0

for x in xs:
  ans += min(x,k-x)
print(ans*2)

Solution (Python):
n = int(input())
k = int(input())
ans = 0
for a in map(int,input().split()):
  mn = min(a, k-a)
  ans += mn * 2

print(ans)

Solution (Python):
n, k, *x = map(int, open(0).read().split())
distance = 0 
for i in x:
        distance += min(i * 2, (k - i) * 2)
print(distance)

Solution (Python):

N = int(input())
K = int(input())
x = list(map(int,input().split()))
S = 0

for i in range(N):
    if x[i] <= K - x[i]:
        S += 2*x[i]
    else:
        S += 2*(K - x[i])

print(S)

Solution (Python):
N=int(input())
K=int(input())
X=list(map(int,input().split()))
ans=0
for i in range(len(X)):
  ans+=min(abs(X[i]),K-abs(X[i]))*2
print(ans)

Solution (Python):
n = int(input())
k = int(input())
A = list(map(int,input().split()))

ans = 0
for a in A:
    ans += min(a,abs(k-a))*2
print(ans)

Solution (Python):
N = int(input())
K = int(input())
ans = 0
for x in [int(i) for i in input().split()]:
    if K - x < x:
        ans += (K - x) * 2

    else:
        ans += x * 2
print(ans)

Solution (Python):
N = int(input())
K = int(input())
x = list(map(int, input().split()))
total_distance = 0

for i in range(N):
    ball_p = x[i]
    total_distance += min(ball_p, abs(ball_p - K)) * 2

print(total_distance)

Solution (Python):


N=int(input())
K=int(input())
X=list(map(int,input().split(" ")))
dsum=0 


for xi in range(len(X)):
    dsum+=(min(X[xi],K-X[xi]))*2

print(dsum)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    n=int(input())
    k=int(input())
    xx=LI()
    ans=0
    for x in xx:
        ans+=min(x,k-x)
    print(ans*2)

main()

Solution (Python):
n = int(input())
k = int(input())
x = list(map(int, input().split()))

s = 0
for i in range(n):
	s += 2 * min(x[i], k-x[i])
print (s)

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,K,*X=map(int,open(0).read().split())
    ans = 0
    for x in X:
        ans += min(abs(x-K), abs(x))
    print(2 * ans)
if __name__ == '__main__':
    main()

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

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

Solution (Python):
from sys import stdin
inf = 10**3
n = int(stdin.readline().rstrip())
k = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

point = 0

for i in li:
    if abs(i-k) >= i:
        point += 2*i
    else:
        point += abs(i-k)*2

print(point)

Solution (Python):
N = int(input())
K = int(input())
x = list(map(int,input().split()))
a = 0
for i in range(N):
  a += min(K-x[i],x[i]) * 2
print(a)

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

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

Solution (Python):
n = int(input())
k = int(input())
a = list(map(int,input().split()))


b = list(map(lambda x: k-x, a))



ans = 0

for i in range(n):
	if a[i]<=b[i]:
		
		ans = ans + a[i]*2
	else:
		
		ans = ans + b[i]*2

print(ans)

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

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

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

Solution (Python):
N = int(input())
K = int(input())
X = list(map(int, input().split()))

print(sum(min(x, K - x) for x in X) * 2)

Solution (Python):
N = int(input())
K = int(input())
x = [int(i) for i in input().split()]

o = []
for i in x:
    o.append(min([i, abs(i - K)]))

print(sum(o)*2)

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

Solution (Python):
N = int(input())
K = int(input())
x = [int(i) for i in input().split()]

o = []
for i in x:
    o.append(min([abs(i - 0),abs(i - K)]))

print(sum(o)*2)

Solution (Python):
n,k=int(input()),int(input())
x=list(map(int,input().split()))

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

print(ans)

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

Solution (Python):
def examB():
    N = I(); K = I(); x = LI()
    ans = 0
    for i in range(N):
        ans += min(abs(0-x[i]),abs(K-x[i]))
    print(ans*2)

import sys
import copy
import bisect
import heapq
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examB()

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

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

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

Solution (Python):

n = int(input())
k = int(input())
x = [int(s) for s in input().split()]

distance = 0

for i in range(n):
    distance += min(x[i], k - x[i])

print(distance * 2)

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

Solution (Python):
N, K = [int(input()) for _ in range(2)]
x = list(map(int, input().split()))

ans = 0

for i in range(N):
  ans += 2 * min(x[i], abs(x[i]-K))
  
print(ans)

Solution (Python):


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

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

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

Solution (Python):
n = int(input())
k = int(input())

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

print(ans)

Solution (Python):
N = int(input())
K = int(input())
x_list = [int(e) for e in input().split()]

ans = 0

for i in range(N):
  ans += min(2*x_list[i],2*(K-x_list[i]))
  
print(ans)

Solution (Python):
N=int(input())
K=int(input())
x=list(map(int,input().split()))

L=0
for i in range(N):
    L+=2*min(abs(x[i]),abs(x[i]-K))
print(L)

Solution (Python):
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)

Solution (Python):
N=int(input())
K=int(input())
A=[int(x) for x in input().split()]
result=0
for i in range(N):
  result +=min(abs(A[i]),abs(A[i]-K))
print(result*2)

Solution (Python):
N = int(input())
K = int(input())
xlist = list(map(int, input().split()))
counter = 0
for x in xlist:
    if x < abs(K - x):
        counter += x * 2
    else:
        counter += abs(K - x) * 2

print(counter)

Solution (Python):
from sys import stdin
n, k, *x = (int(i) for i in stdin.read().split())
total_dist = 0
for i in range(n): total_dist += min(x[i], k - x[i]) * 2
print(total_dist)

Solution (Python):
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)

Solution (Python):
N = int(input())
K = int(input())
x = list(map(int, input().split()))
ans = 0
for i in range(N):
    ans += 2 * min(abs(K-x[i]), x[i])
print(ans)

Solution (Python):
N = int(input())
K = int(input())
x = list(map(int,input().split()))
count = 0
for i in range(len(x)):
    count += min([x[i]*2,abs(x[i]-K)*2])
print(count)

Solution (Python):
N = int(input())
K = int(input())
X = map(int, input().split())

ans = 0
for x in X:
    ans += min(abs(x), abs(x-K))
print(ans*2)

Solution (Python):
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(K, inputs):
    balls = string_to_int(inputs[0])
    distance = 0
    for b in balls:
        if b > abs(b - K):
            distance += abs(b - K) * 2
        else:
            distance += b * 2
    return distance


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    N = int(input())
    K = int(input())
    ret = solve(K, inputs(1))
    print(ret)

Solution (Python):
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)

Solution (Python):
N = int(input())
K = int(input())
X = [int(i) for i in input().split()]

ans = 0
for x in X:
  if abs(K-x) < x:
    ans += (K-x) * 2
  else:
    ans += x * 2

print(ans)

Solution (Python):
N = int(input())
K = int(input())
X = list(map(int, input().split()))

distance = 0
for x in X:
  distance += min(x, K-x) * 2

print(distance)

Solution (Python):
n = int(input())
k = int(input())
list_x = list(map(int, input().split()))

count = 0
for i in range(n):
  count += min(list_x[i], k-list_x[i]) * 2
print(count)

Solution (Python):
N = int(input())
K = int(input())
Data = list(map(int,input().split()))
ans = 0
for d in Data:
    ans += min(d,abs(d-K))*2
print(ans)

Solution (Python):
n=int(input());k=int(input())
x = [int(_) for _ in input().split()]
print(sum(min(x[i]*2, (k-x[i])*2) for i in range(len(x))))

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

Solution (Python):
N = int(input())
K = int(input())
lst = map(int, input().split())
ret = 0
for n in lst:
    ret += min(n - 0, abs(n - K)) * 2
print(ret)

Solution (Python):
N=int(input())
K=int(input())
X=list(map(int,input().split()))

ans=0
for i in range(N):
    ans+=min(X[i]*2,(K-X[i])*2)

print(ans)

Solution (Python):
n = int(input())
k = int(input())
X = map(int, input().split())
ans = [min(x,abs(x-k)) for x in X]
print(sum(ans)*2)

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    k = int(input().rstrip('\n'))
    x = list(map(int, input().rstrip('\n').split()))
    t = 0
    for i in range(n):
        t += (min(abs(x[i]), abs(k - x[i])) * 2)
    print(t)


if __name__ == '__main__':
    slove()

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    k = int(input().rstrip('\n'))
    x = list(map(int, input().rstrip('\n').split()))
    t = 0
    for i in range(n):
        t += (min(abs(x[i]), abs(k - x[i])) * 2)
    print(t)


if __name__ == '__main__':
    slove()

Solution (Python):
n = int(input())
k = int(input())
balls = list(map(int, input().split()))
sum = 0
for ball in balls:
  sum += min(ball, k-ball)*2
print(sum)

Solution (Python):
n = int(input())
k = int(input())
x = list(map(int, input().split()))

dist = 0
for i in x:
    dist += 2*min( abs(k-i), i )
print(dist)

Solution (Python):
def resolve():
    n = int(input())
    k = int(input())
    x = list(map(int, input().split()))
    print(sum([2 * min(xi, k - xi) for xi in x]))


if __name__ == "__main__":
    resolve()

Solution (Python):
def resolve():
    n = int(input())
    k = int(input())
    x = list(map(int, input().split()))
    ans = sum([2 * min(xi, k - xi) for xi in x])
    print(ans)


if __name__ == "__main__":
    resolve()

Solution (Python):
def resolve():
    n = int(input())
    k = int(input())
    x = list(map(int, input().split()))
    ans = sum([min(2 * xi, 2 * (k - xi)) for xi in x])
    print(ans)
        

if __name__ == "__main__":
    resolve()

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

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

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

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

Solution (Python):
N = int(input())
K = int(input())
X = list(map(int,input().split()))
cnt = 0
for i in range(N):
    x = X[i]
    cnt += 2*min(K-x,x)
print(cnt)

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

Solution (Python):

N = int(input())
K = int(input())
X = list(map(int,input().split()))

ans = 0

for x in X:
    ans += min(2*x,2*abs(K-x))

print(ans)

Solution (Python):
n = int(input())
k = int(input())
X = list(map(int, input().split()))

ans = 0
for x in X:
    ans += min(x, k-x)

print(ans*2)

Solution (Python):
N = int(input())
K = int(input())

x = list(map(int, input().split()))

cnt = 0
for i in range(N):
    cnt +=  min(x[i]*2, (K-x[i])*2)

print(cnt)

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

Solution (Python):
n = int(input())
k = int(input())
X = list(map(int,input().split()))

d = 0
for i in range(n):
    d += min(X[i],k-X[i])*2

print(d)

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

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    n = int(input())
    k = int(input())
    x = list(map(int, input().split()))

    ans = 0
    for i in x:
        ans += min(i, k-i) * 2
    print(ans)


if __name__ == '__main__':
    main()

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

Solution (Python):
N = int(input())
K = int(input())
x = map(int, input().split())

ans = 0
for xi in x:
  ans += min(xi, abs(xi-K)) * 2
  
print(ans)

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

Solution (Python):
n=int(input())
k=int(input())
x=list(map(int,input().split()))

total=0
for c in x:
    ax=abs(c-0)
    bx=abs(k-c)
        
    a=2*ax
    b=2*bx
    total +=min(a,b)
    
print(total)

Solution (Python):
n = int(input())
k = int(input())
x_list = list(map(int, input().split()))

res = 0

for x in x_list:
    a = x * 2
    b = abs(k - x) * 2
    res += min(a, b)

print(res)

Solution (Python):
n=int(input())
k=int(input())
x=[min(int(j),k-int(j)) for j in input().split()]
print(2*sum(x))

Solution (Python):
n = int(input())
k = int(input())
x = list(map(int,input().split()))

ans = 0
for i in range(n):
  if x[i]<=abs(k-x[i]):
    ans+=x[i]*2
  else:
    ans+=(k-x[i])*2
print(ans)

Solution (Python):
n = int(input())
k = int(input())
X = list(map(int, input().split()))

counter = 0
for i in range(n):
  counter += min(X[i], k - X[i])
print(counter * 2)

Solution (Python):
n = int(input())
k = int(input())
x = list(map(int, input().split()))

ans = 0
for i in x:
    ans += min(i * 2, (k - i) * 2)
print(ans)

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

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

Solution (Python):
N,K,*x =map(int,open(0).read().split())
print(sum(2*[min(i,K-i) for i in x]))