#include <bits/stdc++.h>
 
using namespace std;
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
using ll = long long;
/*
    g++ -std=c++11 test.cpp -o test.out && ./test.out
*/


void solve1(){
    int n, m, k; cin >> n >> m >> k;
    vector<string> grid;
    for(int i = 0; i < n; i++){
        string s; cin >> s;
        grid.push_back(s);
    }

    vector<int> rows;
    vector<int> columns;

    int total = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            if (grid[i][j] == '#')
                total++;
        }
    }

    int ans = 0;
    for(int i = 0; i < n; i++){
        int count = 0;
        for(int j = 0; j < m; j++){
            if (grid[i][j] == '#')
                count++;
        }
        if(total - count == k){
            cout << "Row: " << i << endl;
            ans++;
        }
    }

    for(int j = 0; j < m; j++){
        int count = 0;
        for(int i = 0; i < n; i++){
            if (grid[i][j] == '#')
                count++;
        }
        if(total - count == k){
            cout << "Col: " << j << endl;
            ans++;
        }
    }

    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            int r = i; int c = j;

            int count = 0;
            for(int k = 0; k < m; k++){
                if(grid[r][k] == '#')
                    count++;
            }
            for(int k = 0; k < n; k++){
                if(grid[k][c] == '#')
                    count++;
            }
            if(grid[r][c] == '#')
                count--;
            
            if(total - count == k){
                cout << r << " " << c << endl;
                ans++;
            }
        }
    }

    cout << ans << endl;

}
using ll = long long ;
void solve(){
    int n; cin >> n;
    vector<ll> a(n);

    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end(), greater<int>());
    if(n == 1){
        cout << 0 << endl;
        return;
    }
    if(n == 2){
        cout << a[0] << endl;
        return;
    }
    ll count = a[0];
    int idx = 1;
    for(int i = 2; i < n; i++){
        count += a[idx];
        i++;
        if(i < n){
            count += a[idx];
            idx++;
        }
    }

    cout << count;
}

int main()
{    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    solve();
    
    return 0;
}

Measured memory_bytes: 4792