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):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')


def A():
    n, a = II(), II()
    print(n * n - a)
    return


def B():
    n = II()
    k = II()
    x = LI()
    ans = 0
    for xi in x:
        ans += min(xi, k - xi)
    print(ans * 2)
    return


def C():
    return


def D():
    return


if __name__ == '__main__':
    B()

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

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

dist = 0

for x in x_list:
    if (K / 2) > x:
        dist += 2*x
    else:
        dist += 2*abs(x - K)

print(dist)

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

Solution (Python):

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

X = [int(el) for el in input().split(' ')]

total = 0
for x in X:
    if x < abs(k-x):
        total += 2*x
    else:
        total += 2*abs(k-x)
print(total)

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

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 = list(map(int, input().split()))
ans = 0
for i in range(n):
  if k /2  > 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 x in X:
  d=min(x, abs(x-k))
  ans+=2*d
print(ans)

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 / 2:
        ans += x[i] * 2
    else:
        ans += (K - x[i]) * 2
        
print(ans)

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

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

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

isum = 0

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

print(isum*2)

Solution (Python):
N = int(input())
K = int(input())
x = [int(i) for i in input().split()]
ans = 0
for i in range(N):
    num = min(2 * abs(x[i]), 2 * abs(x[i]- K))
    ans += num
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], k-x[i])*2
print(ans)

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

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

Solution (Python):
a = int(input())
b = int(input())
c = list(map(int,input().split()))
d = []

for i in range(a):
  d.append(2*min(c[i],abs(c[i]-b)))
else:
  print(sum(d))

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

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

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

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

print(ans)

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

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

total = 0
for x in xlist:
    y = abs(x-K)
    if x > y:
        total = total + 2*y
    else:
        total = total + 2*x

print(total)

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

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

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

print(ans)

Solution (Python):



N = int(input())
K = int(input())
x_list = [int(i) for i in input().split()]
dist = 0

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

Solution (Python):


def solve():
    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)

if __name__ == "__main__":
    solve()

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

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

Solution (Python):
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N = n()
K = n()
X = nl()

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

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],K-x[i])*2
print(ans)

Solution (Python):
N = int(input())
K = int(input())
l = [int(i) for i in input().split()]
zero_kyori = 0
K_kyori = 0
kyori_list = []

for i in range(N):
    zero_kyori = (l[i] - 0) * 2
    K_kyori = (abs(l[i] - K)) * 2
    kyori_list.append(min(zero_kyori, K_kyori))

print(sum(kyori_list))

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


abc()

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

a=0
b=k

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


ans=[]

for i in range(n):
    ans.append(min(abs((nums[i]-a)*2),abs((b-nums[i])*2)))
print(sum(ans))

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

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

print(ans)

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

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

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

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

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


main()

Solution (Python):
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys
import string

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

N, K = [int(sys.stdin.readline()) for _ in range(2)]
X = np.array(list(map(int, sys.stdin.readline().split())))

print(np.minimum(X, abs(X - K)).sum() * 2)

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

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

Solution (Python):

import time
import re
import math

def main():
    n=int(input())
    k=int(input())
    X=map(int,input().split())
    total=0
    for a in X:
        total+=min([a,abs(k-a)])*2
    print(int(total))
main()

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) * 2
print(ans)

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

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

print(answer)

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

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

Solution (Python):
N = int(input())
K = int(input())
x = list(map(int,input().split()))
sum = 0
for i in range(N):
  sum += min(x[i]*2,abs(x[i]-K)*2)
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(2 * x[i], 2 *abs(x[i]-K))

print (ans)

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

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

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

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

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

print(ans)

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

cnt = 0
for i in x:
    cnt += min(i,k-i)

print(cnt*2)

Solution (Python):

import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())


N = int(input())
K = int(input())
Xs = list(mi())

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

print(ans)

Solution (Python):
n = int(input())
k = int(input())
x = [int(i) for i in input().split()]
sum = 0
for i in x:
    sum += 2*min(i, k-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], k-x[i])

print(ans*2)

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])
print(a*2)

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

Solution (Python):

import sys


def solve(N: int, K: int, X: "List[int]"):
    ret = 0
    for x in X:
        ret += min(abs(K - x), x) * 2
    print(ret)
    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)

if __name__ == '__main__':
    main()

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

Solution (Python):
def smaller(x, y):
	if x < y: return x
	return y

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

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

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

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

ans = 0

for i in axis:
    if i >= k/2:
        ans += (k -i)*2
    else:
        ans += i*2
print(ans)

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

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

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

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

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

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

Solution (Python):
import math


def main():
    num = int(input())
    k = int(input())
    data = list(map(int, input().split()))

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





if __name__ == '__main__':
    main()

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

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

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

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

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

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

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

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

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()))
ans = 0
for i in x:
    ans += min(i,abs(k-i))*2
print(ans)

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

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

for i in xs:
  if abs(K - i) < i:
    dist += abs(K - i)*2
  else:
    dist += i*2
    
print(dist)

Solution (Python):
n = int(input())
k = int(input())
x = list(map(int,input().split()))
sum =0 
for i in x:
    sum += min(abs(i-0),abs(i-k))*2
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]*2,abs(k-x[i])*2)
print(ans)

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

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]-0,K-x[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()))
cnt = 0
for i in A:
  cnt += min(abs(K-i), (i))*2
print(cnt)

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

ans = sum([min([x, abs(x-K)]) * 2 for x in X])

print(ans)

Solution (Python):

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

sm=0
for x in l:
  sm+=min(x,K-x)*2


print(sm)

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

Solution (Python):
from sys import stdin
N = int(stdin.readline().rstrip())
K = int(stdin.readline().rstrip())
X = [int(_) for _ in stdin.readline().rstrip().split()]
ans = 0
for i in X:
    if i < K - i:
        ans += 2 * i
    else:
        ans += 2 * (K - i)
print(ans)

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

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

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

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

Solution (Python):
n=int(input())
k=int(input())
ans=[min(int(i),k-int(i)) for i in input().split()]
print(sum(ans)*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], abs(x[i] - k))
  
print(ans * 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],K-x[i])
print(ans*2)

Solution (Python):
n = int(input())
k = int(input())
x = [int(i) for i in 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()))
ans = 0
for i, j in enumerate(x):
    ans += 2 * min(j, abs(k - j))
print(ans)

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

Solution (Python):
input()
K=int(input())
print(sum([min(int(i),K-int(i))*2 for i in input().split()]))

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

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

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],k-x[i])*2
print(ans)

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

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

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

print(ans)

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

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

ans=0

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

print(ans)

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

Solution (Python):


N = int(input())
K = int(input())
Xn = list(map(int, input().split()))
ans = 0
for i in range(N):
  ans += min(Xn[i],K-Xn[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):
    type_a = abs(x[i]-0) * 2
    type_b = abs(x[i]-k) * 2
    ans += min(type_a, type_b)
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(2*x[i], 2*abs(k-x[i]))
print(ans)

Solution (Python):

def read_input():
    n = int(input())
    k = int(input())
    xlist = list(map(int, input().split()))

    return n, k, xlist


def submit():
    n, k, xlist = read_input()

    dist = 0
    for x in xlist:
        adist = 2 * x
        bdist = 2 * (k - x)

        dist += min(adist, bdist)

    print(dist)

if __name__ == '__main__':
    submit()

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

s = 0
for y in x:
    s += min(y,abs(K-y))*2

print(s)

Solution (Python):
import sys
from collections import Counter

n = int(input())
k = int(input())
x_list = list(map(int, input().split()))
ans = 0

for i in x_list:
    if k - i < i:
        ans += (k - i) * 2
    else:
        ans += i * 2

print(ans)

Solution (Python):

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

Solution (Python):
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n = f()[0]
    k = f()[0]
    x = f()

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

    print(ans)

solve()

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

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

Solution (Python):
from functools import reduce
import math

def main():
    
    
    
    

    
    
    
    
    
    

    
    

    
    
    
    
    
    
    
    
    
    INF = float("inf")

    
    MOD = 10**9+7
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
    
    
    
    N = int(input())
    K = int(input())
    x = list(int(_) for _ in input().split())
    ans = 0
    for i in range(N):
        ans += min(x[i],K-x[i]) * 2
    print(ans)
    
if __name__ == '__main__':
    main()

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

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

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

Solution (Python):
N = int(input())
K = int(input())
X = list(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()))

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

Solution (Python):
N, K = eval("int(input())," * 2)
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())
x = [min(int(i), K-int(i)) * 2 for i in input().split()]
print(sum(x))

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],abs(k-x[i]))

print(cnt*2)

Solution (Python):
N = int(input())
K = int(input())
X = list(map(int,input().split()))
ans = 0
for x in X:
    ans1 = min(abs(x), abs(x - K))
    ans += ans1 * 2
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(x[i],abs(k-x[i]))
print(cnt*2)

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

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

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

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

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

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

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

print(total)

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

print(sum*2)

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

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

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

for i in x:
	if i <= abs(k-i):
		kyori += i*2
	else:
		kyori += abs(k-i)*2
print(kyori)

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

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

Solution (Python):
import math
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
K = I()
x = IL()

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

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

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

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

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

print(l)

Solution (Python):
n = int(input())
k = int(input())
x = [int(item) for item in input().split()]
ans = 0
for x_ in x:
    ans += min(abs(x_-0), abs(x_-k)) * 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(x[i],k-x[i])
print(ans*2)

Solution (Python):
N = int(input())
K = int(input())
Xs = sorted(map(int,input().split()))
ans = 0
for x in Xs:
    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 xi in x:
    ans += 2 * min(xi, K - xi)
print(ans)

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

Solution (Python):
_,k,t=open(0);print(sum(min(x,int(k)-x)*2for x in map(int,t.split())))

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

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

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

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

print(sum_len)

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

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

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(x[i],abs(k-x[i]))
print(l)

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

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

ans = sum(min(v * 2, abs(k - v) * 2) for v in x)
print(ans)

Solution (Python):

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

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