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.



import java.util.*;
import java.io.*;
import java.math.BigInteger;

 public class Main {
    static int[] MODS = {1000000007, 998244353, 1000000009};
    static int MOD = MODS[0];

    public static void main(String[] args) {
        sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
//        int t = sc.nextInt();
//        	while(t-- >0) {
//        		
//        	}
        int n=sc.nextInt();
        int[] a=sc.nextArray(n);
        dp=new Long[n+1][n+1];
        Arrays.sort(a);
        System.out.println(minDisc(a, 0, n-1));
      
        out.close();
    }

    
    
    static Long[][] dp;
	static Long minDisc(int[] a,int l,int r) {
		 if(l>=a.length || r<0) return 0L;
		 if(l==r) return 0L;
		 if(dp[l][r]!=null) return dp[l][r];
		 
		 Long c1=minDisc(a, l+1, r);
		 Long c2=minDisc(a, l, r-1);
		 Long c=a[r]-a[l] + Math.min(c1, c2);
		 return dp[l][r]=c;
	 }








	/*-----------------------------*/
    public static int[] sort(int[] arr) {
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 0; i < arr.length; i++) {
            list.add(arr[i]);
        }
        Collections.sort(list);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = list.get(i);
        }
        return arr;
    }
    
    int sqDecom(int[] a,int l,int r) {
		int n=a.length;
		int len=(int)Math.ceil(Math.sqrt(n));
		int[] b=new int[len];
		for(int i=0;i<a.length;i++) {
			b[i/len]+=a[i];
		}
		
		int sum=0;
		int cl=l/len,cr=r/len;
		if(cl==cr) {
			for(int i=l;i<=r;i++) sum+=a[i];
		}else {
			for(int i=l;i<=(cl+1)*len-1;i++) {
				sum+=a[i];
			}
			for(int i=cl+1;i<=cr-1;i++) {
				sum+=b[i];
			}
			for(int i=cr*len;i<=r;i++) {
				sum+=a[i];
			}
		}
		return sum;
		
		
	}
    
    BigInteger gcd(BigInteger a,BigInteger b) {
		if(a.equals(new BigInteger("0")))return b;
		if(b.equals(new BigInteger("0")))return a;
		
		if(a.mod(new BigInteger("2")).equals(new BigInteger("0"))&&b.mod(new BigInteger("2")).equals(new BigInteger("0")))return gcd(a.divide(new BigInteger("2")),b.divide(new BigInteger("2"))).multiply(new BigInteger("2"));
		else if(a.mod(new BigInteger("2")).equals(new BigInteger("0"))&&b.mod(new BigInteger("2")).equals(new BigInteger("1")))return gcd(a.divide(new BigInteger("2")),b);
		else if(a.mod(new BigInteger("2")).equals(new BigInteger("1"))&&b.mod(new BigInteger("2")).equals(new BigInteger("0")))return gcd(a,b.divide(new BigInteger("2")));
		return gcd(b,b.subtract(a).abs());
		
	}

    public static void scan(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            arr[i] = sc.nextInt();
        }
    }

    public static MyScanner sc;
    public static PrintWriter out;

    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = sc.nextInt();
			}
			return a;
		}
     			
       long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++) {
				a[i] = sc.nextLong();
			}
			return a;
		}
        
        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

