#include <bits/stdc++.h>
using namespace std;
priority_queue<long long> q;
long long ans, n, i, x, y, z, now, a[500001];
int main() {
  scanf("%lld", &n);
  for (i = 1; i <= n; i++) scanf("%lld", &a[i]);
  for (i = 1; i <= n; i++) q.push(-a[i]);
  if (n % 2 == 0) q.push(0);
  while (q.size() > 1) {
    x = -q.top();
    q.pop();
    y = -q.top();
    q.pop();
    z = -q.top();
    q.pop();
    now = x + y + z;
    ans += now;
    q.push(-now);
  }
  printf("%lld", ans);
}
