#include <bits/stdc++.h>
using namespace std;
priority_queue<long long, vector<long long>, greater<long long> > q;
long long a, sum, p = 0;
int main() {
  int n, i;
  scanf("%d", &n);
  for (i = 0; i < n; ++i) {
    scanf("%lld", &a);
    q.push(a);
  }
  if (!(n % 2)) q.push(0);
  while (q.size() > 2) {
    sum = q.top();
    q.pop();
    sum += q.top();
    q.pop();
    sum += q.top();
    q.pop();
    p += sum;
    q.push(sum);
  }
  printf("%lld", p);
  return 0;
}
