using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace debug
{
    class main
    {
        static void Main(string[] args)
        {
            //問題クラスを展開
            ProgramD a = new ProgramD();
            a.main();//実行する

        }

    }
    //ABC170
    class ProgramA
    {
        public void main()
        {
            //入力
            int n = int.Parse(Console.ReadLine());

            if(n < 1000)
            {
                Console.WriteLine(1000 - n);
            }
            else
            {
                int m = n / 1000 + 1;
                if (n % 1000 == 0)
                    Console.WriteLine(0);
                else
                    Console.WriteLine(m * 1000 - n);

            }

        }
    }

    class ProgramB
    {
        public void main()
        {
            //入力
            int n = int.Parse(Console.ReadLine());
            int[] ans = new int[4];

            for(int i = 0; i < n;i++)
            {
                string s = Console.ReadLine();
                if (s == "AC")
                    ans[0]++;
                else if (s == "WA")
                    ans[1]++;
                else if (s == "TLE")
                    ans[2]++;
                else
                    ans[3]++;
            }

            Console.WriteLine("AC x " + ans[0]);
            Console.WriteLine("WA x " + ans[1]);
            Console.WriteLine("TLE x " + ans[2]);
            Console.WriteLine("RE x " + ans[3]);

        }
    }

    class ProgramC
    {
        public void main()
        {

            //入力
            string[] s = Console.ReadLine().Split(' ');
            int h = int.Parse(s[0]);
            int w = int.Parse(s[1]);
            int k = int.Parse(s[2]);

            char[,] maze = new char[h, w];

            for(int i = 0;i < h;i++)
            {
                string t = Console.ReadLine();
                for (int j = 0; j < w; j++)
                    maze[i, j] = t[j];
            }
            int ans = 0;

            for(int i = 0;i < (1 << h);i++)
                for (int j = 0; j < (1 << w); j++)
                {
                    int count = 0;
                    for(int x = 0; x < h;x++)
                    {
                        if (((i >> x) & 1) == 1)
                            continue;

                        for(int y = 0;y < w;y++)
                        {
                            if (((j >> y) & 1) == 1)
                                continue;

                            if (maze[x, y] == '#')
                                count++;
                        }
                    }

                    if (count == k)
                        ans++;
                }

            Console.WriteLine(ans);



        }
    }

    class ProgramD
    {
        public void main()
        {

            //入力
            long n = long.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split(' ');
            long[] a = new long[n];


            for (int i = 0; i < n; i++)
                a[i] = long.Parse(s[i]);

            Array.Sort(a);

            long sum = 0;

            for (int i = 0; i < n -1; i++)
                sum += a[n - 1 - (i + 1)/2];

            
            Console.WriteLine(sum);
        }
    }

    class ProgramE
    {

        public void main()
        {
            //入力
            int n = int.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split(' ');
            long[] a = new long[n];

            for (int i = 0; i < n; i++)
                a[i] = long.Parse(s[i]);

            long sum = a[0] ^ a[1];

            for (int i = 2; i < n; i++)
                sum = sum ^ a[i];

            for (int i = 0; i < n; i++)
                Console.Write((sum ^ a[i]) + " ");


        }


    }

}






Measured memory_bytes: 46964