#d1506. 体育节

体育节

Sports Festival

Problem Description

The student union is preparing for the relay race of the sports festival. The student union consists of nn members who will run one by one in the race. The ii-th person has speed sis_i. The ii-th leg of the relay produces a difference value did_i, which equals the difference between the maximum and minimum speeds among the first ii participants — that is, if we denote the speed of the ii-th participant as aia_i, then $d_i = \max(a_1, a_2, \dots, a_i) - \min(a_1, a_2, \dots, a_i)$.

You may arrange the running order of the participants arbitrarily. Each person participates exactly once and everyone must participate. Find the minimum possible value of d1+d2+⋯+dnd_1 + d_2 + \dots + d_n.

Input Format

The first line contains a positive integer nn. The second line contains nn integers representing aia_i.

Output Format

Output one integer, the answer.

Sample Input

3
3 1 2

Sample Output

3

Constraints

1≤n≤20001 \le n \le 2000,

1≤si≤1091 \le s_i \le 10^9