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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
# ABC074 B - Collecting Balls (Easy Version)
N = int(input())
K = int(input())
X = list(map(int,input().split()))

ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

total=0
for c in x:
    ax=abs(c-0)
    bx=abs(k-c)
        
    a=2*ax
    b=2*bx
    total +=min(a,b)
    
print(total)

Submission status: Accepted

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

res = 0

for x in x_list:
    a = x * 2
    b = abs(k - x) * 2
    res += min(a, b)

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

min_list = []
for x in xs:
    min_ = min(abs(x), abs(x-k))
    min_list.append(min_)

total = 0
for m in min_list:
    total += 2*m
print(total)

Submission status: Accepted

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

Submission status: Accepted

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

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

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):
    tgt = x[i]
    cost_a = 2*abs(tgt)
    cost_b = 2*abs(tgt-k)
    ans += min(cost_a,cost_b)
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 - 0), abs(i - K)) * 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 range(n):
    if abs(x[i]) <= abs(x[i] - k):
        ans += x[i] * 2
    else:
        ans += abs(x[i] - k) * 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 range(N):
  ans += min(x[i], K-x[i])*2
print (ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline


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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,k=int(input()),int(input())
    X=list(map(int,input().split()))
    ans=0
    for i in range(n):
        if X[i]<=0: ans+=abs(X[i])
        elif X[i]>=k: ans+=X[i]-k
        else: ans+=min(X[i],k-X[i])
    print(ans*2)
resolve()

Submission status: Accepted

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

X=list(map(lambda x: min(2*x,2*(K-x)),X))
#print(X)

print(sum(X))

Submission status: Accepted

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

result = 0
for i in range(N):
    A_dis = x_list[i]
    B_dis = abs(K - x_list[i])
    min_dif = min(A_dis, B_dis)
    result = result + (min_dif * 2)

print(result)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""


N = int(sys.stdin.readline())
K = int(sys.stdin.readline())
L = list(map(int, sys.stdin.readline().split()))

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N, = map(int, input().split())
A, = map(int, input().split())
L = [int(v) for v in input().split()]

ans = 0
for i in range(N):
    t = L[i]
    ans += min(t * 2, abs(A - t) * 2)

print(ans)

Submission status: Accepted

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

distance = 0

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

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(K-x[i],x[i]-0)

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

Submission status: Accepted

Solution code:
N,K,*X=map(int,open(0).read().split());print(sum(2*min(x,K-x)for x in X))

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:
import sys,bisect as bs,collections as cl
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
n = onem()
m = onem()
a = l()
mid = m//2
ans = 0
for i in range(n):
    if mid >= a[i]:
        ans += 2 * a[i]
    else:
        ans += 2 * abs(m - a[i])
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

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


if __name__ == "__main__":
    main()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#インポート
import sys

#入力用
def ILI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def ISI(): return map(int, sys.stdin.readline().rstrip().split())
def II(): return int(sys.stdin.readline().rstrip())
def ISS(): return sys.stdin.readline().rstrip().split()
def IS(): return sys.stdin.readline().rstrip()

N = II()
K = II()
a = ILI()
ans = 0
for x in a:
    if x < K-x:
        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()))
ans=0
for i in x:
  ans+=min(i,k-i)*2
  
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC074b
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

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

ans = 0

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

print(ans*2)

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

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    k = int(input().rstrip('\n'))
    x = list(map(int, input().rstrip('\n').split()))
    t = 0
    for v in x:
        t += (min(v, abs(k - v)) * 2)
    print(t)


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

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

Submission status: Accepted

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


if __name__ == "__main__":
    test()

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(x[i], K-x[i])
print(2*s)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

ans=0

for i in x:
  #Aロボットの移動距離は2xi
  #Bロボットの移動距離は2(k-xi)
  #AとBの最小値をansに足していく
  ans += min(i*2, abs(i-k)*2)

print(ans)

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
k = int(input())
arr = list(map(int,input().split()))

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

import sys
input = sys.stdin.readline
##############################

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

count = 0

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

print(count)

Submission status: Accepted

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

if __name__ == '__main__':
    print(main())

Submission status: Accepted

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

Submission status: Accepted

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

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

if __name__ == '__main__':
    N = int(input())
    K = int(input())
    X = [int(x) for x in input().split()]
    main(N,K,X)

Submission status: Accepted

Solution code:
n = int(input())
k = int(input())
x = list(map(int, input().split())) 
a = 0
l = 0
while n>a:
    if (k/2)>=x[a]:
        l+=2*x[a]
        a+=1
    else:
        l+=2*(k-x[a])
        a+=1
else:
    print(l)

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

print(ans)

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
k=int(input())
x=input().split()
c=0
for i in range(n):
    if 2*int(x[i])>k:
        c+=2*(k-int(x[i]))
    else:
        c+=2*int(x[i])

print(c)

Submission status: Accepted

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

Submission status: Accepted

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

# processing
res = sum([min([abs(e - 0), abs(e - K)])*2 for e in x])

# output
print(res)

Submission status: Accepted

Solution code:
# nでループを回して、sum(min(xi,k-xi))を出力する
n = int(input())
k = int(input())
x = list(map(int,input().split()))
ans = [2*min(i,k-i) for i in x]
print(sum(ans))

Submission status: Accepted

Solution code:
N = int(input())
K = int(input())
X = list(map(int, input().split()))
ans = 0
for i, x in enumerate(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()))
ans = 0

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

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

print(ans)

Submission status: Accepted

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

x=list(map(int, input().split()))
count=0
for i in range(n):
    a_dis=2*x[i]
    b_dis=abs(k-x[i])*2
    if a_dis>=b_dis:
        count+=b_dis
    else:
        count+=a_dis
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, X: "List[int]"):
    
    res = 0
    for x in X:
        res += min(x, K-x)

    print(res*2)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    x = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, K, x)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

move = []
for x in xs:
    move.append(min(2*x,2*(k-x)))
print(sum(move))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

ret=0
for i in range(N):
    if XN[i] < (K/2):
        ret+= XN[i]*2
    else:
        ret+= 2*(K-XN[i])
print(ret)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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