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



Sample input:
1
10
2


Sample output:
4

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

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

    print(ans)

if __name__ == "__main__":
        main()

Submission status: Accepted

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

print(sum(map(lambda y: min(y, abs(k - y)) * 2, x)))

Submission status: Accepted

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

re = 0
for x in X:
    if x < K - x:
        re += x
    else:
        re += K-x

print(re*2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = list(map(int, (input(), input())))
numlist = list(map(int, input().split()))

total = 0

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

print(total)

Submission status: Accepted

Solution code:
"""
https://abc074.contest.atcoder.jp/tasks/abc074_b
"""
n=int(input())
k=int(input())
x=[int(i) for i in input().split()]
a=0
for i in x:
    a=a+min(abs(i-0),abs(i-k))*2
print(a)

Submission status: Accepted

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

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

print(total)

Submission status: Accepted

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

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

ans=0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(total)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

ans = 0
for i in range(N):
    A = num_list[i]
    B = abs(K - A)
    if A <= B:
        ans += A * 2
    else:
        ans += B * 2
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N=int(raw_input())
K=int(raw_input())
x=map(int,raw_input().split())
print 2*sum([min(xi,K-xi) for xi in x])

Submission status: Accepted

Solution code:
N, K = int(input()), int(input())
a = list(map(int, input().split()))
res = 0
for e in a:
    res += min(e * 2, (K - e) * 2)
print(res)

Submission status: Accepted

Solution code:

a = [input() for i in range(3)]
ave = int(a[1])/2
move = 0
#print(a)
for i in a[2].split():
    if float(i) <= ave:
        move += (2 * float(i))
    else:
        move += (2 * (float(a[1]) - (float(i))))
print(int(move))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# input
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)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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(X[i]))*2
    
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
K = int(input())
X = list(int(i) for i in input().split())

distance = 0

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

Submission status: Accepted

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

cost = 0

for dis in x:
    cost += min(dis, k-dis)

print(cost*2)

Submission status: Accepted

Solution code:
N = int(input())
K = int(input())
xchar = input().split()
x = []
for i in range(N):
    x.append(int(xchar[i]))

distance = 0

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

print(distance)

Submission status: Accepted

Solution code:
s=0;input();k=int(input())
for x in input().split():
    x=int(x);s+=min(abs(k-x),x)*2
print(s)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
K = int(input())
balls = list(map(int, input().split(' ')))
dist = 0
for i in balls:
    if i >= abs(K - i):
        dist += abs(K - i) * 2
    else:
        dist += i * 2
print(dist)

Submission status: Accepted

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

for d in x:
    counter += min(d*2,(k-d)*2)
    
print(counter)

Submission status: Accepted

Solution code:
n = int(input())
k = int(input())
x = map(int, input().split())
dis = 0

for i in x:
    if abs(k-i) >= i:
        dis += 2 * i
    else:
        dis += 2 * abs(k-i)

print(dis)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
K = int(input())
X = list(map(int,input().split()))[:N]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
a=int(input())
b=int(input())
c=list(map(int, input().split()))

print(sum([min(i*2,(b-i)*2) for i in c]))

Submission status: Accepted

Solution code:
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(total*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def distance(balls, k):
    total = 0
    for x in balls:
        total += 2 * min(x, abs(x - k))
    return total


if __name__ == '__main__':
    _ = input()
    k = int(input())
    balls = map(int, input().split())
    print(distance(balls, k))

Submission status: Accepted

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

Submission status: Accepted

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

temp_list = list(map(int, input().split()))
total_len = 0

for i in temp_list:
    if K-i <= i:
        total_len +=((K-i)*2)
    else:
        total_len += i*2
     
print(total_len)

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

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

print(num)

Submission status: Accepted

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

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

sumdist = 0
for x in X:
    typeA = x * 2
    typeB = abs(x- K) * 2
    dist = min(typeA, typeB)
    sumdist += dist

print(sumdist)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
K = int(input())
sum = 0
num = input().split()
for i in range(N):
  work = int(num[i])
  sum += min(2*work,abs(K-work)*2)
print(sum)

Submission status: Accepted

Solution code:
p=input;p();k=int(p());print(sum([2*min(i,abs(k-i))for i in map(int,p().split())]))

Submission status: Accepted

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

ans = sum(map(lambda a: min(abs(a-0), abs(K-a)), x))
print(ans * 2)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem B

if __name__ == '__main__':
    ball_count = int(input())
    robotB_position = int(input())
    positions = list(map(int, input().split()))

    total_length = 0

    for i in range(ball_count):
        if positions[i] < abs(robotB_position - positions[i]):
            total_length += 2 * positions[i]
        else:
            total_length += 2 * abs(robotB_position - positions[i])

    print(total_length)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# Set 2 dimension list
def dim2input(N):
    li = []
    for _ in range(N):
        li.append(input().split())
    return li

# --------------------------------------------

dp = None

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

    move = 0

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

    print(move)

main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
K=int(input())
x=list(map(int,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)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
K = int(input())
S = 0
st = input().split()
for i in range(N):
  xi = int(st[i])
  S += 2*min([xi,K-xi])
 
print(S)

Submission status: Accepted

Solution code:
N = int(input())
K = int(input())
S = 0
st = input().split()
for i in range(N):
  xi = int(st[i])
  S += 2*min([xi,K-xi])

print(S)

Submission status: Accepted

Solution code:
N=int(input())
K=int(input())
S=list(map(int, input().split()))

t=0
for i in range(N):
    if K-S[i]<S[i]:
        t+=(K-S[i])*2
    else:
        t+=S[i]*2

print(t)

Submission status: Accepted

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

Submission status: Accepted

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

print(sum((min(x, k-x) * 2 for x in xs)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
k = int(input())
xl = [int(x) for x in input().split()]
s=0
for x in xl:
    s+= x*2 if abs(k-x)>x else abs(k-x)*2
print(s)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

n = input()
K = int(input())

xs = map(int, input().split())

res = 0
for p in xs:
    res += min(p, K - p)

print(res*2)

Submission status: Accepted

Solution code:
n = int(input())
k = int(input())
arr = map(int, input().split())
ans = []
for ar in arr:
  if (ar < k - ar):
    ans.append(ar)
  else:
    ans.append(k-ar)



print(sum(ans)*2)

Submission status: Accepted

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

a = 0

for i in range(N):
    a += min(x[i], K-x[i])

print(a*2)

Submission status: Accepted

Solution code:
import math

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

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

print(l)

Submission status: Accepted

Solution code:
a=int(input())
b=int(input())


def ab(x):
  return min(abs(x),abs(x-b))*2

print(sum([ab(int(i)) for i in input().split(' ')]))

Submission status: Accepted

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

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

print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8

# 入力
n = int(input())
k = int(input())
li = list(map(int, input().split()))

# メイン処理
count = 0
for p in li:
    if p < k - p:
        count += p * 2
    else:
        count += (k-p) * 2

# 出力
print(count)

Submission status: Accepted

Solution code:
N=input();K=input();x=input().split();Ans=int(0)
x.sort(key=int)
for i in range(0,len(x)):
    if(int(x[i])>(int(K)/2)):
        Ans += 2*(int(K)-int(x[i]))
    else:
        Ans += 2*int(x[i])
print(int(Ans))

Submission status: Accepted

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

Ans = 0

for i in range(N):
	p = abs(x[i])
	q = abs(K - x[i])
	if p >= q :
		Ans += 2 * q
	if p < q:
		Ans += 2 * p

print(Ans)

Submission status: Accepted

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

Submission status: Accepted

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

dsum = 0

for i in x:
    if i <= k/2:
        dsum += i*2
    else:
        dsum += (k-i)*2

print(dsum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python

def main():
    N = int(input())
    K = int(input())
    x_list = list(map(int, input().split(" ")))

    sum = 0
    for x in x_list:
        A = x * 2
        B = (K - x) * 2
        sum += A if A <= B else B
    print(sum)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
K = int(input())
X_MAP = map(int, input().split())

def ans(num):
    print(num * 2)

def main():
    accumulation = 0
    for x in X_MAP:
        distance = min(x, K - x)
        accumulation += distance
    ans(accumulation)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
K = int(input())
x = map(int,input().split())
sum = 0
for a in x:
    if int(K/2) >= a:
        sum += a*2
    else:
        sum += (K-a)*2

print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = input()
k = input()
ball_list = [int(x) for x in raw_input().split()]
ans = 0
for xi in ball_list:
	ans += (min(abs(k - xi), xi) * 2)
print ans

Submission status: Accepted

Solution code:
N = int(input())
K = int(input())
x = list(int(i) for i in input().split())
sum = 0
for i in range(N):
    if K - x[i] <= x[i]:
        sum += (K-x[i])*2
    if K - x[i] > x[i]:
        sum += x[i]*2

print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin

def solve(K, xs):
  return sum([2 * min(x, K - x) for x in xs])

def splitToInt(line):
  words = line.strip().split()
  return [int(w) for w in words]

N = int(stdin.readline())
K = int(stdin.readline())
xs = splitToInt(stdin.readline())
if len(xs) != N: raise
print(solve(K, xs))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

Submission status: Accepted

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

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

HalfK = K/2.0

Ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print (res)

Submission status: Accepted

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

res = 0

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

print(res)

Submission status: Accepted

Solution code:
#!/usr/bin/python3

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

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

print(d)

Submission status: Accepted

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

print(d)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-



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

if __name__ == "__main__": main()

Submission status: Accepted

Solution code:
# coding: utf-8
n,k=int(input()),int(input())
data=list(map(int,input().split()))
ans=0
for x in data:
    ans += min(x*2,(k-x)*2)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
K=int(input())
ans=0

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

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

print(ans)

Submission status: Accepted

Solution code:
n, k = [int(input()) for _ in range(2)]
xi = [int(i) for i in input().split()]
dist = 0
for x in xi:
    l, m = [abs(k-x), abs(x)]
    dist += l*2 if l<m else m*2

print(dist)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
N=input()
K=input()
x=map(int,raw_input().split())
print sum(min(t,abs(K-t))for t in x)*2

Submission status: Accepted

Solution code:
N = int(input())
K = int(input())
x = [int(i) for i in 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)

Submission status: Accepted

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

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

print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
N = int(input())
K = int(input())
X = list(map(int,input().split()))
ans = 0
for a in X:
    if abs(a-K) < a:
        ans += 2 * abs(a-K)
    else:
        ans += 2*a
print(ans)

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    N = int(input())
    K = int(input())
    xs = [int(s) for s in input().split(' ')]
    res = 0
    for i in range(N):
        res += min(xs[i], abs(K - xs[i])) * 2
    print(res)

Submission status: Accepted

Solution code:
n = int(input())
k = int(input())
l = input().split()
ans = 0
for i in l:
  j = int(i)
  if( j < abs( j - k )  ):
    ans += 2*j
  else:
    ans += 2*abs(j-k)
print(ans)

Submission status: Accepted

Solution code:
def calc_dist(N, K, x):
    dists = [2 * min(K - x_i, x_i) for x_i in x]
    return sum(dists)

if __name__ == "__main__":
    N = int(raw_input())
    K = int(raw_input())
    x = map(int, raw_input().split())
    print(calc_dist(N, K, x))

Submission status: Accepted

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

#iterate through number of bals
for i in range(N):
	dist = []
	for Rtype in ['A','B']:
		if Rtype == 'A':
			dist.append(abs(X[i] - 0)*2)
		if Rtype == 'B':
			dist.append(abs(X[i] - K)*2)
	Total_dist += min(dist)

print(Total_dist)

Submission status: Accepted

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

x = input().split()

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

Submission status: Accepted

Solution code:
dump = int(input())
K = int(input())
sum = 0
x = list(map(int, input().split()))
for x_i in x:
  sum += 2*min(x_i, K-x_i)
print(sum)

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    N = int(input())
    K = int(input())
    x = list(map(int, input().split()))
    ans = 0
    for i in range(N):
        r = min(x[i],abs(K-x[i]))
        ans += 2*r
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
K = int(input())
xstr = input().split()
d = 0
for i in xstr:
    xi = int(i)
    dK = K-xi
    if dK < xi:
        d += dK
    else:
        d += xi
print(d*2)

Submission status: Accepted

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

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

print(ret)