#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
long long int dx[] = {0, 0, 1, -1};
long long int dy[] = {1, -1, 0, -1};
long long int m, k, n, a[200005], sm = 0, vis[200000] = {0};
multiset<long long int> st, st2;
string s1 = "one", s2 = "zero", s, ch = "";
vector<long long int> v[200005];
vector<pair<long long int, long long int> > vv;
vector<pair<long double, long long int> > vvA, vvB;
vector<pair<long long int, pair<long long int, long long int> > > vvv;
priority_queue<long long int> pq;
map<long long int, long long int> cost;
long long int xa, xb, xc, ya, yb, yc, xres;
long double dist(long long int x1, long long int y1, long long int x2,
                 long long int y2) {
  long double res = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  return res;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long int i = 0, x, y, j = 0, z = 0, q, nb0 = 0, nb = 0, nbmax = 0,
                nbinf = 0, nb2 = 0, mm = 5e8, idx = 0, ok = 0, l, r,
                negatif = 0, positif = 0, l1, r1;
  multiset<long long int>::iterator it, it1, it2;
  char c;
  cin >> n;
  nb = 0;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    nb += a[i];
    st.insert(a[i]);
  }
  if (n % 2 == 0) st.insert(0);
  if (n == 1) return cout << "0", 0;
  if (n <= 3) return cout << nb, 0;
  long long int res = 0;
  while (st.size() >= 3) {
    k = 0;
    long long int cur = 0;
    for (it = st.begin(); it != st.end() && k < 3; it++) {
      a[k] = (*it);
      k++;
      cur += (*it);
    }
    res += cur;
    for (i = 0; i < 3; i++) {
      st.erase(st.find(a[i]));
    }
    st.insert(cur);
  }
  cout << res;
  return 0;
}
