#include <bits/stdc++.h>
using namespace std;
int main() {
  long long num;
  cin >> num;
  priority_queue<long long, vector<long long>, greater<long long>> q;
  for (int k = 0; k < num; k++) {
    long long x;
    cin >> x;
    q.push(x);
  }
  if (num % 2 == 0) q.push(0);
  long long ans = 0;
  while (q.size() > 1) {
    long long add = 0;
    for (int k = 0; k < 3; k++) {
      add += q.top();
      q.pop();
    }
    ans += add;
    q.push(add);
  }
  cout << ans << endl;
}
