100 #ABC074B. [ABC074B] Collecting Balls (Easy Version)

[ABC074B] Collecting Balls (Easy Version)

Score : 200200 points

Problem Statement

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

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

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

  • When a type-A robot is activated at coordinates (0,a)(0, a), it will move to the position of the ball on the line y=ay = a, collect the ball, move back to its original position (0,a)(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)(K, b), it will move to the position of the ball on the line y=by = b, collect the ball, move back to its original position (K,b)(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 2N2N robots to collect all of the balls. Find the minimum possible total distance covered by robots.

Constraints

  • 1N1001 \leq N \leq 100
  • 1K1001 \leq K \leq 100
  • 0<xi<K0 < x_i < K
  • All input values are integers.

Inputs

Input is given from Standard Input in the following format:

NN

KK

x1x_1 x2x_2 ...... xNx_N

Outputs

Print the minimum possible total distance covered by robots.

1
10
2
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 22, and the distance from the ball to the original position of the robot is also 22, for a total distance of 44.

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

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

2
9
3 6
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.

5
20
11 12 9 17 12
74