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.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;


public class Main {
    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());
        }

        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;
        }

    }
    static class TreeMultiSet<T> implements Iterable<T>
    {
        private final TreeMap<T,Integer> map;
        private int size;

        public TreeMultiSet(){map=new TreeMap<>(); size=0;}
        public TreeMultiSet(boolean reverse)
        {
            if(reverse) map=new TreeMap<>(Collections.reverseOrder());
            else map=new TreeMap<>(); size=0;
        }
        public void clear(){map.clear(); size=0;}
        public int size(){return size;}
        public int setSize(){return map.size();}
        public boolean contains(T a){return map.containsKey(a);}
        public boolean isEmpty(){return size==0;}
        public Integer get(T a){return map.getOrDefault(a,0);}
        public void add(T a, int count)
        {
            int cur=get(a);map.put(a,cur+count); size+=count;
            if(cur+count==0) map.remove(a);
        }
        public void addOne(T a){add(a,1);}
        public void remove(T a, int count){add(a,Math.max(-get(a),-count));}
        public void removeOne(T a){remove(a,1);}
        public void removeAll(T a){remove(a,Integer.MAX_VALUE-10);}

        public T ceiling(T a){return map.ceilingKey(a);}
        public T floor(T a){return map.floorKey(a);}
        public T first(){return map.firstKey();}
        public T last(){return map.lastKey();}
        public T higher(T a){return map.higherKey(a);}
        public T lower(T a){return map.lowerKey(a);}
        public T pollFirst(){T a=first(); removeOne(a); return a;}
        public T pollLast(){T a=last(); removeOne(a); return a;}

        public Iterator<T> iterator()
        {
            return new Iterator<>()
            {
                private final Iterator<T> iter = map.keySet().iterator();
                private int count = 0; private T curElement;

                public boolean hasNext(){return iter.hasNext()||count>0;}
                public T next()
                {
                    if(count==0)
                    {
                        curElement=iter.next();
                        count=get(curElement);
                    }
                    count--; return curElement;
                }
            };
        }
    }
    static int arr[];
    static long vis[][] = new long[2000][2000];
    public static long dp(int i, int j){
        if(vis[i][j] != -1) return vis[i][j];
        if(i == j){
            long diff = arr[j] - arr[i];
            vis[i][j] = diff;
            return diff;
        }
        long diff1 =  arr[j] - arr[i];
        long op1 = dp(i+1,j) + diff1;
        long op2 = dp(i,j-1) + diff1;
        vis[i][j] = Math.min(op1,op2);
        return vis[i][j];
    }
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        int t = 1;
        while (t-- != 0) {
           int n = sc.nextInt();
           arr = new int[n];
           for(int i=0;i<n;i++){
               arr[i] = sc.nextInt();
           }
           Arrays.sort(arr);
           for(int i=0;i<n;i++){
               for(int j=0;j<n;j++){
                   vis[i][j] = -1;
               }
           }
           System.out.println(dp(0,n-1));

        }
    }
}
