#include <bits/stdc++.h>
using namespace std;
int n;
long long a[200005];
int main(void) {
  scanf("%d", &n);
  priority_queue<long long, vector<long long>, greater<long long> > que;
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    que.push(a[i]);
  }
  long long ans = 0;
  while (que.size() > 1) {
    long long sum = 0;
    if (que.size() % 2 == 0) que.push(0LL);
    for (int i = 0; i < 3; i++) {
      if (que.size()) {
        sum += que.top();
        que.pop();
      }
    }
    ans += sum;
    que.push(sum);
  }
  printf("%lld\n", ans);
  return 0;
}
