#include <bits/stdc++.h>
using namespace std;
int n, x;
long long ans;
priority_queue<long long, vector<long long>, greater<long long> > Q;
void work() {
  scanf("%d", &n);
  for (register int i = 1; i <= n; ++i) scanf("%d", &x), Q.push(x);
  if (n % 2 == 0) {
    long long x = Q.top();
    Q.pop();
    long long y = Q.top();
    Q.pop();
    Q.push(x + y), ans += x + y;
  }
  while (Q.size() >= 3) {
    long long x = Q.top();
    Q.pop();
    long long y = Q.top();
    Q.pop();
    long long z = Q.top();
    Q.pop();
    Q.push(x + y + z), ans += x + y + z;
  }
  printf("%lld\n", ans);
}
signed main() {
  int _ = 1;
  while (_--) {
    work();
  }
  return 0;
}
