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