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: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
K = int(input())
X = list(map(int,input().split()))
distance = 0
for n in range(N):
  if X[n] < K/2:
    distance += X[n]
  else:
    distance += K - X[n]
print(distance)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
k = int(input())
x_l = list(map(int, input().split()))
th = k/2

ans = 0
for x in x_l:
  if x >= th:
    ans += abs(x-k)
  else:
    ans += x
print(ans)

Submission status: Wrong Answer

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

for p in x:
  a = 2*p
  b = 2*abs(K-p)
  if a > b:
    sum_min += b
  elif a < b:
    sum_min += a

print(sum_min)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

sum = 0

for i in range(N):
  if x[i] >= K - x[i]:
    sum += K - x[i]
  
  else:
    sum += x[i]

print(sum)

Submission status: Wrong Answer

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

ans=0
for i in l:
  if i>=k/2:
    ans+=abs(k-i)*2
  else:
    ans+=i

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = int(input())
print(n**2-a)

Submission status: Wrong Answer

Solution code:
def distance(a,b,c,d):
    return int(((c-a)**2 + (d-b)**2)**0.5)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
M=int(input())
C=list(map(int,input().split()))
ans=0
for i in range(len(C)):
  lm=0
  rm=0
  lm=abs((N-C[i])*2)+4
  rm=abs((M-C[i])*2)+4
  if lm<=rm:
    ans+=lm
  else:
    ans+=rm
print(ans)

Submission status: Wrong Answer

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: Wrong Answer

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: Wrong Answer

Solution code:

N = int(input())
K = int(input())
x = list(map(int, input().split()))
K_half =  10/2

total=0

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

Submission status: Wrong Answer

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

for i in range(N):
    A = a[i]
    B = K-a[i]
    sum_a += min(A,B)
    
    
print(sum_a)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
from collections import deque
from collections import defaultdict

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq

n = readInt()
k = readInt()
x = readInts()

ans = 0
for i in range(n):
	ans+=min(x[i],abs(x[i]-k))
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
def main():
  N = int(input())
  K = int(input())
  x = list(map(int, input().split()))
  x = np.array(x)
  print(min(np.sum(x), np.sum(K-x)))
if __name__ == "__main__":
  main()

Submission status: Wrong Answer

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

line = K // 2
ans = 0

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

Submission status: Wrong Answer

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

line = K // 2
ans = 0

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

Submission status: Wrong Answer

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

x = tuple([int(t)for t in input().split()]) 

print(sum(x))

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
K = int(input())
X = input().split()
S = 0
for i in range(N):
  if (K-int(X[i])) > int(X[i]) :
    S += int(X[i])
  else:
    S += (K-int(X[i]))
print(S)

Submission status: Wrong Answer

Solution code:
N=int(input())
K=int(input())
c=list(map(int, input().split()))
l=[K]*N
sub=[]
res=[]
for i in range(0, N):
	sub.append(l[i]-c[i])
	if (sub[i]<=c[i]):
		res.append(2*sub[i])
	else:
		res.append(2*c[i])

Submission status: Wrong Answer

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)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

distance = []

for i in range(n):
  if abs(x[i] - 0) < abs(x[i] - k):
    distance.append(abs((x[i] - 0) * 2))
  else:
    distance.append(abs((x[i] - k) * 2))

print(distance)
print(sum(distance))

Submission status: Wrong Answer

Solution code:
N = int(input())
K = int(input())
X = list(map(int, input().split()))
count = 0
for i in X:
    A = i
    B =abs(i - K)
    if A >= B:
        count = count + B
    else:
        count = count + A
print(count)

Submission status: Wrong Answer

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

length = 0

for i in x:
    length += min(i,K-i)

print(length)

Submission status: Wrong Answer

Solution code:
import sys

lines = sys.stdin.readlines()

N = int(lines[0])
K = int(lines[1])
X = lines[2].split(' ')
x =[]

y = 0
for i in range(N):
  x.append(int(X[i]))
  if 2*x[i] >= K:
      dist = K-x[i]
  else:
      dist = x[i]
  y = y + dist

print(y)

Submission status: Wrong Answer

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

ans = 0
mid = (0 + k) // 2

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

Submission status: Wrong Answer

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

x_L = sorted(x_L)

center = int(k/2)

a_L,b_L = [],[]

for i in x_L:
    if i < center:
        a_L.append(i)
    else:
        b_L.append(i)

a_dis,b_dis = 0,0

for i in a_L:
    a_dis += 2*i
for i in b_L:
    b_dis += 2*(k-i)

#print(a_L,b_L)
#print(a_dis,b_dis)
print(a_dis+b_dis)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
k = int(input())
xxx = list(map(int, input().split()))
ans = sum(min(x, abs(k - x)) for x in xxx)
print(ans)

Submission status: Wrong Answer

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

ans = 0

p1 = 0
p2 = K

for i in range(N):
    if abs(x[i] - p1) < abs(x[i] - p2):
        ans += abs(x[i] - p1)*2
        p1 = x[i]
    else:
        ans += abs(x[i] - p2)*2
        p2 = x[i]

print(ans)

Submission status: Wrong Answer

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)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

lis = []
for i in range(len(A)):
  for j in range(len(A)):
    lis.append(abs(A[i]-A[j]))

print(max(lis))

Submission status: Wrong Answer

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

ans = 0

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

l = [int(i) for i in input().split()]
s = 0

for i in range(n):
  if k - l[i] > l[i]:
    s += l[i]  * 2
 
  elif k - l[i] < l[i]:
    s += 2 * (k - l[i])
    
print(s)

Submission status: Wrong Answer

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

sum = 0
for ball in b:
  sum += ball - 0 if (ball - 0) < k - ball else k - ball
  
  print(sum*2)

Submission status: Wrong Answer

Solution code:
n = int(input())
b = int(input())
d = list(map(int, input().split()))
c = 0
for i in d:
    if i < b - i:
        c += i
    else:
        c += b-i
print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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]) + max(x[i], k-x[i])

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
k = int(input())
x = map(int, input().split())
s = 0
for xx in x:
  s += min(xx, k-xx)
print(s)

Submission status: Wrong Answer

Solution code:
def main48():
    n = int(input())
    k = int(input())
    data = input().split()
    x = []
    for i in range(n):
        x.append(int(data[i]))
    result = 0
    for i in range(n):
        if x[i] < k-x[i]:
            result = result + x[i]
        else:
            result = result + k-x[i]
    print(result)

if __name__ == "__main__":
    main48()

Submission status: Wrong Answer

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

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

print(sum(min(x, k-x) for x in arr))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans=0

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(sum_len)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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)

Submission status: Wrong Answer

Solution code:
N=int(input())
K=int(input())
def ans(s):
  n=int(s)
  return 2*min(K-n,n)
x=list(map(int,input().split()))
print(sum(x))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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)

Submission status: Wrong Answer

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))
print(sum(l))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#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: Wrong Answer

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: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0

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

    print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
X=int(input())
Y=int(np.sqrt(X))+1
max=1
for j in range(2,Y+1):
    for i in range(1,Y+1):
        if i**j<=X and i**j>max:
            max=i**j
print(max)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
k=int(input())
l=[int(x) for x in range(n)]
s=0
for i in range(n):
  if abs(l[i]-k)>abs(l[i]):
    s+=abs(l[i])
  else:
    s+=abs(l[i]-k)
print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
NUM = int(input())
K = int(input())
POS = list(map(int, input().split()))
a = 0
b = 0
sum = 0
for i in POS:
    a = pow(i, 2)
    b = pow(abs((i - K)), 2)
    sum += min(a, b)
print(sum)

Submission status: Wrong Answer

Solution code:
NUM = int(input())
K = int(input())
POS = list(map(int, input().split()))
a_sum = 0
b_sum = 0
for i in POS:
    a_sum += pow(i, 2)
    b_sum += pow(abs((i - K)), 2)

print(min(a_sum, b_sum))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0
if K==1:
    print(0)
else:
    for xi in x:
        if xi < K//2:
            ans += xi*2
        else:
            ans += (K-xi)*2
    print(ans)

Submission status: Wrong Answer

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

sum = 0

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

print(sum)

Submission status: Wrong Answer

Solution code:
import math
N,K=input(),input()
x = [int(_) for _ in raw_input().split()]
sum = 0

for i in range(N):
	if abs(x[i]) < abs(K-x[i]):
		tmp = abs(x[i])
		sum += tmp
	else:
		tmp = abs(x[i])
		sum += tmp
print(sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

a = 0
for i in x:
    if float(i) < (K / 2):
        a += i * 2
    elif float(i) > (K / 2):
        a += (K - i) * 2

print(a)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

a = 0
for i in x:
    if i < int(K / 2):
        a += i * 2
    elif i > int(K / 2):
        a += (K - i) * 2

print(a)

Submission status: Wrong Answer

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

ans = 0
if K == 1:
    print(2*N)
else:
    for xi in x:
        if xi < K//2:
            ans += xi*2
        else:
            ans += (K-xi)*2
    print(ans)

Submission status: Wrong Answer

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

n = int(input())
k = int(input())
x = list(map(int, input().split())) #x[0->(n-1)]

sum = 0

for i in x:
    if i < k - i:
        sum = sum + i
    else:
        sum = sum + k - i

print(sum)

Submission status: Wrong Answer

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

ans = 0
for xi in x:
    if xi < K//2:
        ans += xi*2
    else:
        ans += (K-xi)*2
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

n = int(input())
k = int(input())
x = list(map(int, input().split())) #x[0->(n-1)]

sum = 0

for i in x:
    if i > k - i:
        sum = sum + i
    else:
        sum = sum + k - i

print(sum)

Submission status: Accepted

Solution code:
N = int(input())
K = int(input())
X = list(map(int, input().split()))
Y = [i for i in range(1, N+1)]
ans = 0

for x in X:
    distance_a = x
    distance_b = abs(K-x)
    if distance_a < distance_b:
        ans += distance_a
    else:
        ans += distance_b
    
print(ans*2)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
K = int(input())
X = list(map(int,input().split()))
distance = 0
for n in range(N):
  if X[n] < K/2:
    distance += X[n]
  else:
    distance += K - X[n]
print(distance*2)

Submission status: Accepted

Solution code:
def int_list(sepalate=" "): return list(map(int, input().split(sepalate)))


def solve1(n, k, x):
    ans = 0

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

    return ans


n = int(input())
k = int(input())
x = int_list()
print(solve1(n, k, x))

Submission status: Accepted

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


def solve(N: int, K: int, x: "List[int]"):
    return sum(min(xx, abs(xx-K)) for xx in x) * 2


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
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]"
    print(solve(N, K, x))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from typing import List


def answer(n: int, k: int, xs: List[int]) -> int:
    moving_distance = 0
    reference_value = k / 2
    for x in xs:
        if x <= reference_value:
            moving_distance += x * 2
        else:
            moving_distance += (k - x) * 2

    return moving_distance


def main():
    n = int(input())
    k = int(input())
    xs = list(map(int, input().split()))
    print(answer(n, k, xs))


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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for i in v:
    tmp = min(i, k-i)
    ans += tmp
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:
N=int(input())
K=int(input())
X=list(map(int,input().split()))

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

Submission status: Accepted

Solution code:
import sys
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

n = I()
k = I()
x = LI()


# xy平面上の（xi, i)にボールが配置されている。つまり各行に対して必ず一つボールがある。
# これを回収する2種類のロボットA,BをN台ずつ用意している。
# Aのi代目を(0, i)に、Bのi代目を(k, i)に設置した。
# Aロボットは、x=0からスタート, Bロボットはx = kからスタートして、各行上のボールを回収して元の位置に戻る。
# 各行のロボットを起動してすべてのボールを回収するとき、ロボットの移動距離の総和の最小値を求めよ
mov = 0

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

print(mov)

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/local/bin/python3
# https://atcoder.jp/contests/abc074/tasks/abc074_b

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

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