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):
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

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

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

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

for i in range(len(x)):
  dist_a = x[i] * 2
  dist_b = abs(K - x[i]) * 2
  if dist_a < dist_b:
    sum += dist_a
  else:
    sum += dist_b

print(sum)

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

a = 0 

ans = 0

for i in range(N):

    if K>x[i]:
        a = K - x[i]
    else:
        a = x[i] - K
    
    if x[i]<a:
        ans += x[i]
    else:
        ans += a

print(str(ans * 2))

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

tmp = []
for i in x:
    tmp.append((min(abs(K-i), i))*2)
print(sum(tmp))

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())
X = list(map(int, input().split()))
ans = 0

for i in range(n):
    if k - X[i] >= X[i]:
        ans = ans + X[i] * 2
    else:
        ans = ans + (k - X[i] ) * 2

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

print(ans)

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

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

x_list = [int(i) for i in input().split()]

th = k // 2

dis = 0
for x in x_list:
    if x <= th:
       dis += x*2
    else:
       dis += (k - x) * 2

print(dis)

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(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 range(N):
    if abs(K-X[i]) >= X[i]:
        ans += X[i]
    else:
        ans += abs(K-X[i])
print(ans*2)

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

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

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

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

sumX = 0
for y in x:
    if K / 2 < y:
        sumX += (K - y) * 2
    else:
        sumX += y * 2
print(sumX)

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):
N = int(input())
K = int(input())
l = list(map(int, input().split()))

ans = 0
for i in l:
  ans += min([K-i, i])*2
  
print(ans)

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

print(ans)

Solution (Python):

import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, K: int, x: "List[int]"):
    print(sum(min(xi, K - xi) for xi 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)]  
    solve(N, K, x)


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):
    ans+=min(X[i],k-X[i])*2
print(ans)

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

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

print(ret)

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

Solution (Python):
n = int(input())
k = int(input())
x = list(map(int,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*2, abs(i-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]-0)*2,(abs(x[i]-k))*2)

print(ans)

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

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

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

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

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

print(sumval)

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()]

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

print(ans)

Solution (Python):


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)

Solution (Python):
totalball = int(input())
K = int(input())
basyo = map(int, input().split())
out = 0
for i in basyo:
  A = i - 0
  B = K - i
  if A > B:
    out = out + B*2
  else:
    out = out + A*2
print(out)

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

Solution (Python):


N = int(input().strip())
K = int(input().strip())
x_list = list(map(int, input().rstrip().split()))


sum = 0
for x in x_list:
    dist_0 = abs(x)
    dist_K = abs(x-K)
    sum += min(dist_0 , dist_K) * 2

print(sum)

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

Solution (Python):

def main():
    import sys
    
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    
    from itertools import combinations, permutations
    
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    

    

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

if __name__ == '__main__':
    main()

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

def calcDist(ball):
    robot_A_dist = abs(0-ball)
    robot_B_dist = abs(K-ball)
    if robot_A_dist <= robot_B_dist:
        return robot_A_dist * 2
    else :
        return robot_B_dist * 2
    
cnt = 0    
for ball in balls:
    cnt += calcDist(ball)
    
print(cnt)

Solution (Python):








def resolve():
    N=int(input())
    K=int(input())

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

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

    print(cnt)

resolve()

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

disb = list(map(lambda b: k - b, xs))

result = 0
for a, b in zip(xs, disb):
    result += min([a, b]) * 2

print(result)

Solution (Python):
N=int(input())
K=int(input())
x=input().split()
X=[int(a) for a in x]
list=[]
for b in X:
    if b>=abs(b-K):
        list.append(abs(b-K))
    else:
        list.append(b)
print(sum(list)*2)

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

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

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

Solution (Python):
from sys import stdin

n = int(stdin.readline().rstrip())
k = int(stdin.readline().rstrip())
x = [int(x) for x in stdin.readline().rstrip().split()]

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

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

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

Solution (Python):


n = int(input().rstrip())
k = int(input().rstrip())

ans = [min(j, abs(k-j))*2 for j in [int(i) for i in input().rstrip().split(" ")]]

print(sum(ans))

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

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

Solution (Python):

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

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

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

ans = 0

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

Solution (Python):


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

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

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

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

ans = 0
for i in range(n):
    l = min(a[i], k-a[i])
    ans += l * 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-0, k-i)
print(ans*2)

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

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

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

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
K = int(input())
x = [int(x) for x in 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())
x = [int(_) for _ in input().split()]

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

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

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

Solution (Python):

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    K=I()
    x=LI()
    ans=0
    for i in range(N):
        ans+=min(x[i],abs(K-x[i]))
    print(ans*2)

main()

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

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

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] - 0), 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(abs(0 - x[i]), abs(k - x[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], a[i]) * 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(x[i],abs(K-x[i]))
print(ans)

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

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

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

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


if __name__ == '__main__':
    main()

Solution (Python):
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from math import floor, ceil, sqrt, factorial, log
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop
from itertools import product
import sys
stdin = sys.stdin
mod = 10**9 + 7


def ns(): return stdin.readline().rstrip()


def ni(): return int(ns())


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


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

Solution (Python):
n, k, *a = map(int, open(0).read().split())

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

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

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


if __name__ == '__main__':
    main()

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

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

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

Solution (Python):
def main():
    ball_num = int(input())
    type_b_initial_y = int(input())
    x_coodinates = list(map(int, input().split()))
    answer = 0
    for i in range(ball_num):
        answer += min(x_coodinates[i] * 2, abs(x_coodinates[i] - type_b_initial_y) * 2)
    print(answer)


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

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

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

Solution (Python):
def ballrobot(n , k , xl):

    ans = 0

    for i in xl:
        if k - i < i:
            ans += k - i
        else:
            ans += i

    return ans*2

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

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

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

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

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

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

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

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

Solution (Python):
N = int(input())
K = int(input())
X = list(map(int, input().split()))
res = 0
for i in range(N):
  x = X[i]
  a = abs(0-x)
  b = abs(K-x)
  res += a if a < b else b

print(res*2)

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), abs(i)) * 2

print(ans)

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

Solution (Python):

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

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

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

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


print(r)

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

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

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

import math
ans = []
for i in range(N):
  a = math.sqrt((x[i] - 0) ** 2) * 2
  b = math.sqrt((x[i] - K) ** 2) * 2
  ans.append(min(a, b))
print(round(sum(ans)))

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

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

Solution (Python):




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


if __name__ == "__main__":
    main()

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

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

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

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

print(ans)

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

print(ans)

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

for i in x:
	ans.append(min(abs(0 - i), abs(i - k)) * 2)

print(sum(ans))

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

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

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

Solution (Python):
n=input()
k=int(input())
x=list(map(int,input().split()))
xa=[]
xb=[]
for i in range(len(x)):
	if x[i]<=(k/2):
		xa.append(x[i])
	else :
		xb.append(x[i])
suma=sum(xa)*2
sumb=(len(xb)*k-sum(xb))*2
print(suma+sumb)

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

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

ans = 0

for x in xs:
  a = x*2
  b = abs(x-k)*2
  if a < b:
    ans += a
  else:
    ans += b

print(ans)

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

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

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

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

count = 0

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

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

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

Solution (Python):

def intinput():
    return int(input())

def listintinput():
    return list(map(int,input().split()))

def splitintinput():
    return map(int,input().split())

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

print(ans)

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

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

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

for i in range(n):
    if(x[i] - 0 <= abs(k - x[i])):
        sum += 2 * 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()))
count=0
for i in range(N):
    if (x[i]<K-x[i]):
        count=count+2*x[i]
    else:
        count=count+2*(K-x[i])
print(count)

Solution (Python):
"""
author : halo2halo
date : 30, Jan, 2020
"""

import sys


import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N, K, *x = map(int, read().split())
X = np.array(x)
R = X[K / 2 < X]
L = X[K / 2 >= X]

ans = sum(L * 2) + sum(2 * (K - R))
print(ans)

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

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

print(ans)

Solution (Python):
def solve(n, k, X):
    return 2 * sum(min(x, abs(k - x)) for x in X)

_n = int(input())
_k = int(input())
_X = list(map(int, input().split()))
print(solve(_n, _k, _X))

Solution (Python):
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n=INT()
    k=INT()
    x=LIST()
    ans=0
    for i in x:
        ans+=2*min(abs(k-i),abs(0-i))
    print(ans)
if __name__ == '__main__':
    do()

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 += 2 * min(x, K - x)

print(ans)

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

print(answer)

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

a = [min(n, abs(K-n)) for n in x]
print(sum(a)*2)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n = INT()
k = INT()
x_l = LIST()

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

print(ans*2)

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

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

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

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

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

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

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

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

l = [min(x*2,(k-x)*2) for x in xl]
print(sum(l))