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:
def main():
    n = int(input())
    k = int(input())
    l = [int(i) for i in input().split()]

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# ABC 074
def getInt(): return int(input())
def getIntList(): return [int(x) for x in input().split()]
N = getInt()
K = getInt()
x = getIntList()
d = 0
for i in range(N):
    d += min(x[i], abs(K-x[i]))*2
print(d)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

count = 0
for i in range(n):
    count += min([x_list[i], k-x_list[i]])*2

print(int(count))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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


abc074_b()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
#B Collecting Balls (Easy Version)
n = int(input())
k = int(input())
l = list(map(int, input().split()))
for i in range(n):
    l[i] = min(l[i],abs(l[i]-k))*2
print(sum(l))

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
k = int(K/2)
for x in X:
  if(x > k):
    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()))

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

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

Submission status: Accepted

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


def main():
    """Function."""
    n = int(input())
    k = int(input())
    x = list(map(int, input().split()))

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    k = int(input())
    xs = list(map(int, input().split()))
    res = sum(2 * min(x, abs(x - k)) for x in xs)
    print(res)


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

Submission status: Accepted

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

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

print(distance_sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
K=int(input())
count=0
Min=0

a=input().strip().split(" ")
a=[int(i) for i in a]

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

print(count)

Submission status: Accepted

Solution code:
# coding: utf-8
N = int(input())
K = int(input())
lst = list(map(int, input().split()))
print(sum(min(x*2, (K-x)*2) for x in lst))

Submission status: Accepted

Solution code:
# coding: utf-8
N = int(input())
K = int(input())
lst = list(map(int, input().split()))

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

result = sum(min(x, K - x) * 2 for x in Xs)

print(result)

Submission status: Accepted

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

# x_listごとにループ
for xi in x_list:
	# x_listと(K-xi)の比較
    # 小さい方を選んで2倍して足す
    x_move += min(xi,K-xi)*2
    
#出力
print(x_move)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for num in num_list:
    ans += 2*min(num,k-num)
print(ans)

Submission status: Accepted

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

for num in num_list:
    diff = k-num
    if num > diff:
        ans += diff*2
    else:
        ans += num*2
print(ans)

Submission status: Accepted

Solution code:
# https://beta.atcoder.jp/contests/abc074/tasks/abc074_b


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

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


if __name__ == '__main__':
    solve()

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = int(input())
k = int(input())
ar = list(map(int,input().split(" ")))
count = 0
for r in ar:
    if abs(0-r) >= abs(r-k):
        count += abs(r-k)
    else:
        count += abs(0-r)
print(count * 2)

Submission status: Accepted

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

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

Submission status: Accepted

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

print(count)

Submission status: Accepted

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

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

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(x, K - x)

print(2 * R)

Submission status: Accepted

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

Submission status: Accepted

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

for item in li:
        total += 2* min(item , k-item)

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

Submission status: Accepted

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

for i in range(n):
    if int(x[i]) < k-int(x[i]):
        listy.append(int(x[i]))
    else:
        listy.append(k-int(x[i]))
    
print(2*sum(listy))

Submission status: Accepted

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

ans = 0
for x in xx:
    if k-x > x:
        ans += x*2
    else:
        ans += (k-x)*2
print(ans)

Submission status: Accepted

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

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

total = 0

for i in range(len(xs)):
    bx = xs[i]
    by = i + 1
    v1 = bx * 2
    v2 = abs(K - bx) * 2
    v = v1 if (v1 < v2) else v2 
    total += v
    
print(total)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input()
k = int(input())
ax = [int(s) for s in input().split()]
s = 0

for a in ax:
  s += min(a, abs(k - a))

print(2 * s)

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(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 x in X:
    a = x * 2
    b = (K - x) * 2
    ans += min(a, b)
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n=int(input())
k=int(input())
s = list(map(int, input().split()))
r=0
for i in range(0,n):
  if s[i] < k-s[i]:
    r=r+(s[i]*2)
  else:
    r=r+(k-s[i])*2
print(r)

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:
from sys import stdin


def main() -> None:
    n, k = [next_int() for _ in range(2)]
    a = b = 0
    for i in range(n):
        xi = next_int()
        if xi <= k // 2:
            a += xi
        else:
            b += k - xi
    print((a + b) * 2)


def next_int() -> int:
    return int(next_str())


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


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

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

Submission status: Accepted

Solution code:
n = int(input())
k = int(input())
mid = k/2
date = list(map(int,input().split()))
ans = []
for i in date:
  if i <= mid:
    ans.append(i*2)
  else:
    ans.append(abs(i-k)*2)
print(sum(ans))

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

goukei = []
for i in range(N):
    goukei.append(min([abs(x[i] - 0), abs(x[i] - K)]))

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

Submission status: Accepted

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

walk_sum = 0
for n_i in range(n):
    walk_sum += min(2*x[n_i], 2*(k-x[n_i]))

print(walk_sum)

Submission status: Accepted

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

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

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:
def fa(): #final answer
    global ans
    print(ans)
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
N = getN()
K= getN()

xs = getList()

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

print(ans)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
k = ni()
x = list(li())

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

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

Submission status: Accepted

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

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

print(sum)

Submission status: Accepted

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

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

ans = 0

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

    else:
        ans += 2 * x[i]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
distance = 0
N = int(input())
K = int(input())
xi = list(map(int,input().split()))
for i in xi:
    if abs(i) > abs(K-i):
        distance+=(K-i)
    else:
        distance+=abs(i)

print(distance*2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

sum = 0

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

print(sum)

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


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

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


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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
#全体のボールの数
N = int( input() )
#Kの数
K = int( input() )
#入力のリスト代入
list = map( int, input().split() )
#個別に確認
x = 0
for num in list:
    a = num * 2
    b = (K - num) * 2
#比較して加算
    if b <= a:
        x += b
    elif b > a:
        x += a
#値の出力
print( x )

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

print(ans)

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
#74b
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())
x = list(map(int, input().split()))
ans = 0
for num in x:
    if num <= abs(K-num):
        ans += 2*num
    else:
        ans += 2*abs(K-num)
print(ans)

Submission status: Accepted

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

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

print(ans*2)

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N = int(input())
K = int(input())
xx = inpl()
ans = 0
for x in xx:
	ans += min(x,K-x)*2

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

    distance = 0

    for i in x_list:
        distance += 2 * min(k - i, i)
    
    print(distance)

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

Submission status: Accepted

Solution code:
def f(K):
  return lambda n:min(int(n),K-int(n))*2

N=int(input())
K=int(input())
g=f(K)
x=map(g,input().split())
print(sum(x))

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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))
ans *= 2
print(ans)

Submission status: Accepted

Solution code:
n = input()
k = input()
n = int(n)
k = int(k)
xs = input().split(" ")

l = list()
for x in xs:
	l.append(int(x))

cost = 0
for arg in l:
	if (2 * arg) <= (2 * abs(k - arg)):
		cost += (2 * arg)
	else:
		cost += (2 * abs(k - arg))

print(cost)

Submission status: Accepted

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

kyori = []
for i in range(len(Ns)):
	a = Ns[i]
	b = K - Ns[i]

	if(a<=b):
		kyori.append(a*2)
	else:
		kyori.append(b*2)

print(sum(kyori))

Submission status: Accepted

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

Submission status: Accepted

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

total = 0
for y, v in enumerate(x):
    total += min(k-v, v) * 2

print(total)

Submission status: Accepted

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

result = 0

for i in range(len(x)):
  if x[i] * 2 <= abs((x[i] - K) * 2):
    result += x[i] * 2
  else:
    result += abs((x[i] - K) * 2)

print(result)

Submission status: Accepted

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

x = tuple(map(int, input().split()))
assert len(x) == n

r = sum([min(k - x[i], x[i]) for i in range(len(x))]) * 2
print(r)

Submission status: Accepted

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

Submission status: Accepted

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