P17549 [JAG 2026 Summer Camp #2] Warp

Description

There is a circle with circumference $L$, where $L$ is an even integer. Positions on the circle are measured counterclockwise and represented by real numbers in the range $[0,L)$. There are $N$ points on this circle. The $i$-th point is located at position $A_i$. The positions are not necessarily distinct. Initially, you can choose any position on the circle as your starting position. After that, you can move along the circle either clockwise or counterclockwise at a speed of $1$ unit per second. You can change your direction at any time, without consuming any time. Furthermore, you can use a magic warp at any time, as many times as you like. A magic warp takes no time and moves you to the exact opposite of your current position on the circle. More precisely, if you are at position $x$ ($0\le x

Input Format

The input consists of a single test case of the following format. ```text N L A_1 A_2 ... A_N ``` The integer $N$ represents the number of points on the circle ($1\le N\le 2\times 10^5$). The even integer $L$ represents the circumference of the circle ($2\le L\le 10^9$). Each integer $A_i$ satisfies $0\le A_i

Output Format

Output the minimum time required to visit all $N$ points. It can be proved that the answer is an integer.

Explanation/Hint

In Sample Input 1, it is possible to visit all $4$ points in $3$ seconds as follows. - First, you start at position $2$, visiting the second point. - Move to position $3$, taking $1$ second. - Use a magic warp and move to position $8$, taking $0$ seconds. You also visit the third point. - Move to position $9$, taking $1$ second. You also visit the fourth point. - Move to position $0$, taking $1$ second. You also visit the first point.