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:
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    n = i_input()
    k = i_input()
    num_list = i_list()

    count = 0 
    for num in num_list:
        count += min(num, k - num)

    print(count*2)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

sum = 0

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

print(sum)

Submission status: Accepted

Solution code:
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
k = inint()
X = inintl()

ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

dist = 0

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

Submission status: Accepted

Solution code:
# # Make IO faster
# import sys
# input = sys.stdin.readline

# # get single (or) multiple str
# X = input()

# # get single int
# N = int(input())
# # get multiple int (e.g., 2)
# X, Y = map(int, input().split())
# # get multiple int (e.g., 2) for N lines
# XY = [list(map(int, input().split())) for _ in range(N)]

# from IPython import embed; embed(); exit();

# 全部入り
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
K = INT()
x = list(MAP())

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

Submission status: Accepted

Solution code:
N, K = [int(input()), int(input())]

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

res = 0

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

print(res)

Submission status: Accepted

Solution code:
N = int(input())
K = int(input())
x = 0
arrayx = list()
if N == 1:
  x = int(input())
  if x <= (K - x):
    print(x * 2)
  else:
    print((K - x) * 2)
  exit(0)
else:
  arrayx = list(map(int,input().split()))

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

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    K = int(input())
    X = map(int, input().split())
    ans = 0

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


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K, *X = map(int, read().split())

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

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

print(sum([2*min(b,k-b) for b 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):
  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:
N = int(input())
K = int(input())
X = list(map(int, input().split()))

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

print(c)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# coding: utf-8
import math
#a, b, c = map(int,input().split())
N = int(input())
K = int(input())
#S = input()
ans = 0
#l = list(map(int,input().split()))
A = list(map(int,input().split()))

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

print(ans)

Submission status: Accepted

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

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

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 = [int(i) for i in input().split()]

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
k = int(input())
x = list(map(int, input().split()))

cnt = 0

for i in x:
    if i <= (k / 2):
        cnt += i * 2
    else:
        cnt += (k - i) * 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:
    left = x*2
    right = abs(k-x)*2
    ans += min(left, right)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
K = int(input())
MM = input().split()
total = 0
for i in MM:
  x = int(i)
  y = K - int(i)
  if x <= y:
    total += x*2
  else:
    total += y*2
print(total)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N = I()
K = I()
x = LI()

print(2*sum(min(x[i],K-x[i]) for i in range(N)))

Submission status: Accepted

Solution code:
n, k = [int(input()) for _ in range(2)]
x = list(map(int, input().split()))

print(sum([min(x[i], abs(x[i] - k)) * 2 for i in range(n)]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

suml = [0] * N

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

print(sum(suml))

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 = int(input())
k = int(input())
x = list(map(int,input().split()))
ans = 0

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

Submission status: Accepted

Solution code:
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') 
inf = float('inf') ;mod = 10**9+7 
mans = inf ;ans = 0 ;count = 0 ;pro = 1

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9

def main():
    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))
    print(ans*2)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

v = input()
k = int(v)

locations = []

sub = []

answer = 0

x = input().split()
for i in range(n):
    y = int(x[i])
    locations.append(y)

for i in range(len(locations)):
    sub.append(min(locations[i], k - locations[i]) * 2)

for i in range(len(sub)):
    answer += sub[i]

print(answer)

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

print(s)

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

Submission status: Accepted

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

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

print(res)

Submission status: Accepted

Solution code:
N_ko = int(input())
K = int(input())
x_s = list(map(int, input().split()))

ans_list = [min(abs(i - 0), abs(K - i)) for i in x_s]
ans = 2 * sum(ans_list)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#ABC 074 B

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

cnt = 0

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

Submission status: Accepted

Solution code:
from sys import stdin

n = int(stdin.readline().strip())
k = int(stdin.readline().strip())
x_lst = [int(x) for x in stdin.readline().strip().split()]
sum_move = 0

# 絶対値の小さい方で和を取ればいいだけ
for x in x_lst:
  sum_move += min(abs(k-x), abs(x)) * 2
  
print(sum_move)

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

a = []
res = 0

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

num = 0

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

Submission status: Accepted

Solution code:
n=int(input())
k=int(input())
x=input().split(" ")
for i in range(len(x)):
  x[i]=int(x[i])
y=[]
for i in x:
  y.append(k-i)
c=0
for i in range(len(x)):
  c+=min(x[i],y[i])*2

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

Submission status: Accepted

Solution code:
def resolve():
    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)
    return

resolve()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
K = int(input())
x = [int(x) for x in 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 = int(input())
k = int(input())
x = list(map(int,input().split()))
a = 0
b = 0
c = 0

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

Submission status: Accepted

Solution code:
def resolve():
    n = int(input())
    k = int(input())
    pos = list(map(int, input().split()))

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

Submission status: Accepted

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

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()))
ans=0
mid=k/2
for i in x:
    if i>mid:
        ans+=(2*abs(k-i))
    else:
        ans+=i*2
    
print(ans)

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

Submission status: Accepted

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

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

print(cost)

Submission status: Accepted

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    K = ii()
    X = il()

    ret = 0
    for n in range(N):
        ret += min(X[n] * 2, abs(K - X[n]) * 2)
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(sum)

Submission status: Accepted

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

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

ans = 0
tmp_N = 0
tmp_K = 0
min_xi = 0

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

print(ans)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n = int(input())
    k = int(input())
    a = [int(i) for i in input().split()]

    ans = 0

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

Submission status: Accepted

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


resolve()

Submission status: Accepted

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

ans = 0
for x in xs:
    ans += 2 * min(x, 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 += 2 * (x if x <= K//2 else K - x)

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    N = int(input())
    K = int(input())
    xs = [int(item) for item in input().split()]

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

    print(res)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
K = int(input())
X = np.array(input().split(), int)
Y = K - X

ans = [2 * min(x,y) for x,y in zip(X,Y)]
print(sum(ans))

Submission status: Accepted

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

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

print(result)

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

Submission status: Accepted

Solution code:
n, k, *xx = map(int, open(0).read().split())

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
K = int(input())
X = input().split(' ')
X = [int(X[i]) for i in range(len(X)) ]
distance = 0
for i in range(N):
  if abs(X[i]) - abs(X[i]-K) > 0:
    distance += abs(X[i]-K)*2
  else:
    distance += abs(X[i])*2
print(distance)

Submission status: Accepted

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

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

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])
    D+=d
print(2*D)

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

print(total)

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

res = 0

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

Submission status: Accepted

Solution code:
# ####################################################################
# import io
# import sys

# _INPUT = """\
# 84 97 66
# 79 89 11
# 61 59 7
# 7
# 89
# 7
# 87
# 79
# 24
# 84
# 30

# """
# sys.stdin = io.StringIO(_INPUT)
####################################################################
import sys
def p(*_a):
  # return
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
####################################################################
yn = lambda b: print('Yes') if b else print('No')
####################################################################
N = int(input())
K = int(input())
X = [int(i) for i in input().split()]

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

print(ans)