#include <bits/stdc++.h>
using namespace std;
int myRnd(int L, int R) {
  return abs(((rand() << 15) | rand())) % (R - L + 1) + L;
}
int main() {
  srand(time(NULL));
  priority_queue<long long, vector<long long>, greater<long long> > pq;
  int n;
  scanf("%d", &(n));
  ;
  for (int i = 1; (n) >= i; ++i) {
    long long a;
    scanf("%lld", &(a));
    ;
    pq.push(a);
  }
  if (n % 2 == 0) pq.push(0);
  long long ans = 0;
  while (((int)(pq).size()) != 1) {
    long long a = pq.top();
    pq.pop();
    long long b = pq.top();
    pq.pop();
    long long c = pq.top();
    pq.pop();
    pq.push(a + b + c);
    ans += (a + b + c);
  }
  printf("%lld\n", (ans)*1LL);
  ;
}
