#include <bits/stdc++.h>
using namespace std;
int n;
long long x, t1, t2, t3;
priority_queue<long long, vector<long long>, greater<long long> > q;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%lld", &x), q.push(x);
  long long ans = 0;
  if (n % 2 == 0) {
    t1 = q.top();
    q.pop();
    t2 = q.top();
    q.pop();
    ans += t1 + t2;
    q.push(t1 + t2);
    n--;
  }
  for (int i = 1; i < n; i += 2) {
    t1 = q.top();
    q.pop();
    t2 = q.top();
    q.pop();
    t3 = q.top();
    q.pop();
    ans += t1 + t2 + t3;
    q.push(t1 + t2 + t3);
  }
  printf("%lld\n", ans);
  return 0;
}
