A concert hall has n loudspeakers set out in a single row, wired into n/2 mirrored pairs: the speaker at position i (0-indexed from the left) is paired with the speaker at position n-1-i. Every speaker currently outputs an integer volume level between 0 and k inclusive. For an upcoming symmetric sound effect, the engineer wants to choose one single integer gap value d, with 0 <= d <= k, and then recalibrate as few speakers as possible — recalibrating a speaker means setting its level to any integer in [0,k], and each speaker touched counts as one recalibration — so that afterwards every mirrored pair's two levels differ by exactly d. The engineer is completely free to pick d; different choices of d may require recalibrating different numbers of speakers. Find the minimum total number of speakers that need to be recalibrated, over every possible choice of d.
The first line contains two integers n and k, where n is guaranteed to be even. The second line contains n integers level[0], level[1], ..., level[n-1] — the current volume level of each speaker.
Print a single integer: the minimum total number of speakers that must be recalibrated, over all choices of the shared gap d.
Example 1
Input
4 5 0 5 3 4
Expected
1
Explanation
The two mirrored pairs are (level[0], level[3]) = (0, 4) and (level[1], level[2]) = (5, 3). Choosing d = 2: the second pair already differs by exactly 2, so it needs no change, and the first pair (0, 4) can be fixed with a single recalibration by changing the 0 to a 2 (giving levels 2 and 4, which differ by 2, and 2 is a valid level since 0 <= 2 <= 5). No choice of d lets both pairs need zero changes, so 1 recalibration is the minimum.
Example 2
Input
2 3 1 3
Expected
0
Explanation
With only a single mirrored pair, the engineer can always pick d equal to that pair's current gap — here |1-3| = 2 — so zero speakers ever need to be recalibrated.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →