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