The student council is preparing for the relay race at the sports festival.

The council consists of n members. They will run one after the other in the race, the speed of member i is s_i. The discrepancy d_i of the i-th stage is the difference between the maximum and the minimum running speed among the first i members who ran. Formally, if a_i denotes the speed of the i-th member who participated in the race, then d_i = max(a_1, a_2, ..., a_i) - min(a_1, a_2, ..., a_i).

You want to minimize the sum of the discrepancies d_1 + d_2 + ... + d_n. To do this, you are allowed to change the order in which the members run. What is the minimum possible sum that can be achieved?

Input

The first line contains a single integer n (1 ≤ n ≤ 2000) — the number of members of the student council.

The second line contains n integers s_1, s_2, ..., s_n (1 ≤ s_i ≤ 10^9) – the running speeds of the members.

Output

Print a single integer — the minimum possible value of d_1 + d_2 + ... + d_n after choosing the order of the members.

Examples

Input


3
3 1 2


Output


3


Input


1
5


Output


0


Input


6
1 6 3 3 6 3


Output


11


Input


6
104 943872923 6589 889921234 1000000000 69


Output


2833800505

Note

In the first test case, we may choose to make the third member run first, followed by the first member, and finally the second. Thus a_1 = 2, a_2 = 3, and a_3 = 1. We have:

  * d_1 = max(2) - min(2) = 2 - 2 = 0. 
  * d_2 = max(2, 3) - min(2, 3) = 3 - 2 = 1. 
  * d_3 = max(2, 3, 1) - min(2, 3, 1) = 3 - 1 = 2. 



The resulting sum is d_1 + d_2 + d_3 = 0 + 1 + 2 = 3. It can be shown that it is impossible to achieve a smaller value.

In the second test case, the only possible rearrangement gives d_1 = 0, so the minimum possible result is 0.
#include<cmath>
#include<iostream>
#include<cstdio>
#include<array>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<cstring>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<deque>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<string>
#include<sstream>
#include<climits>
#include<chrono>
#include<random>
#include<unordered_set>
#include<unordered_map> 
#include<ctype.h>
#include<cassert>
#include<numeric>
#include<functional>
using namespace std;
typedef long long ll; typedef unsigned long long ull; typedef long double ldb; typedef double db;
typedef pair<ll, ll> pll; typedef pair<int, int> pii; typedef pair<ll, int> pli;
#define all(a) (a).begin(),(a).end()
#define Timepreliminary clock_t clock_start_time = clock()
#define TimeDisplay cout << "Time: " << clock() - clock_start_time << "ms\n"
#define Debug cout<<"\nRight Here\n";
template <class output_type, class input_type>
output_type Convert(const input_type& input) {
	stringstream ss; output_type result;
	ss.clear(); ss << input; ss >> result;
	return result;
}
const double Pi = acos(-1.0); constexpr int inf = 1 << 29, Mod = 1e9 + 7, N = 1e5 + 3; constexpr ll INF = 1ll << 60;
ll qpow(ll a, ll b, ll mod = Mod, ll ans = 1) {
	for (; b; b >>= 1, a = (a * a + mod) % mod)if (b & 1)ans = (ans * a + mod) % mod;
	return ans;
}
ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); }; ll lcm(ll a, ll b) { return a * b / (gcd(a, b)); }
pii EXgcd(int x, int y) {        //return.first ny
	if (!y) { return { 1,0 }; }pii a = EXgcd(y, (x + y) % y);
	return { a.second, a.first - a.second * (x / y) };
}
inline bool Ezisprime(const int n) {
	if (n <= 1)return 0; if (n <= 3)return 1;
	vector<int> ezp{ 5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97 };
	for (int i = 0; i < ezp.size(); i++)if (n == ezp[i])return 1;
	for (int i = 2; i <= sqrt(n); i++)if (n % i == 0)return 0;
	return 1;
}
inline int LIS(const vector<int>& Origins, const int& n) {
	if (!n || !Origins.size()) return 0;
	int len = 0; vector<int> d(n, 0); d[0] = Origins[0];
	for (int i = 1; i < n; i++)
		if (Origins[i] >= d[len])d[++len] = Origins[i];
		else d[upper_bound(d.begin(), d.begin() + len, Origins[i]) - d.begin()] = Origins[i];
	return len + 1;
}
inline int LCSseq(const string& s1, const string& s2) {
	vector<vector<int>>dp(s1.size() + 1, vector<int>(s2.size() + 1, 0));
	for (int i = 1; i <= s1.size(); ++i)
		for (int j = 1; j <= s2.size(); ++j)
			if (s1[i - 1] == s2[j - 1])dp[i][j] = dp[i - 1][j - 1] + 1;
			else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
	return dp[s1.size()][s2.size()];
}
inline int LCSstr(const string& s1, const string& s2) {
	vector<vector<int>>dp(s1.size() + 1, vector<int>(s2.size() + 1, 0)); int res = 0;
	for (int i = 1; i <= s1.size(); ++i)
		for (int j = 1; j <= s2.size(); ++j)
			if (s1[i - 1] == s2[j - 1])
				dp[i][j] = dp[i - 1][j - 1] + 1, res = max(res, dp[i - 1][j - 1] + 1);
			else dp[i][j] = 0;
	return res;
}
pll Fib(ll n) {
	if (n == 0) return { 0, 1 };
	auto p = Fib(n >> 1);
	ll c = p.first * ((p.second) << 1 - p.first), d = p.first * p.first + p.second * p.second;
	if (n & 1)return { d, c + d }; else return { c, d };
}
inline vector<ll>& EuSieve(const ll& n) {
	vector<ll> prime; vector<bool>is_prime(n + 1, 1);
	for (ll i = 2; i <= n; ++i) {
		if (is_prime[i])prime.emplace_back(i);
		for (auto& p : prime) {
			if (i * p > n)break;
			is_prime[i * p] = 0;
			if (i % p == 0)break;
		}
	}
	return prime;
}
inline ll& Digsum(ll n, ll ans = 0) {
	for (; n; n /= 10)ans += n % 10;
	return ans;
}
inline void modize(ll& n,const ll& add, const ll& mod = Mod) { n = ((n+add) % mod + mod) % mod; }
inline int Alptonum(const char& a) { if (a <= 'z')return int(a - 'a'); else return int(a - 'A'); }
inline char Numtoalp(const int& n, const bool t) { if (!t)return char('a' + n); else return char('A' + n); }
inline bool cmp(const pii a, const pii b) {  //default more and more larger 
	return a.second < b.second;
}
struct cmpstl {           //reverse
	inline bool operator()(const pll& a, const pll& b) {
		if (a.first == b.first)return a.second > b.second;
		return a.first > b.first;
	}
};
//partial_sum(begin,end,place,minus<int>()) adjacent_differece(begin,end,place) 
//count(begin(),end(),char=='x') count_if(begin(),end(),boolcmp) vector<int> p(n);iota(p.begin(), p.end(), 0);

//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Code follows ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\\
//VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV Code follows VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVII
ll dp[2001][2001]; vector<ll>a;
ll dfs(const int& l,const int& r)
{
	if (dp[l][r] >= 0)return dp[l][r];
	if (l == r)return 0ll;
	return dp[l][r] = a[r] - a[l] + min(dfs(l+1,r), dfs(l,r-1));
}
int main()
{
	ios::sync_with_stdio(0); cin.tie(0), cout.tie(0);
	
	int n; cin >> n;
	a.resize(n);
	memset(dp, -1, sizeof dp);
	for (auto& i : a)cin >> i;
	sort(all(a));
	cout << dfs(0, n - 1) << '\n';
	

}
/*
10
9
TTTTTMMMT

*/