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