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

if __name__ == "__main__":
    solve()

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

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

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

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

Solution (Python):
import sys
from collections import defaultdict, deque, Counter
import math


from bisect import bisect_left, bisect_right





input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def solve():
    n = getN()
    k = getN()
    nums = getList()

    ans = 0
    for i, num in enumerate(nums):
        ans += 2 * (min(abs(k - num), num))


    print(ans)
def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    
    solve()

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()))
P=0
for i in range(N):
  P+=min(K-X[i],X[i])
print(P*2)

Solution (Python):
import sys
sys.setrecursionlimit(10**7) 
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right

from collections import deque


from collections import Counter

from itertools import accumulate,combinations,permutations

from heapq import heapify,heappop,heappush


from functools import lru_cache

from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    

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




if __name__ == "__main__":
    main()

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
k = inp()
a = inpl()
res = 0
for i,x in enumerate(a):
    res += min(abs(k-x)*2, x*2)
print(res)

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

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

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

Solution (Python):










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

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

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

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

Solution (Python):
N = int(input())
K = int(input())
x = list(map(int, input().split()))
A = [0] * N
B = [0] * N

ans = 0
for i in range(N):
    x[i] = [x[i], i+1]
    A[i] = [0, i+1]
    B[i] = [K, i+1]

    if x[i][1] == A[i][1] == B[i][1]:
        ans += min(abs(x[i][0] - A[i][0]), abs(x[i][0] - B[i][0]))

print(ans*2)

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

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

total_move = 0
for ball in balls:
    if ball < K - ball:
        total_move += ball * 2
    else:
        total_move += (K - ball) * 2
print(total_move)

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

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

Solution (Python):
input()
K = int(input())
ans = 0

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

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

s = 0
for i in x:
  if abs(i - k) < i:
    i = abs(i - k)
  s += i * 2

print(s)

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

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

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

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

print(sum)

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

X = tuple(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())
x = list(map(int, input().split()))
ans = 0
for yi, xi in enumerate(x):
    ans += min((xi) * 2, abs(k - xi) * 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]))

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

print(ans * 2)

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

print(result)

Solution (Python):
N=int(input())
K=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=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 xi in X:
    ans += min(xi, (K-xi))*2
print(ans)

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

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

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

Solution (Python):

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

total=0

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

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

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

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

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

Solution (Python):


LI = lambda: list(map(int, input().split()))


N = int(input())
K = int(input())
X = LI()


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


if __name__ == "__main__":
    main()

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

for i in range(N):
    A = 2*a[i]
    B = 2*(K-a[i])
    sum_a += min(A,B)
    
    
print(sum_a)

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

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

print(sum(dp))

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

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

Solution (Python):
import sys
import heapq
import re
from heapq import heapify, heappop, heappush
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def dijkstra_heap(s, edge, n):
    
    d = [10**20] * n
    used = [True] * n 
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


def lcm(x, y):
    return (x * y) // gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm, numbers, 1)


def gcd_list(numbers):
    return reduce(gcd, numbers)


def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True



def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P


def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret


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

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

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

idoukyori = 0
for x in x_lst:
    idoukyori += 2*min(abs(0-x),abs(k-x))

print(idoukyori)

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

border = K // 2
ans = 0
for x in xx:
    if x <= border:
        
        ans += x * 2
    else:
        
        ans += (K - x) * 2
print(ans)

Solution (Python):




from __future__ import division, print_function 

import sys
import os
from collections import Counter, deque, defaultdict
import itertools
import math
import io


"""Uncomment modules according to your need"""













if sys.version_info[0] < 3:
    input = raw_input
    range = xrange

    filter = itertools.ifilter
    map = itertools.imap
    zip = itertools.izip



"""value of mod"""
MOD = 998244353
mod = 10**9 + 7

"""Uncomment next 4 lines if doing huge recursion"""




def prepare_factorial(mod=mod):
    """ returns two lists, factorial and inverse factorial modulo argument by default 10**9 +7 """
    
    fact = [1]
    for i in range(1, 200005):
        fact.append((fact[-1] * i) % mod)

    ifact = [0] * 200005
    ifact[200004] = pow(fact[200004], mod - 2, mod)
    for i in range(200004, 0, -1):
        ifact[i - 1] = (i * ifact[i]) % mod

    return fact, ifact

def modinv(n, p):
    """ returns N inverse modulo p """
    return pow(n, p - 2, p)

def ncr(n, r,  fact, ifact):
    """ takes 4 arguments: n , r and factorial and inverse factorial lists"""
    t = (fact[n] * (ifact[r]*ifact[n-r]) % MOD)% MOD
    return t


def get_n(Sum):    
    """this function returns the maximum n for which Summation(n) <= Sum"""
    ans = (-1 + sqrt(1 + 8*Sum))//2
    return ans

def sieve(n):
    """ returns a list of prime numbers till n """
    if n < 2: return list()
    prime = [True for _ in range(n + 1)]
    p = 3
    while p * p <= n:
        if prime[p]:
            for i in range(p * 2, n + 1, p):
                prime[i] = False
        p += 2
    r = [2]
    for p in range(3, n + 1, 2):
        if prime[p]:
            r.append(p)
    return r



def divs(n, start=1):
    """ returns a list of all divisors till n """
    divisors = []
    for i in range(start, int(math.sqrt(n) + 1)):
        if n % i == 0:
            if n / i == i:
                divisors.append(i)
            else:
                divisors.extend([i, n // i])
    return divisors



def divn(n, primes):
    """ returns the number of divisors, two arguments n and the sieve till n """
    divs_number = 1
    for i in primes:
        if n == 1:
            return divs_number
        t = 1
        while n % i == 0:
            t += 1
            n //= i
        divs_number *= t



def lrfind(d, x, default=-1):
    """ Takes 2 arguments an iterable and an element. returns a tuple (firstoccurence,lastoccurence) -1 if not found """
    left = right = -1
    for i in range(len(d)):
        if d[i] == x:
            if left == -1: left = i
            right = i
    if left == -1:
        return default, default
    else:
        return left, right

def gcd(x, y): 
    """ returns greatest common divisor of x and y """
    while y:
        x, y = y, x % y
    return x

def check_sorted(a):
    ''' returns True/False '''
    for i in range(len(a)-1):
        if a[i]>a[i+1]:
            return False
    return True
def ceil(n, k=1): return n // k + (n % k != 0) 
def input(): return sys.stdin.readline().strip()
def ii(): return int(input()) 
def mi(): return map(int, input().split()) 
def li(): return list(map(int, input().split())) 
def lw(): return input().split() 
def lcm(a, b): return abs(a * b) // gcd(a, b) 
def prr(a, sep=' ', end='\n'): print(sep.join(map(str, a)), end=end) 
def dd(): return defaultdict(int) 
def ddl(): return defaultdict(list) 
def write(s): return sys.stdout.write(s)













def main():
    
    n=ii()
    k=ii()
    x=li()
    answer=0
    for i in x:
        answer+=min(i,abs(k-i))
    answer*=2
    print(answer)


























""" -------- Python 2 and 3 footer by Pajenegod and c1729 ---------"""

py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange

import os, sys
from io import IOBase, BytesIO

BUFSIZE = 8192

class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill(): pass
        return super(FastIO, self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill();
            self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)


class IOWrapper(IOBase):

    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s: self.buffer.write(s.encode('ascii'))
            self.read = lambda: self.buffer.read().decode('ascii')
            self.readline = lambda: self.buffer.readline().decode('ascii')


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')



""" main function"""

if __name__ == '__main__':
    main()

Solution (Python):



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

    tmp = 0
    for x in l:
        if x <= (k/2):
            tmp+=(2*x)
        else:
            tmp+=(2*(k-x))
    print(tmp)

if __name__ == '__main__':
    main()

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 += abs(x[i]-K)
    else:
        dist += x[i]

print(dist*2)

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

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

print(sum)

Solution (Python):
N,K=int(input()),int(input());print(sum([i*2 if (i*2<(K-i)*2) else ((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()))
a = [i*2 for i in x]
b = [(K-i)*2 for i in x]
print(sum([i if i < j else j for i,j in zip(a,b)]))

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

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

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

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

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

for i in I:
    a = i           
    b = abs(K-i)    
    if a >= b:
        dis += 2 * b
    else:
        dis += 2 * a


print(dis)

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

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

cost=0
for i in range(n):
    cost+=min(abs(a[i]),abs(k-a[i]))

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

Solution (Python):
def calcdistance(N, K, x) : 
  sum = 0
  for i in range(N) : 
    sum += 2 * min(x[i] - 0, K - x[i])
  return sum

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

print(calcdistance(N, K, x))

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

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

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

print(res)

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

ans = 0

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

Solution (Python):
N=int(input())
K=int(input())
xlis=[int(x) for x in input().split(' ')]
sums=0
for i in range(N):
	ball=xlis[i]
	arob=ball*2
	brob=abs(K-ball)*2
	sums+=min([arob,brob])
print(sums)

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

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

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

Solution (Python):


N = int(input())
K = int(input())
X = list(int(x) for x in 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()))
sum = 0
for i in range(N):
    if x[i] <= K//2:
        sum += 2*x[i]
    else:
        sum += 2*(K-x[i])
print(sum)

Solution (Python):
def main():
    from builtins import int, map, list, print, min
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = (lambda: (sys.stdin.readline()).rstrip())
    input_list = (lambda: input().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

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


if __name__ == '__main__':
    main()

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

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

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

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

m = 0

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

print(m*2)

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

print(ans)

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

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

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

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

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

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

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

print(ans*2)

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

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

print(ans)

Solution (Python):
def main():
    from sys import setrecursionlimit, stdin
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**9+10

    N = II()
    K = II()
    X = LMIIS()
    ans = 0
    for x in X:
        ans += min(x,K-x)*2
    print(ans)
    
main()

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

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

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

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

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

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

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

print(res)