#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 1;
long long w[maxn];
bool comp(int a, int b) { return w[a] > w[b]; }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  int A[n];
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    sum += A[i];
  }
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  if (n <= 3) {
    cout << sum << endl;
    return 0;
  }
  sort(A, A + n);
  priority_queue<int, vector<int>, function<bool(int, int)>> q(comp);
  for (int i = 0; i < n; i++) {
    w[i] = A[i];
    q.push(i);
  }
  int nxt = n - 1;
  if (n % 2 == 0) {
    int a = q.top();
    q.pop();
    int b = q.top();
    q.pop();
    w[++nxt] = w[a] + w[b];
    q.push(nxt);
  }
  while (q.size() != 1) {
    int a = q.top();
    q.pop();
    int b = q.top();
    q.pop();
    int c = q.top();
    q.pop();
    w[++nxt] = w[a] + w[b] + w[c];
    q.push(nxt);
  }
  long long ans = 0;
  for (int i = nxt; i >= n; i--) {
    ans += w[i];
  }
  cout << ans << endl;
  return 0;
}
