Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks:

  * Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. 
  * Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. 



After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?

Input

The first line contains a single integer n (1 ≤ n ≤ 3·105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the initial group that is given to Toastman.

Output

Print a single integer — the largest possible score.

Examples

Input

3
3 1 5


Output

26


Input

1
10


Output

10

Note

Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
import java.util.*;
import java.math.*;
import java.io.*; 
 public class B{
static int[] dx={-1,1,0,0};
static int[] dy={0,0,1,-1};
    static FastReader scan=new FastReader();
   public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
  static ArrayList<Pair>es;
  static LinkedList<Pair>edges[][];
   static boolean prime[];
   static void sieve(int n) 
    { 
        
        prime = new boolean[n+1]; 
        for(int i=0;i<n;i++) 
            prime[i] = true; 
          
        for(int p = 2; p*p <=n; p++) 
        { 
           
            if(prime[p] == true) 
            { 
                
                for(int i = p*p; i <= n; i += p) 
                    prime[i] = false; 
            } 
        } 
          
        
    }  
  
 public static boolean areSame(int []arr)
    {
        // Put all array elements in a HashSet
        Set<Integer>s=new HashSet<Integer>();
        for(int i=0;i<arr.length;i++)
            s.add(arr[i]);

 
        // If all elements are same, size of
        // HashSet should be 1. As HashSet contains only distinct values.
        return (s.size() == 1);
    }
   

    
     public static int lowerBound(long[] array, int length, long value) {
        int low = 0;
        int high = length;
        while (low < high) {
            final int mid = (low + high) / 2;
            //checks if the value is less than middle element of the array
            if (value <= array[mid]) {
                high = mid;
            } else {
                low = mid + 1;
            }
        }
        return low;
    }
    public static int upperBound(long[] array, int length, long value) {
        int low = 0;
        int high = length;
        while (low < high) {
            final int mid = low+(high-low) / 2;
            if ( array[mid]>value) {
                high = mid ;
            } else {
                low = mid+1;
            }
        }
        return low;
    }
static long mod(long x,long y)
    {
        if(x<0)
            x=x+(-x/y+1)*y;
        return x%y;
    }
    
    
    static boolean isPowerOfTwo(int n)
{
    if(n==0)
    return false;
 
return (int)(Math.ceil((Math.log(n) / Math.log(2)))) == 
       (int)(Math.floor(((Math.log(n) / Math.log(2)))));
}
static int CeilIndex(int A[], int l, int r, int key) 
    { 
        while (r - l > 1) { 
            int m = l + (r - l) / 2; 
            if (A[m] >= key) 
                r = m; 
            else
                l = m; 
        } 
  
        return r; 
    } 
  
    static int LongestIncreasingSubsequenceLength(int A[], int size) 
    { 
        // Add boundary case, when array size is one 
  
        int[] tailTable = new int[size]; 
        int len; // always points empty slot 
  
        tailTable[0] = A[0]; 
        len = 1; 
        for (int i = 1; i < size; i++) { 
            if (A[i] < tailTable[0]) 
                // new smallest value 
                tailTable[0] = A[i]; 
  
            else if (A[i] >= tailTable[len - 1]) 
                // A[i] wants to extend largest subsequence 
                tailTable[len++] = A[i]; 
  
            else
                // A[i] wants to be current end candidate of an existing 
                // subsequence. It will replace ceil value in tailTable 
                tailTable[CeilIndex(tailTable, -1, len - 1, A[i])] = A[i]; 
        } 
  
        return len; 
    } 
static boolean isprime(long x)
           {
            for(long i=2;i*i<=x;i++)
                if(x%i==0)
                    return false;
                return true;
           }
           static long arr[];
      
        static int k;

 static boolean can(long x)
 {
    int bl=0;
    int i=0;
    for(int kas=0;i<n&&kas<k;kas++)
    {
        long hasta=arr[i];
        hasta+=x*2;
        while(i<n-1&&arr[i+1]<=hasta)i++;
        i++;
        
    }
return (i>=n);
 }
static int n,m;
static boolean vis[][];
static boolean light[][];
static boolean e(int x,int y)
{
    return (x>=0&&x<n&&y>=0&&y<n);
}
static int ans=0;
static void dfs(int x,int y)
{
    if(vis[x][y])
        return;
    vis[x][y]=true;
   //light[x][y]=true;
    for(Pair p:edges[x][y])
    {
        if(!light[p.x][p.y]){
            light[p.y][p.y]=true;
            ans++;
            dfs(p.x,p.y);
                    }
    }
    for(int i=0;i<4;i++){
    int nx=x+dx[i],ny=y+dy[i];
    if(e(nx,ny))
        dfs(nx,ny);
}

}
static int dist(int x1,int y1,int x2,int y2){
return Math.abs(x1-x2)+Math.abs(y1-y2);
}
static int x;
static int min(int y,int k)
{
    if(y==x)
        return 0;
    return Math.min(min(y+k,k++)+1,min(y-1,k)+1);
}
static boolean is(int arr[])
{
    for(int i=1;i<arr.length;i++)
        if(arr[i]<arr[i-1])
            return false;
        return true;
}
  static void reverse(int myArray[]) 
    { 
        Collections.reverse(Arrays.asList(myArray)); 
    } 
    static boolean isPerfect(long n) 
{ 
    // To store sum of divisors 
    long sum = 1; 
  
    // Find all divisors and add them 
    for (long i = 2; i * i <= n; i++) 
    { 
        if (n % i==0) 
        { 
            if(i * i != n) 
                sum = sum + i + n / i; 
            else
                sum = sum + i; 
        } 
    }  
    // If sum of divisors is equal to 
    // n, then n is a perfect number 
    if (sum == n && n != 1) 
        return true; 
  
    return false; 
} 
static char []a,b,c;
static char chose(int i)
{
char ch='a';
while(ch==a[i]||ch==b[i])
ch++;
return ch;
}
static int v1,v2,t,d;
static boolean can(int k,int l)
{
while(l>0)
{
    k-=d;
    l--;
}
if(k<=v2)
    return true;
else 
    return false;
}
 
    static long cuberoot(long x)
    {
        long lo = 0, hi = 1000005;
        while(lo<hi)
        {
            long m = (lo+hi+1)/2;
            if(m*m*m>x)
                hi = m-1;
            else
                lo = m;
        }
        return lo;
    }
     public static int log2(int N) 
    { 
  
        // calculate log2 N indirectly 
        // using log() method 
        int result = (int)(Math.log(N) / Math.log(2)); 
  
        return result; 
    } 
public static void main(String[] args)  throws IOException 



{
//java.util.Scanner scan=new java.util.Scanner(new File("mootube.in"));
 //PrintWriter out = new PrintWriter (new FileWriter("mootube.out"));
//java.util.Scanner scan=new java.util.Scanner(new File("lightson.in"));
//PrintWriter out = new PrintWriter (new FileWriter("lightson.out"));
    int n=scan.nextInt();
    int arr[]=new int[n];
    long sum=0;
    PriorityQueue<Long>pq=new PriorityQueue<Long>();
    for(int i=0;i<n;i++){
        long x=scan.nextLong();
        sum+=x;
        pq.add(-x);
    }

while(pq.size()>=2)
{
    long cur=(-pq.poll())+(-pq.poll());
    //out.println(cur);
    sum+=cur;
    pq.add(-cur);
}
out.println(sum);



out.close();
}
static class special implements Comparable<special>{
    int x;
    char id;
    special(int x,char id)
    {
        this.id=id;
       this.x=x;
    }
    public int compareTo(special o)
    {
        
        return x-o.x;
    }
   
}
 public static  long pow(long b, long e) {
            long r = 1;
            while (e > 0) {
                if (e % 2 == 1) r = r * b ;
                b = b * b;
                e >>= 1;
            }
            return r;
        }

private static void sort(long[] arr) {
        List<Long> list = new ArrayList<>();
        for (long object : arr) list.add(object);
        Collections.sort(list);
        for (int i = 0; i < list.size(); ++i) arr[i] = list.get(i);
    }
 public static class FastReader {
        BufferedReader br;
        StringTokenizer root;
        
 
        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
 
        String next() {
            while (root == null || !root.hasMoreTokens()) {
                try {
                    root = new StringTokenizer(br.readLine());
                } catch (Exception addd) {
                    addd.printStackTrace();
                }
            }
            return root.nextToken();
        }
 
        int nextInt() {
            return Integer.parseInt(next());
        }
 
        double nextDouble() {
            return Double.parseDouble(next());
        }
 
        long nextLong() {
            return Long.parseLong(next());
        }
 
        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (Exception addd) {
                addd.printStackTrace();
            }
            return str;
        }
         public int[] nextIntArray(int arraySize) {
            int array[] = new int[arraySize];
 
            for (int i = 0; i < arraySize; i++) {
                array[i] = nextInt();
            }
 
            return array;
        }
}
public static class Pair implements Comparable<Pair>{
         int x;
        int  y;
        int id;
        public Pair(){}
        public Pair(int x1, int y1,int id) {
            x=x1;
            y=y1;
            this.id=id;
        }
        public Pair(int x1, int y1) {
            x=x1;
            y=y1;
        
        }
        @Override
        public int hashCode() {
            return (int)(x + 31 * y);
        }
        public String toString() {
            return x + " " + y;
        }
        @Override
        public boolean equals(Object o){
            if (o == this) return true;
            if (o.getClass() != getClass()) return false;
            Pair t = (Pair)o;
            return t.x == x && t.y == y;
        }
        public  int compareTo(Pair o)
        {
            if(x==o.x)
                return y-o.y;
            return x-o.x;
        }
}

}







