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())
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):
n = int(input())
k = int(input())

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


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

print(ans)

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

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

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

    ans = []
    for i in x:
        ans.append(i*2 if k/2 > i else (k-i)*2)

    print(sum(ans))

resolve()

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

print(total)

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

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

Solution (Python):

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

sx = sorted(x)
mn = min(x)

cost = 0
for s in sx:
    cost += min(((K-s)*2), s*2)
print(cost)

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

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

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

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

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

print(ans)

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

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

half = K / 2
ans = 0
for x in X:
    if half < x:
        ans += K - x
    else:
        ans += x

print(ans * 2)

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

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

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

ans = 0
midp = k / 2
for x in X:
  if x < midp:
    ans += 2 * x
  else:
    ans += (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(x[i] - 0), abs(x[i] - K))
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7


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

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

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


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

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

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

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

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

length = 0

for i in range(N):
    if K-X[i] > X[i]:
        length += 2*X[i]
    else:
        length += 2*(K-X[i])

print(length)

Solution (Python):
import numpy as np
N = int(input())
K = int(input())
X = np.array(list(map(int, input().split())))

distance_B = np.abs(X - K)
total_distance = 0
for x, b in zip(X, distance_B):
    if x > b:
        total_distance += 2*b
    else:
        total_distance += 2*x

print(total_distance)

Solution (Python):



def get_min_total_dist(K, X):
    return sum([2 * min(x, abs(x - K)) for x in X])

def main():
    N = int(input())
    K = int(input())
    X = list(map(int, input().split()))
    print(get_min_total_dist(K, X))

if __name__ == "__main__":
    try:
        assert get_min_total_dist(10, [2]) == 4
        assert get_min_total_dist(9, [3, 6]) == 12
        assert get_min_total_dist(20, [11, 12, 9, 17, 12]) == 74
    except:
        import traceback
        traceback.print_exc()
        exit()
    main()

Solution (Python):
import sys
readline = sys.stdin.readline

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

if __name__ == '__main__':
    main()

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

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

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

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

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

Solution (Python):


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

res = []
for i in range(N):
    a_cost = 2 * x[i]
    b_cost = 2 * (K - x[i])
    cost = min([a_cost, b_cost])
    res.append(cost)

print(sum(res))

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

ans=0
i=0
while i<N:
    ans+=2*min(X[i],K-X[i])
    i+=1

print(ans)

Solution (Python):
N,K=int(input()),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):
a=int(input())
b=int(input())
ballist=list(map(int,input().split()))
dist=0
for t in ballist:
    dist+=min(abs(t),abs(t-b))
print(dist*2)

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

Solution (Python):
import sys
input = sys.stdin.readline


def read():
    N = int(input().strip())
    K = int(input().strip())
    X = map(int, input().strip().split())
    return N, K, X


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


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

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

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

ans = 0

for x in x_list:
    if x <= K // 2:
        ans += x * 2
    else:
        ans += (K - x) * 2

print(ans)

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

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

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

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

print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
K = INT()
x = LIST()

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

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):
    if x[i]>=(K-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()))
ans = 0

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

Solution (Python):
import sys

def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))

def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]

def to_bin(x: int) -> str: return format(x, 'b') 
def to_oct(x: int) -> str: return format(x, 'o') 
def to_hex(x: int) -> str: return format(x, 'x') 
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]

from itertools import accumulate as acc
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left



def main():
    n = II()
    k = II()
    xx = MII()
    sumv = 0
    for x in xx:
        sumv += min(x,abs(x-k))*2
    print(sumv)

if __name__ == '__main__':
    main()

Solution (Python):
def multi_input():
    return map(int, input().split())

N = int(input())
K = int(input())
x = list(multi_input())

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

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

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

print(answer)

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

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

print(ans)

Solution (Python):
N = int(input())
K = int(input())
ball = list(map(int,input().split()))
l = 0
for i in range(len(ball)):
  A = ball[i] * 2
  B = (K - ball[i]) * 2
  if A <= B:
    l += A
  else:
    l += B
print(l)

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

Solution (Python):
N = int(input())
K = int(input())
X = list(map(int, input().split()))
result = 0
def A(x):
    disA = 0
    disA = 2 * x
    return disA
def B(k, x):
    disB = 0
    disB = 2 * (k -x)
    return disB

for i in X:
    if A(i) <= B(K, i):
        result += A(i)
    else:
        result += B(K, i)
print(result)

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

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

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

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

print(ans)

Solution (Python):
n = int(input())
k = int(input())
x = (list(map(int,input().split())))
xa = [2*x[j] for j in range(n)]
l = 0
xb = [2*abs(x[i]-k) for i in range(n)]

for k in range(n):
    if xa[k] >= xb[k]:
        l += xb[k]
    else:
        l += xa[k]

print(l)

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

result = 0
for i in range(N):
    if k - x[i] > x[i] :
        result += x[i] *2
    
    else:
        result += (k - x[i]) *2
                

print(result)

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=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):
import math
n = int(input())
k = int(input())
li=list(map(int,input().split()))
ans = 0
for i in li:
    ans += min(i * 2, (k - i)*2) 
print(ans)

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

Solution (Python):


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

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

ans = 0
for one in x:
    ansOne = min([one, K - one])
    ans += ansOne * 2

print(ans)

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

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

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

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

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

r = 0
for x in X:
    if x > K/2:
        r += (K-x)*2
    else:
        r += x*2

print(r)

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

Solution (Python):
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())
K = int(input())
A = sum(map(lambda x: 2 * min(int(x), K - int(x)), input().split()))
print(A)

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

total = 0

for i in range(n):
    x = xs[i]
    total += min(2 * x, 2 * (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]*2, abs(K-x[i])*2)
print(ans)

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

Solution (Python):

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

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

res = 0
for i in range(len(x_n)):
    if x_n[i] > (k / 2):
        res = res + abs(x_n[i] - k) * 2
    else:
        res = res + 2 * x_n[i]

print(res)

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

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

resolve()

Solution (Python):
N=int(input())
K=int(input())
c=list(map(int, input().split()))
l=[K]*N
sub=[]
res=[]
for i in range(0, N):
	sub.append(l[i]-c[i])
	if (sub[i]<=c[i]):
		res.append(2*sub[i])
	else:
		res.append(2*c[i])
print(sum(res))

Solution (Python):
import math

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

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

print(ans)

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

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

Solution (Python):
import sys
input = sys.stdin.readline

def readlines(n):
    for i in range(n):
        for j, x in enumerate(input().split()):
            yield int(x), (i, j)


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

    for x in (map(int, input().split())):
        yield min(x, K - x) * 2

print(sum(main()))

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):
n = int(input())
k = int(input())
x = list(map(int,input().split()))

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

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

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

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

            

if '__main__' == __name__:
    resolve()

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

print(ans)

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    k = int(input())
    X = list(map(int, input().split()))

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

    print(res)


if __name__ == '__main__':
    resolve()

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

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

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

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

distance = []

for i in range(n):
  if abs(x[i] - 0) < abs(x[i] - k):
    distance.append(abs((x[i] - 0) * 2))
  else:
    distance.append(abs((x[i] - k) * 2))

print(sum(distance))

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

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

ans = 0

for i in range(len(x)):
     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()))

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()))
count = 0
for i in X:
    A = i
    B =abs(i - K)
    if A >= B:
        count = count + 2*B
    else:
        count = count + 2*A
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())
A=list(map(int,input().split()))

ans=0
for i in A:
    if i >=K/2:
        ans+=2*(K-i)
    else:
        ans+=2*i

print(ans)

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

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

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

print(ans)

Solution (Python):
N = int(input())
K = int(input())
li = list(map(int, input().split()))
ans = 0
for i in li:
    if i < abs(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()))

count = 0
for _, v in enumerate(X):
    count = count + min(v * 2, (K - v) * 2)

print(count)

Solution (Python):
ball_n = int(input())
robbotb_x_position = int(input())
ball_x_positions= map(int, input().split())


result = 0
for ball_x_position in ball_x_positions:
    b_distance = abs(ball_x_position - robbotb_x_position)
    a_distance = ball_x_position
    if b_distance > a_distance:
        result += a_distance * 2
    else:
        result += b_distance * 2

print(result)

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

length = 0

for i in x:
    length += min(i,K-i)*2

print(length)

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

Solution (Python):
N,K,*X = map(int,open(0).read().split())

ans= 0

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

Solution (Python):


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

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

print(ans)

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

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

print(count)

Solution (Python):
import sys

lines = sys.stdin.readlines()

N = int(lines[0])
K = int(lines[1])
X = lines[2].split(' ')
x =[]

y = 0
for i in range(N):
  x.append(int(X[i]))
  if 2*x[i] >= K:
      dist = 2*(K-x[i])
  else:
      dist = 2*x[i]
  y = y + dist

print(y)

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

Solution (Python):

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

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

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

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

print(answer *2)

Solution (Python):


import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN

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

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

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

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

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

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

c = 0

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

print(c)

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

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

ans = 0

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

print(ans)

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

ans = 0

for i in range(N):
    ans += 2 * min(lx[i], abs(K - lx[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(k-x[i])) * 2

print(ans)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7


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

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

for x in x_l:
    if x <= k-x:
        total += x*2
    else:
        total += (k-x)*2

print(total)

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


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

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


mid = k // 2
t = 0
for i in range(n):
    if nums[i] < mid:
        t += nums[i] * 2
    else:
        t += (k - nums[i]) * 2

mid = (k + 1) // 2
ans = 0
for i in range(n):
    if nums[i] < mid:
        ans += nums[i] * 2
    else:
        ans += (k - nums[i]) * 2
ans = min(ans, t)
print(ans)

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

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

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