Problem:


Score : 200 points

Problem Statement

There are N balls in the xy-plane. The coordinates of the i-th of them is (x_i, i).
Thus, we have one ball on each of the N lines y = 1, y = 2, ..., y = N.

In order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B.
Then, he placed the i-th type-A robot at coordinates (0, i), and the i-th type-B robot at coordinates (K, i).
Thus, now we have one type-A robot and one type-B robot on each of the N lines y = 1, y = 2, ..., y = N.

When activated, each type of robot will operate as follows.

When a type-A robot is activated at coordinates (0, a), it will move to the position of the ball on the line y = a, collect the ball, move back to its original position (0, a) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything.

When a type-B robot is activated at coordinates (K, b), it will move to the position of the ball on the line y = b, collect the ball, move back to its original position (K, b) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything.

Snuke will activate some of the 2N robots to collect all of the balls. Find the minimum possible total distance covered by robots.

Constraints

1 \leq N \leq 100

1 \leq K \leq 100

0 < x_i < K

All input values are integers.

Inputs

Input is given from Standard Input in the following format:

N
K
x_1 x_2 ... x_N

Outputs

Print the minimum possible total distance covered by robots.

Sample Input 1

1
10
2

Sample Output 1

4

There are just one ball, one type-A robot and one type-B robot.

If the type-A robot is used to collect the ball, the distance from the robot to the ball is 2, and the distance from the ball to the original position of the robot is also 2, for a total distance of 4.

Similarly, if the type-B robot is used, the total distance covered will be 16.

Thus, the total distance covered will be minimized when the type-A robot is used. The output should be 4.

Sample Input 2

2
9
3 6

Sample Output 2

12

The total distance covered will be minimized when the first ball is collected by the type-A robot, and the second ball by the type-B robot.

Sample Input 3

5
20
11 12 9 17 12

Sample Output 3

74



Sample input:
1
10
2


Sample output:
4

Submission status: Accepted

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

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

print(total)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


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

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    x = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, x)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

print(sum(min(abs(K-x), abs(0-x)) * 2 for x in X))

Submission status: Accepted

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

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

print(sum)

Submission status: Accepted

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

robot_1 = 0
robot_2 = K
for i in range(N):
    distance_1 = abs(robot_1 - x[i])*2
    distance_2 = abs(robot_2 - x[i])*2

    ans += min(distance_1, distance_2)
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    K = inputInt()
    x = inputList()
    
    ans = 0
    for i, val in enumerate(x):
        tmp = min(val-0, abs(K-val))
        ans += tmp * 2
        
    print(ans)
    
            	
if __name__ == "__main__":
	main()

Submission status: Accepted

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

if __name__ == "__main__":
    main48()

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(a)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

for x in xs:
  if k - x > x:
    ans += x
  else:
    ans += k - x

print(ans * 2)

Submission status: Accepted

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

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
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n, a = II(), II()
    print(n * n - a)
    return

#B
def B():
    n = II()
    k = II()
    x = LI()
    ans = 0
    for xi in x:
        ans += min(xi, k - xi)
    print(ans * 2)
    return

#C
def C():
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    B()

Submission status: Accepted

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

Submission status: Accepted

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

dist = 0

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

print(dist)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC 74, B - collecting balls easy version
n = int(input())
k = int(input())

X = [int(el) for el in input().split(' ')]

total = 0
for x in X:
    if x < abs(k-x):
        total += 2*x
    else:
        total += 2*abs(k-x)
print(total)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b=[int(input())for i in range(2)]
c=[int(i) for i in input().split()]
d=0
for i in range(a):
  if b-c[i]>=c[i]:
    d+=c[i]*2
  else :
    d+=(b-c[i])*2
    
print(d)

Submission status: Accepted

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

Submission status: Accepted

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

isum = 0

for i in range(n):
    isum += min(x[i], k-x[i])

print(isum*2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(sum(map(lambda a: min(a, k-a), x)) * 2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = int(input())
b = int(input())
c = list(map(int,input().split()))
d = []

for i in range(a):
  d.append(2*min(c[i],abs(c[i]-b)))
else:
  print(sum(d))

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(total)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

N = int(input())
K = int(input())
x_list = [int(i) for i in input().split()]
dist = 0

for i in range(N):
    if abs(x_list[i] - K) >= x_list[i]:
        dist += 2 * x_list[i]
    else:
        dist += 2 * abs(x_list[i] - K)
print(dist)

Submission status: Accepted

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

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

if __name__ == "__main__":
    solve()

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

Submission status: Accepted

Solution code:
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N = n()
K = n()
X = nl()

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
K = int(input())
l = [int(i) for i in input().split()]
zero_kyori = 0
K_kyori = 0
kyori_list = []

for i in range(N):
    zero_kyori = (l[i] - 0) * 2
    K_kyori = (abs(l[i] - K)) * 2
    kyori_list.append(min(zero_kyori, K_kyori))

print(sum(kyori_list))

Submission status: Accepted

Solution code:
def abc():
    input()
    k = int(input())
    balls = list(map(int, input().split()))
    dist = 0
    for ball in balls:
        dist += min(ball, k - ball)
    print(dist * 2)


abc()

Submission status: Accepted

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

a=0
b=k

nums=list(map(int,input().split()))
#print(nums)

ans=[]

for i in range(n):
    ans.append(min(abs((nums[i]-a)*2),abs((b-nums[i])*2)))
print(sum(ans))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


main()

Submission status: Accepted

Solution code:
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys
import string

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

sys.setrecursionlimit(2147483647)
INF = float("inf")

N, K = [int(sys.stdin.readline()) for _ in range(2)]
X = np.array(list(map(int, sys.stdin.readline().split())))

print(np.minimum(X, abs(X - K)).sum() * 2)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# coding: utf-8
import time
import re
import math

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

Submission status: Accepted

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

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

print(answer)

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

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

Submission status: Accepted

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

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

print (ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

cnt = 0
for i in x:
    cnt += min(i,k-i)

print(cnt*2)

Submission status: Accepted

Solution code:
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###

N = int(input())
K = int(input())
Xs = list(mi())

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

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

Submission status: Accepted

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


def solve(N: int, K: int, X: "List[int]"):
    ret = 0
    for x in X:
        ret += min(abs(K - x), x) * 2
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    x = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, K, x)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def smaller(x, y):
	if x < y: return x
	return y

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

Submission status: Accepted

Solution code:
from sys import stdin
N=int(stdin.readline().rstrip())
K=int(stdin.readline().rstrip())
data=[int(x) for x in stdin.readline().rstrip().split()]
ans = 0
for i in data:
    ans += min(abs(K - i),i)
print(ans * 2)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

for i in axis:
    if i >= k/2:
        ans += (k -i)*2
    else:
        ans += i*2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math


def main():
    num = int(input())
    k = int(input())
    data = list(map(int, input().split()))

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





if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#https://atcoder.jp/contests/abc074/tasks/abc074_b
N = int(input())
K = int(input())
x = list(map(int,input().split()))
ans = 0
for i in range(N):
    ans += min(x[i]-0,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:
    ans += min(i, k - i) * 2

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

# 出力
print(sm)

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

Submission status: Accepted

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
K = int(stdin.readline().rstrip())
X = [int(_) for _ in stdin.readline().rstrip().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()))
route = 0
for i in x:
    if i < K - i:
        route += 2 * i
    else:
        route += 2 * (K - i)
print(route)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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