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
10
2

-----Sample Output-----
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.
[{"code": "n = int(input())\nk = int(input())\nx = list(map(int,input().split()))\nans = 0\nfor i in range(n):\n    ans += 2*min(k-x[i],x[i])\nprint(ans)", "passed": true, "time": 0.14, "memory": 14116.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\nli = list(map(int,input().split()))\n\ndis = 0\nfor i in range(n):\n    dis += min(2*li[i],2*abs(li[i]-k))\n\nprint(dis)", "passed": true, "time": 0.29, "memory": 14240.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\nx = list(map(int, input().split()))\nans = 0\n\nfor i in x:\n  ans += 2*min(i,abs(k-i))\n\nprint(ans)", "passed": true, "time": 0.19, "memory": 14176.0, "status": "done"}, {"code": "N=int(input())\nK=int(input())\nX=list(map(int,input().split()))\n\nans=0\nfor x in X:\n    ans+=min(abs(x),abs(x-K))*2\nprint(ans)", "passed": true, "time": 0.19, "memory": 14212.0, "status": "done"}, {"code": "N = int(input())\nK = int(input())\nX = list(map(int,input().split()))\n\nans = 0\nfor x in X:\n    ans += min(abs(x),abs(x-K))\n\nprint(ans*2)", "passed": true, "time": 0.15, "memory": 14272.0, "status": "done"}, {"code": "N = int(input())\nK = int(input())\nprint((sum([min(int(a), K - int(a)) for a in input().split()]) * 2))\n", "passed": true, "time": 0.29, "memory": 14168.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\nxn = list(map(int,input().split()))\n\nclass Solution:\n    def __init__(self,n,k,xn):\n        self.n = n\n        self.k = k\n        self.xn = xn\n    \n    def printout(self):\n        print(n,k,xn)\n    \n    def answer(self):\n        total = 0\n        total = 0\n        for xi in xn:\n            a = abs(xi - 0)\n            b = abs(xi - k)\n            if a <= b:\n                total += a * 2\n            else:\n                total += b * 2\n        print(total)\n\nconditions = Solution(n,k,xn)\nconditions.answer()", "passed": true, "time": 0.21, "memory": 14248.0, "status": "done"}, {"code": "def mapt(fn, *args):\n    return tuple(map(fn, *args))\n\n\ndef Input():\n    return mapt(int, input().split(\" \"))\n\n\ndef main():\n    n, k = (int(input()) for _ in range(2))\n    x = Input()\n    ans = 0\n    for i in range(n):\n        ans += min(abs(0-x[i]), abs(k-x[i])) * 2\n    print(ans)\n\n\nmain()", "passed": true, "time": 0.19, "memory": 14248.0, "status": "done"}, {"code": "N = int(input())\nK = int(input())\nx = list(map(int,input().split()))\ndistance = 0\n\nfor i in range(N):\n  distance += min(2*x[i],2*abs(x[i]-K))\n  \nprint(distance)", "passed": true, "time": 0.26, "memory": 14180.0, "status": "done"}, {"code": "N = input()\nK = int(input())\nl = input().split()\n         \n\n         \nans =0 \nfor i in l:\n\ts = int(i)\n\tans += min(s,K-s)\nprint((ans*2))\n", "passed": true, "time": 0.2, "memory": 14080.0, "status": "done"}, {"code": "n=int(input())\nk=int(input())\nx=list(map(int,input().split()))\nans=0\nfor i in range(n):\n    ans+=min(x[i],k-x[i])\nprint(2*ans)", "passed": true, "time": 0.14, "memory": 14312.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\nxn = list(map(int, input().split()))\n\n\nclass Solution:\n    def __init__(self, n, k, xn):\n        self.n = n\n        self.k = k\n        self.xn = xn\n\n    @staticmethod\n    def printout():\n        print(n, k, xn)\n\n    @staticmethod\n    def answer():\n        total = 0\n        for xi in xn:\n            a = abs(xi - 0)\n            b = abs(xi - k)\n            if a <= b:\n                total += a * 2\n            else:\n                total += b * 2\n        print(total)\n\n\nconditions = Solution(n, k, xn)\nconditions.answer()", "passed": true, "time": 0.14, "memory": 14232.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\nx = list(map(int, input().split()))\n\ntot_dis = 0\nfor i in range(n):\n    min_dis = min(x[i], k-x[i])\n    tot_dis += 2*min_dis\nprint(tot_dis)", "passed": true, "time": 0.23, "memory": 14264.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\npoints = list(map(int, input().split()))\n\nans = 0\nfor i in points:\n    minimum = min(abs(k-i), abs(i))\n    ans += minimum*2\n\nprint(ans)", "passed": true, "time": 0.15, "memory": 14268.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\nli = list(map(int,input().split()))\ntotal = 0\nfor i in range(n):\n    total += 2*min(li[i],k-li[i])\nprint(total)", "passed": true, "time": 0.14, "memory": 14340.0, "status": "done"}, {"code": "def int_list(sepalate=\" \"): return list(map(int, input().split(sepalate)))\n\n\ndef solve1(n, k, x):\n    ans = 0\n\n    for i in range(n):\n        ans += min(abs(k-x[i]), x[i]) * 2\n\n    return ans\n\n\nn = int(input())\nk = int(input())\nx = int_list()\nprint((solve1(n, k, x)))\n", "passed": true, "time": 0.15, "memory": 14320.0, "status": "done"}, {"code": "#!/usr/local/bin/python3\n# https://atcoder.jp/contests/abc074/tasks/abc074_b\n\nN = int(input())\nK = int(input())\nX = list(map(int, input().split()))\n\nans = 0\nfor x in X:\n    if x > abs(K-x):\n        ans += abs(K-x)*2\n    else:\n        ans += x*2\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14272.0, "status": "done"}, {"code": "n,k=int(input()),int(input());print(sum([min(i*2,(k-i)*2) for i in list(map(int,input().split()))]))", "passed": true, "time": 0.14, "memory": 14072.0, "status": "done"}, {"code": "N = int(input())\nK = int(input())\nX = list(map(int, input().split()))\nans = 0\n\nfor i in range(N):\n    if X[i] <= (K - X[i]):\n        ans += (X[i] * 2)\n    else:\n        ans += ((K - X[i]) * 2)\nprint (ans)", "passed": true, "time": 0.15, "memory": 14044.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\nx = list(map(int, input().split()))\nans = 0\nfor i in x:\n    ans += min(i,k-i)\nprint(2*ans)", "passed": true, "time": 0.14, "memory": 14320.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\nx = [int(x) for x in input().split()]\n\n\nans = 0\nfor i in range(n):\n    ans += 2*min(x[i], abs(x[i]-k))\n\nprint(ans)", "passed": true, "time": 0.2, "memory": 14096.0, "status": "done"}, {"code": "N = int(input())\nK = int(input())\nX = list(map(int, input().split()))\n\nans = 0\n\nfor x in X:\n    ans += min(x, K-x)*2\n    \nprint(ans)", "passed": true, "time": 0.14, "memory": 14224.0, "status": "done"}, {"code": "N = int(input())\nK = int(input())\nx = list(map(int, input().split()))\nans = 0\nfor i in x:\n  ans += min(i, K - i) * 2\nprint(ans)", "passed": true, "time": 0.15, "memory": 14216.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\nx = [int(x.strip()) for x in input().split()]\nans = 0\nfor i in x:\n  if abs(i-k) > i:\n    ans = ans + i\n  else:\n    ans = ans + abs(i-k)\nans += ans\nprint(ans)", "passed": true, "time": 0.14, "memory": 14184.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\nx = [int(s) for s in input().split()]\n\nmove = 0\nfor i in x:\n    move += min(i, abs(i - k)) * 2\nprint(move)", "passed": true, "time": 0.14, "memory": 14084.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\nx_l = list(map(int, input().split()))\nth = k/2\n\nans = 0\nfor x in x_l:\n  if x >= th:\n    ans += abs(x-k)\n  else:\n    ans += x\nprint(ans*2)", "passed": true, "time": 0.14, "memory": 14216.0, "status": "done"}, {"code": "n,k = [int(input()) for i in range(2)]\nx = list(map(int,input().split()))\n\ndistance = 0\n\nfor i in range(len(x)):\n    distance += 2*(min(x[i], abs(x[i]-k)))\n    \nprint(distance)", "passed": true, "time": 0.14, "memory": 14260.0, "status": "done"}, {"code": "a=int(input())\nb=int(input())\nc=list(map(int,input().split()))\ntotal=0\nfor i in range(a):\n    d=2*c[i]\n    e=2*abs(b-c[i])\n    total+=min(d,e)\nprint(total)", "passed": true, "time": 0.27, "memory": 14112.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\nline = list(map(int, input().split()))\nans = 0\nfor i in range(n):\n  ans += min(line[i], k-line[i]) * 2\nprint(ans)", "passed": true, "time": 0.14, "memory": 14148.0, "status": "done"}, {"code": "N=int(input())\nK=int(input())\nx=list(map(int,input().split()))\n\nans=0\nfor i in range(N):\n    a=abs(x[i])*2\n    b=abs(K-x[i])*2\n    ans+=min(a,b)\n    \nprint(ans)", "passed": true, "time": 0.14, "memory": 14080.0, "status": "done"}, {"code": "_,k=input(),int(input());print(sum([min(i*2,(k-i)*2) for i in list(map(int,input().split()))]))", "passed": true, "time": 0.22, "memory": 14308.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\ndata = list(map(int,input().split()))\nans = 0\nfor i in range(n):\n    ans += min(data[i]*2, (k - data[i])*2)\nprint(ans)", "passed": true, "time": 0.14, "memory": 14044.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\nL = list(map(int,input().split()))\nans = 0\nfor l in L:\n  a = l\n  b = abs(k-l)\n  ans += min(a,b)*2\nprint(ans)", "passed": true, "time": 0.14, "memory": 14124.0, "status": "done"}, {"code": "#!/usr/bin/env python3\nimport sys\n\n\ndef solve(N: int, K: int, x: \"List[int]\"):\n    return sum(min(xx, abs(xx-K)) for xx in x) * 2\n\n\n# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools\ndef main():\n    def iterate_tokens():\n        for line in sys.stdin:\n            for word in line.split():\n                yield word\n    tokens = iterate_tokens()\n    N = int(next(tokens))  # type: int\n    K = int(next(tokens))  # type: int\n    x = [int(next(tokens)) for _ in range(N)]  # type: \"List[int]\"\n    print((solve(N, K, x)))\n\ndef test():\n    import doctest\n    doctest.testmod()\n\ndef __starting_point():\n    #test()\n    main()\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14352.0, "status": "done"}, {"code": "import math\n\nn = int(input())\nk = int(input())\nx = list(map(int,input().split()))\ncnt = 0\n\ndis = math.ceil(k/2)\nfor i in x:\n    if i == k:\n        continue\n    elif i <= dis:\n        cnt += i*2\n    else:\n        cnt += (k-i)*2\nprint(cnt)\n", "passed": true, "time": 0.18, "memory": 14264.0, "status": "done"}, {"code": "import sys\ninput = lambda: sys.stdin.readline().rstrip() \nsys.setrecursionlimit(10**7)\nINF = 10**20\ndef I(): return int(input())\ndef F(): return float(input())\ndef S(): return input()\ndef LI(): return [int(x) for x in input().split()]\ndef LI_(): return [int(x)-1 for x in input().split()]\ndef LF(): return [float(x) for x in input().split()]\ndef LS(): return input().split()\n\ndef resolve():\n    N = I()\n    K = I()\n    x = LI()\n\n    ans = sum([2 * min(x[i], K - x[i]) for i in range(N)])\n    print(ans)\n\ndef __starting_point():\n    resolve()\n__starting_point()", "passed": true, "time": 0.15, "memory": 14276.0, "status": "done"}, {"code": "N = int(input())\nK = int(input())\nx = list(map(int, input().split()))\n\nsum = 0\nfor i in range(N):\n  dist = min(x[i], abs(x[i]-K))\n  sum += dist\n  \nprint(sum*2)", "passed": true, "time": 0.14, "memory": 14324.0, "status": "done"}, {"code": "n,k=int(input()),int(input());print(sum([min(abs(i*2),abs((i-k)*2)) for i in list(map(int,input().split()))]))", "passed": true, "time": 0.14, "memory": 14076.0, "status": "done"}, {"code": "a=int(input())\nb=int(input())\nc=list(map(int,input().split()))\nd=0\nfor i in range(a):\n  if c[i]<b-c[i]:\n    d=d+c[i]\n  else:\n    d=d+b-c[i]\nprint(2*d)", "passed": true, "time": 0.14, "memory": 14272.0, "status": "done"}, {"code": "#\n# abc074 b\n#\nimport sys\nfrom io import StringIO\nimport unittest\n\n\nclass TestClass(unittest.TestCase):\n    def assertIO(self, input, output):\n        stdout, stdin = sys.stdout, sys.stdin\n        sys.stdout, sys.stdin = StringIO(), StringIO(input)\n        resolve()\n        sys.stdout.seek(0)\n        out = sys.stdout.read()[:-1]\n        sys.stdout, sys.stdin = stdout, stdin\n        self.assertEqual(out, output)\n\n    def test_\u5165\u529b\u4f8b_1(self):\n        input = \"\"\"1\n10\n2\"\"\"\n        output = \"\"\"4\"\"\"\n        self.assertIO(input, output)\n\n    def test_\u5165\u529b\u4f8b_2(self):\n        input = \"\"\"2\n9\n3 6\"\"\"\n        output = \"\"\"12\"\"\"\n        self.assertIO(input, output)\n\n    def test_\u5165\u529b\u4f8b_3(self):\n        input = \"\"\"5\n20\n11 12 9 17 12\"\"\"\n        output = \"\"\"74\"\"\"\n        self.assertIO(input, output)\n\n\ndef resolve():\n    N = int(input())\n    K = int(input())\n    X = list(map(int, input().split()))\n\n    ans = 0\n    for x in X:\n        ans += min(x*2, abs(K-x)*2)\n\n    print(ans)\n\n\ndef __starting_point():\n    # unittest.main()\n    resolve()\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14372.0, "status": "done"}, {"code": "N = int(input())\nK = int(input())\nX = [int(n) for n in input().split()]\n\nans = 0\n\nfor x in X:\n    diff = abs(K - x)\n    if diff < x:\n        ans += diff\n    else:\n        ans += x\nprint((2*ans))\n", "passed": true, "time": 0.14, "memory": 14092.0, "status": "done"}, {"code": "N = int(input())\nK = int(input())\nx = list(map(int, input().split()))\n\nsum = 0\n\nfor i in range(N):\n  if x[i] >= K - x[i]:\n    sum += 2 * (K - x[i])\n  \n  else:\n    sum += 2 * x[i]\n\nprint(sum)", "passed": true, "time": 0.14, "memory": 14204.0, "status": "done"}, {"code": "# -*- coding:utf-8 -*-\nN = int(input())\nK = int(input())\nx_list = list(map(int,input().split()))\n\nsum_distance = 0\n\nfor x in x_list:\n    if x < K - x:\n        sum_distance += 2*x\n    else:\n        sum_distance += 2*(K-x)\n\nprint(sum_distance)", "passed": true, "time": 0.14, "memory": 14336.0, "status": "done"}, {"code": "N = int (input())\nK = int (input())\nx = list(map(int, input().split()))\nsum_min = 0\n\nfor p in x:\n  a = 2*p\n  b = 2*abs(K-p)\n  if a >= b:\n    sum_min += b\n  elif a < b:\n    sum_min += a\n\nprint(sum_min)", "passed": true, "time": 0.14, "memory": 14032.0, "status": "done"}, {"code": "N = int(input())\nK = int(input())\nx = list(map(int, input().split()))\n\nans = 0\nfor i in range(N):\n    ans += min(x[i]-0, K-x[i])\nprint((ans*2))\n", "passed": true, "time": 0.14, "memory": 14144.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\na = [int(x) for x in input().split()]\n\nres = 0\n\nfor i in range(n):\n  res += min(2*(abs(a[i])),2*(abs(a[i] - k)))\n\nprint(res)", "passed": true, "time": 0.14, "memory": 14064.0, "status": "done"}, {"code": "N = int(input())\nK = int(input())\n\nx = list(map(int, input().split()))\ncalc = 0\n\nfor i in range(N):\n    calc += min(x[i], abs(K-x[i])) * 2\n\nprint(calc)", "passed": true, "time": 0.14, "memory": 14144.0, "status": "done"}, {"code": "N = int(input(\"\"))\nK = int(input(\"\"))\na = input(\"\").split(\" \")\na = [int(aa) for aa in a]\nans = 0\nfor x in a:\n    if (K-x) < x:\n        ans += (K-x)*2\n    elif (K-x) >= x:\n        ans += x*2\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14208.0, "status": "done"}, {"code": "\"\"\"Boot-camp-for-Beginners_Easy009_B_Collecting-Balls-(Easy-Version)_28-August-2020.py\"\"\"\n\nN = int(input())\nK = int(input())\nx = list(map(int, input().split()))\n\ns = 0\nfor i in range(N):\n    if x[i] < K/2:\n        s += 2*x[i]\n    else:\n        s += 2*(K-x[i])\nprint(s)\n", "passed": true, "time": 0.14, "memory": 14208.0, "status": "done"}, {"code": "N = int(input())\nK = int(input())\nX = list(map(int,input().split()))\n\nans = 0\nfor x in X:\n  ans += 2 * (x if x <= K - x else K - x)\n  \nprint(ans)", "passed": true, "time": 0.15, "memory": 14052.0, "status": "done"}, {"code": "\n# ABC074\n\nN = int(input())\nK = int(input())\nX = list(map(int, input().split()))\n\nans = 0\nfor x in X:\n    ans += min(x, K-x)*2\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14256.0, "status": "done"}, {"code": "def main():\n    _ = int(input())\n    k = int(input())\n    x = list(map(int, input().split()))\n    print((sum([min([abs(xi - point) for point in [0, k]]) * 2 for xi in x])))\n\n\ndef __starting_point():\n    main()\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14184.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\nx = list(map(int, input().split()))\n\nprint(sum([min(position, abs(k - position)) * 2 for position in x]))", "passed": true, "time": 0.15, "memory": 14056.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\nx = list(map(int, input().split()))\nans = 0\nfor i in x:\n    ans += min(i, k-i)*2\nprint(ans)", "passed": true, "time": 0.32, "memory": 14264.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\n\nx = list(map(int, input().split()))\nans = 0\nfor i in x:\n  ans += 2 * min(i, k - i)\nprint(ans)", "passed": true, "time": 0.32, "memory": 14228.0, "status": "done"}, {"code": "N = int(input())\nK = int(input())\nx = list(map(int,input().split()))\nans = 0\nfor i in x:\n  if i <= K - i:\n    ans += i\n  if i > K - i:\n    ans += K - i\nprint((2 * ans))\n    \n", "passed": true, "time": 0.14, "memory": 14348.0, "status": "done"}, {"code": "N=int(input())\nK=int(input())\nx=list(map(int,input().split()))\nprint((sum(2*min(y,K-y) for y in x)))\n", "passed": true, "time": 0.19, "memory": 14040.0, "status": "done"}, {"code": "N = int(input())\nK = int(input())\nX = list(map(int, input().split()))\ncnt = 0\n\nfor x in X:\n    cnt += min(x, abs(K-x))*2\nprint(cnt)\n", "passed": true, "time": 0.16, "memory": 14300.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\nx = list(map(int, input().split()))\n\nd = 0\nfor i in x:\n    d += min(i, k-i)\nprint(2*d)", "passed": true, "time": 0.15, "memory": 14072.0, "status": "done"}, {"code": "N=int(input())\nK=int(input())\nx=list(map(int,input().split()))\ntot=0\nfor i in range(N):\n    if abs(x[i]-K)<x[i]:\n        tot+=2*(abs(x[i]-K))\n    else:\n        tot+=2*x[i]\nprint(tot)", "passed": true, "time": 0.17, "memory": 14252.0, "status": "done"}, {"code": "N = int(input())\nK = int(input())\nlst = input().split()\n\nans = 0\n\nfor i in range(N):\n   x = int(lst[i])\n   if abs(x) < abs(K - x):\n      ans += 2 * abs(x)\n   else:\n      ans += 2 * abs(K - x)\n\nprint(ans)", "passed": true, "time": 0.15, "memory": 14328.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\nx = list(map(int,input().split()))\nc= 0\nfor i in range(len(x)):\n    c+=min(x[i],k-x[i])*2\nprint(c)", "passed": true, "time": 0.15, "memory": 14252.0, "status": "done"}, {"code": "N = int(input())\nK = int(input())\nx = [int(x) for x in input().split()]\nans = 0\nfor i in range(N):\n  ans += 2 * min(abs(x[i]-0), abs(x[i]-K))\nprint(ans)", "passed": true, "time": 0.16, "memory": 14304.0, "status": "done"}, {"code": "N = int(input())\nK = int(input())\nx = list(map(int,input().split()))\nans = 0\n\nfor i in range(N):\n  ans += min(abs(x[i] - 0), abs(K - x[i]))\nprint(ans * 2)", "passed": true, "time": 0.14, "memory": 14108.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\n\ns = 0\nxs = list(map(int, input().split()))\nfor x in xs:  \n  if x < abs(k-x):\n    s += 2 * x\n  else:\n    s += 2 * abs(k-x)\n    \nprint(s)\n", "passed": true, "time": 0.21, "memory": 14216.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\nv = list(map(int, input().split()))\n\nans = 0\nfor i in v:\n    tmp = min(i, k-i)\n    ans += tmp\nprint((ans*2))\n", "passed": true, "time": 0.14, "memory": 14296.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\nl = list(map(int, input().split()))\nc = 0\nfor x in l:\n  c += min(x,k-x)\nprint(2*c)", "passed": true, "time": 0.14, "memory": 14104.0, "status": "done"}, {"code": "n=int(input())\nk=int(input())\nx=list(map(int,input().split()))\n\nans=0\nfor i in range(n):\n  ans+=min(abs(x[i]-0), abs(x[i]-k))\nprint(ans*2)", "passed": true, "time": 0.14, "memory": 14272.0, "status": "done"}, {"code": "#!/usr/bin/env python3\nimport sys\n\n\ndef solve(N: int, K: int, x: \"List[int]\"):\n    res = 0\n    for x_ in x:\n        res += 2*min(x_, abs(K-x_))\n    print(res)\n    return\n\n\n# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)\ndef main():\n    def iterate_tokens():\n        for line in sys.stdin:\n            for word in line.split():\n                yield word\n    tokens = iterate_tokens()\n    N = int(next(tokens))  # type: int\n    K = int(next(tokens))  # type: int\n    x = [int(next(tokens)) for _ in range(N)]  # type: \"List[int]\"\n    solve(N, K, x)\n\ndef __starting_point():\n    main()\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14056.0, "status": "done"}, {"code": "N = int(input())\nK = int(input())\nX = list(map(int, input().split()))\nans = 0\nfor x in X:\n    ans += min(x, abs(K-x))*2\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14232.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\nx = list(map(int,input().split()))\ncount = 0\nfor i in range(n):\n    count += min(x[i], k-x[i])\nprint(count * 2)", "passed": true, "time": 0.16, "memory": 14276.0, "status": "done"}, {"code": "_,k=input(),int(input());print(sum(min(i,(k-i))*2 for i in list(map(int,input().split()))))", "passed": true, "time": 0.14, "memory": 14248.0, "status": "done"}, {"code": "N = int(input())\nK = int(input())\nx = [int(c) for c in input().split() ]\n\ncnt = 0\nfor i in range(N):\n    a = 0\n    b = 0\n    a = abs(x[i]-0)*2\n    b = abs(x[i]-K)*2\n    if a <= b:\n        cnt += a\n    else:\n        cnt += b\n\nprint(cnt)", "passed": true, "time": 0.14, "memory": 14228.0, "status": "done"}, {"code": "N = int(input())\nK = int(input())\nA = list(map(int, input().split()))\n\nans = 0\nfor a in A:\n  ans += 2*min(a, K-a)\nprint(ans)", "passed": true, "time": 0.14, "memory": 14124.0, "status": "done"}, {"code": "N = int(input())\nK = int(input())\nx = [int(i) for i in input().split()]\nans = 0\nfor i in range(N) :\n    xi = x[i]\n    if xi <= (K//2) :\n        ans += 2*xi\n    else :\n        ans += 2*(K-xi)\nprint(ans)", "passed": true, "time": 0.14, "memory": 14064.0, "status": "done"}, {"code": "_,k=input(),int(input());print(sum([min(i,(k-i))*2 for i in list(map(int,input().split()))]))", "passed": true, "time": 0.15, "memory": 14228.0, "status": "done"}, {"code": "N = int(input())\nK = int(input())\nx = list(map(int, input().split()))\n\nans = 0\n\nfor x in x:\n    a = 2 * x\n    b = abs(K - x) * 2\n    ans += min(a, b)\n\nprint(ans)\n", "passed": true, "time": 0.26, "memory": 14320.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\nnums = list(map(int, input().split()))\nprint(2 * sum([min(k - i, i) for i in nums]))", "passed": true, "time": 0.23, "memory": 14280.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\nx = list(map(int, input().split()))\nans = 0\nfor i in range(n):\n    if x[i] >= k - x[i]:\n        ans += 2*(k - x[i])\n    else:\n        ans += 2*x[i]\nprint(ans)", "passed": true, "time": 0.63, "memory": 14344.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\nx_list = list(map(int, input().split()))\nans = 0\nfor i in x_list:\n    if 2*i < k:\n        ans += 2*i\n    else :\n        ans += (k-i)*2\nprint(ans)\n", "passed": true, "time": 0.25, "memory": 14304.0, "status": "done"}, {"code": "N = int(input())\nK = int(input())\nx = list(map(int,input().split()))\ntotal = 0\nfor i in range (N):\n  if x[i]<K/2:\n    total += 2*x[i]\n  elif x[i]>= K/2:\n    total += 2*(K-x[i])\nprint(total)", "passed": true, "time": 0.29, "memory": 14112.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\nx = list(map(int, input().split()))\na = 0\nfor i in x:\n    if 2 * i < 2 * (k - i):\n        a += 2 * i\n    else:\n        a += 2 * (k - i)\nprint(a)", "passed": true, "time": 0.18, "memory": 14292.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\nx = list(map(int, input().split()))\nd = 0\nfor i in x:\n    y = min(i, abs(k-i))\n    d += 2*y\nprint(d)", "passed": true, "time": 0.18, "memory": 14232.0, "status": "done"}, {"code": "N = int(input())\nK = int(input())\nxs = list(map(int, input().split()))\n\ndist_sum = 0\nfor i in range(N):\n\ty = i + 1\n\tx = xs[i]\n\t\n\tif x > K - x:\n\t\tdist_sum += (K - x) * 2\n\telse:\n\t\tdist_sum += x * 2\n\t\t\nprint(dist_sum)\n\t\n", "passed": true, "time": 0.18, "memory": 14112.0, "status": "done"}, {"code": "N = int(input())\nK = int(input())\nX = list(map(int, input().split()))\nY = [i for i in range(1, N+1)]\nans = 0\n\nfor x in X:\n    distance_a = x\n    distance_b = abs(K-x)\n    if distance_a < distance_b:\n        ans += distance_a\n    else:\n        ans += distance_b\n    \nprint(ans*2)", "passed": true, "time": 0.26, "memory": 14108.0, "status": "done"}, {"code": "N = int(input())\nK = int(input())\nX = list([int(x) for x in input().split()])\n\nresult = 0\n\nfor pos in X:\n    if pos <= abs(pos - K):\n        result += 2 * pos\n    else:\n        result += 2 * abs(pos - K)\n\nprint(result)\n", "passed": true, "time": 0.14, "memory": 14172.0, "status": "done"}, {"code": "#-*-coding:utf-8-*-\nimport sys\ninput=sys.stdin.readline\n\ndef main():\n    data=[]\n    n = int(input())\n    k = int(input())\n    data=list(map(int,input().split()))\n    length=0\n\n    for ball in data:\n        if ball < k-ball:\n            length+=2*ball\n        else:\n            length+=2*(k-ball)\n    print(length)\n\ndef __starting_point():\n    main()\n__starting_point()", "passed": true, "time": 0.22, "memory": 14176.0, "status": "done"}, {"code": "n=int(input())\nk=int(input())\nx=list(map(int,input().split()))\nans=0\nfor  i in range(n):\n  m=min(abs(x[i]),abs(k-x[i]))\n  ans+=m\n\nprint(ans*2)", "passed": true, "time": 0.14, "memory": 14260.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\nx = list(map(int,input().split()))\nans = 0\nfor i in range(n):\n  ans += 2*min(abs(x[i]-k),abs(x[i]))\nprint(ans)", "passed": true, "time": 0.14, "memory": 14364.0, "status": "done"}, {"code": "N = int(input())\nK = int(input())\ndist = 0\nfor val in list(map(int,input().split())):\n  dist += 2*min(val,abs(val-K))\n  \nprint(dist)", "passed": true, "time": 0.14, "memory": 14128.0, "status": "done"}, {"code": "N=int(input())\nK=int(input())\nX=list(map(int,input().split()))\n\nans=0\n\nfor i in X:\n    Y=[]\n    Y.append(2*abs(i))\n    Y.append(2*abs(i-K))\n    ans+=min(Y)\n    \nprint(ans)", "passed": true, "time": 0.14, "memory": 14052.0, "status": "done"}, {"code": "n,k=int(input()),int(input());x=list(map(int,input().split()))\nprint(sum([min(i,j) for i,j in zip([abs(i*2) for i in x],[abs((i-k)*2) for i in x])]))", "passed": true, "time": 0.14, "memory": 14204.0, "status": "done"}, {"code": "n=int(input())\nk=int(input())\nl=list(map(int,input().split()))\n\nans=0\nfor i in l:\n  if i>=k/2:\n    ans+=abs(k-i)*2\n  else:\n    ans+=i*2\n\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14260.0, "status": "done"}, {"code": "N = int(input())\nK = int(input())\nX = [int(x) for x in input().split()]\n\nans = 0\nfor x in X:\n    ans += min(x, abs(x-K))\nans *= 2\nprint(ans)", "passed": true, "time": 0.15, "memory": 14260.0, "status": "done"}, {"code": "n=int(input())\nk=int(input())\nx=list(map(int,input().split()))\nans=0\nfor xi in x:\n    ans+=2*min(xi,k-xi)\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14188.0, "status": "done"}, {"code": "from typing import List\n\n\ndef answer(n: int, k: int, xs: List[int]) -> int:\n    moving_distance = 0\n    reference_value = k / 2\n    for x in xs:\n        if x <= reference_value:\n            moving_distance += x * 2\n        else:\n            moving_distance += (k - x) * 2\n\n    return moving_distance\n\n\ndef main():\n    n = int(input())\n    k = int(input())\n    xs = list(map(int, input().split()))\n    print(answer(n, k, xs))\n\n\ndef __starting_point():\n    main()\n__starting_point()", "passed": true, "time": 0.15, "memory": 15352.0, "status": "done"}]