Christmas Eve#365

Christmas Eve

1 seconde
256 mégaoctets
Medium

Christmas is coming, and Sakurako will celebrate it with her close-knit friends. To make it more fascinating, they plan to hold a gift exchange on Christmas Eve.

Sakurako knows that it will take place at a round table, and this gift exchange will be super simple: everyone will give their present to the person sitting to their right. Everyone has already decided where they will sit, except for Sakurako.

She also knows the price of each friend's gift; the -th friend's gift costs a_i coins. Of course, after the exchange, someone might be disappointed if they receive a cheaper gift than the one they gave. Intuitively, their disappointment is described as the absolute difference between the cost of the gift they gave and the gift they received. The value Sakurako is interested in is the total disappointment.

More formally, if b_1, b_2, \dots, b_{n} are the costs of the friends' gifts respectively, then the total disappointment is calculated as:

|b_1 - b_2| + |b_2 - b_3| + \dots + |b_{n-1} - b_n| + |b_n - b_1|.

Sakurako, on her end, bought a gift for coins. Since she hasn't decided where to sit yet, you can give her a hint. Tell her what the minimal total disappointment might be if Sakurako chooses her position optimally, as she wants the Christmas Eve mood to be as cheerful as possible. With your hint, she will be able to find the optimal position by herself.

For example, if Sakurako has friends where the -th friend has bought a present for coins and Sakurako's present costs coins, then one of the possible places where Sakurako may sit is illustrated below:

Here, Sakurako sits between the first and the fifth friend. Hence, the total disappointment is |1-2|+|2-3|+|3-4|+|4-5|+|5-6|+|6-1|=10.

Input

The first line contains two integers and (1\le n\le 2\cdot 10^5; 0\le x\le 10^9) — the number of friends and the cost of Sakurako's present.

The second line contains positive integers a_1,a_2,\dots, a_n ~(0\le a_i\le 10^9) — the costs of the friends' presents.

Output

Output one integer — the minimal total disappointment after Sakurako takes her place.

Examples

Example 1

Loading
Loading

Scoring

In this problem, there are conditional blocks. If your solution works correctly for certain constraints, it will receive a certain number of points. Note that testing is going test by test, but not by blocks.

  1. ( points): n\le 10^3;

  2. ( points): without additional constraints.