292 传统题

[ABC450D] 同余最小极差 (Minimize Range)

时间限制
2000ms
内存限制
256MiB
登顶 / 尝试
0/ 0
难度
3

[ABC450D] 同余最小极差 (Minimize Range)

Problem Statement

You are given a sequence AA of NN positive integers and a positive integer KK.

You can perform the following operation on the sequence AA any number of times.

  • Choose an integer ii with 1≤i≤N1 \leq i \leq N, and add KK to AiA_i.

Find the minimum possible value of max⁡(A)−min⁡(A)\max(A) - \min(A).

Input

The input is given from Standard Input in the following format:

$N$ $K$
$A_1$ $A_2$ $\dots$ $A_N$

Output

Output the answer on a single line.

Example

3 10
3 21 9
4

Note

  • Constraints:

  • 1≤N≤2×1051 \leq N \leq 2 \times 10^5

  • 1≤K≤1091 \leq K \leq 10^9

  • 1≤Ai≤1091 \leq A_i \leq 10^9

  • All input values are integers.

  • Source: ABC450D