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:
input()
K=int(input())
print(sum([min(int(i),K-int(i))*2 for i in input().split()]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K=[int(input()) for _ in range(2)]
print(sum([2*min(K-x, x) for x 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])*2
print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
n,k,*x=map(int,open(0).read().split())
d=0
for c in x:
  d+=min(2*c,2*abs(c-k))
print(d)

Submission status: Accepted

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: Accepted

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

Submission status: Accepted

Solution code:


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

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

Submission status: Accepted

Solution code:

def read_input():
    n = int(input())
    k = int(input())
    xlist = list(map(int, input().split()))

    return n, k, xlist


def submit():
    n, k, xlist = read_input()

    dist = 0
    for x in xlist:
        adist = 2 * x
        bdist = 2 * (k - x)

        dist += min(adist, bdist)

    print(dist)

if __name__ == '__main__':
    submit()

Submission status: Accepted

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

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

print(s)

Submission status: Accepted

Solution code:
import sys
from collections import Counter

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

for i in x_list:
    if k - i < i:
        ans += (k - i) * 2
    else:
        ans += i * 2

print(ans)

Submission status: Accepted

Solution code:
# ABC074B - Collecting Balls (Easy Version)
n, k = list(map(int, [input().rstrip() for _ in range(2)]))
lst = list(map(int, input().rstrip().split()))
total = 0
for i in lst:
    total += min(i, k - i) * 2
print(total)

Submission status: Accepted

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n = f()[0]
    k = f()[0]
    x = f()

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

    print(ans)

solve()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input())
    K = int(input())
    x = list(int(_) for _ in input().split())
    ans = 0
    for i in range(N):
        ans += min(x[i],K-x[i]) * 2
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(total)

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

print(sum*2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
K = I()
x = IL()

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(l)

Submission status: Accepted

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

Submission status: Accepted

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

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 += x * 2 if x < K - x else (K - x) * 2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(sum_len)

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

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = sum(min(v * 2, abs(k - v) * 2) for v in x)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

import itertools
import collections
import bisect

def main():
    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(K - X[i])) * 2
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

length = 0

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

print(length)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
"""
n,a = IR(2)
print(n**2-a)
"""
#B
n,k = IR(2)
x = LI()
ans = 0
for i in range(n):
    ans += min(x[i]*2,(k-x[i])*2)
print(ans)
#C
"""
a,b,c,d,e,f = LI()
a *= 100
b *= 100
ans = [a,0]
for i in range(f//a+1):
    for j in range((f-a*i)//b+1):
        for k in range((f-a*i-b*j)//c+1):
            for l in range((f-a*i-b*j-c*k)//d+1):
                if i or j or k or l:
                    s = c*k+d*l
                    w = a*i+b*j
                    q = w*e//100
                    if s <= q:
                        if w+s <= f:
                            if ans[1]/ans[0] < s/(s+w):
                                ans = [w+s,s]
print(*ans)
"""

#D
"""
n = I()
d = LIR(n)
l = [[1 for j in range(n)] for i in range(n)]
for k in range(n):
    for i in range(n):
        for j in range(n):
            if d[i][j] > d[i][k]+d[k][j]:
                print(-1)
                quit()
            if d[i][j] == d[i][k]+d[k][j]:
                l[i][j] = l[i][k]+l[k][j]

ans = 0
for i in range(n):
    for j in range(n):
        if l[i][j] == 4:
            ans += d[i][j]
ans //= 2
print(ans)
"""
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
K = int(input())
x = list(map(int,input().split()))
lists = []
result = 0
for i in range(N):
    min = x[i] * 2
    num = x[i] - K
    B = abs(num) * 2
    if min > B:
        lists.append(B)
    else:
        lists.append(min)
    result += lists[i]
print(str(result))

Submission status: Accepted

Solution code:
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
from operator import itemgetter
#以下てんぷら
def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)

def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")

def ip():
    return int(input())

def pne(n):
    print(n,end='')

rem = pow(10,9)+7

n = ip()                                     #入力整数1つ
k = ip()
#a,b,c= (int(i) for i in input().split())       #入力整数横2つ以上
a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[input() for i in range(n)]    #入力セット(文字列改行あり)(2/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)

#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#こっから本文
#''' なんだかんだ必要じゃねと思って残す複数入力
s = 0
for i in range(n):
    s+= 2*min(abs(k-a[i]),a[i])
print(s)

Submission status: Accepted

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

count = 0

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

Submission status: Accepted

Solution code:
# 074 B 
N = int(input())
K = int(input())

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

Submission status: Accepted

Solution code:
import sys

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

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

    print(total)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def collecting_balls(N: int, K: int, X: list)->int:
    dist = 0
    for x in X:
        if x < K - x:
            # ボールはロボット A よりなので
            # A を動かす
            dist += 2 * x
        else:
            # ボールはロボット B よりなので
            # B を動かす
            dist += 2 * (K-x)
    return dist


if __name__ == "__main__":
    N = int(input())
    K = int(input())
    X = [int(s) for s in input().split()]
    ans = collecting_balls(N, K, X)
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

l = list(map(int,input().split()))
c = 0

for i in l:
	if i < abs(k-i):
		c += 2*i
	else:
		c += 2*abs(k-i)
print(c)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

res = 0
c = k/2
for x_ in x:
    if x_ < c:
        res += x_*2
    else:
        res += (k-x_)*2
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
"""AtCoder"""

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

ans = 0

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

distance=0
for i in X:
    adis=i*2
    bdis=abs(K-i)*2
    if adis<bdis:
        distance+=adis
    else:
        distance+=bdis
print(distance)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


N = int(input())
K = int(input())

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

ans = 0

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

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

Submission status: Accepted

Solution code:
int_n = int(input())
int_k = int(input())

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

print(sum([i if i <= abs(i - int_k) else abs(i - int_k) for i in li_x]) * 2)

Submission status: Accepted

Solution code:
n,k = [int(input()) for i in range(2)]
l = [list(map(int,input().split()))]
a = 0

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

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

Submission status: Accepted

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

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