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


def read_numbers():
    return [int(num) for num in sys.stdin.readline().split()]
def read_string():
    return sys.stdin.readline().rstrip('\r\n')
def list2str(*array):
    return ' '.join([str(i) for i in array])

def main(N, K, xs):
    result = 0
    for x in xs:
        result += 2*min(K-x, x)
    return result

def parse_stdin():
    
    
    
    
    N = read_numbers()[0]
    K = read_numbers()[0]
    xs = read_numbers()
    return N, K, xs

def test_main():
    """run pytest stdin.py to test"""
    assert main(2, 9, [3, 6]) == 12

if __name__ == '__main__':
    N, K, xs = parse_stdin()
    result = main(N, K, xs)
    print(result)

Solution (Python):
if __name__ == '__main__':
    N = int(input())
    K = int(input())
    x = list(map(int, input().split()))
    sum_half = 0
    for tmp_x in x:
        sum_half += min(tmp_x, K - tmp_x)

    print(sum_half * 2)

Solution (Python):
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]

n=i1()
k=i1()
x=i2()
c=0
for i in x:
    if i>abs(k-i):
       c+=abs(k-i)
    else:
       c+=i
print(c*2)

Solution (Python):
N=(int)(input())
K=(int)(input())
x=(input()).split(' ')
result=0

for i in x:
    result+=2*min((int)(i),abs((int)(i)-K))

print(result)

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

ans = 0

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

print(ans)

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


if __name__ == "__main__":
    main()

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

goukei = 0
for x in x_list:
    if abs(0-x) > abs(k-x):
        goukei += 2*abs(k-x)
    else:
        goukei += 2*abs(x)

print(goukei)

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

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

print(res)

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

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

dist = 0

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

Solution (Python):
import sys

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())


def main():
    n = I()
    k = I()
    xs = LI()

    r = 0
    for x in xs:
        r += 2*min(k-x, x)

    return r


print(main())

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

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

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

print(ans)

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

counter = 0

for _ in listx:
    if abs(K - _) > _:
        counter += _*2
    else:
        counter += abs(K - _)*2

print(counter)

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

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

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

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

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

print(d)

Solution (Python):



from collections import defaultdict
from math import factorial as f
from fractions import gcd as g

N = int (raw_input ())
K = int (raw_input ())
l = [int (i) for i in raw_input ().split ()]
print sum (2 * min (i, abs (K - i)) for i in l)

Solution (Python):


N = int(input())
K = int(input())
x_list = map(int, input().split(" "))

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

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

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

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

print(sum(min(abs(k - i), i) * 2 for i in a))

Solution (Python):
def min(a,b):
	if(a<b):
		return a
	else:
		return b
n=int(input())
k=int(input())
l=list(map(int,input().split()))
ans=0
for val in l:
	ans+=2*abs(min(val,abs(k-val)))
print(ans)

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

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

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

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

Solution (Python):
n=int(input())
k=int(input())
x=[int(x) for x in input().split()]
ans=0
from math import fabs
for i in x:
    ans+=min(fabs(i-k),fabs(i))
print(int(ans*2))

Solution (Python):

def get_ln_inputs():
    return input().split()


def get_ln_int_inputs():
    return list(map(int, get_ln_inputs()))


def main():
    N = get_ln_int_inputs()[0]
    K = get_ln_int_inputs()[0]
    xs = get_ln_int_inputs()

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

    print(2 * ans)
    return


main()

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

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