#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 5;
int n;
priority_queue<long long, vector<long long>, greater<long long> > q;
int main() {
  long long x;
  while (~scanf("%d", &n)) {
    while (!q.empty()) q.pop();
    for (int i = 0; i < n; ++i) {
      scanf("%lld", &x);
      q.push(x);
    }
    if ((n & 1) == 0) q.push(0);
    long long ans = 0;
    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;
}
