#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
priority_queue<long long, vector<long long>, greater<long long> > pq;
int main() {
  long long n;
  cin >> n;
  for (long long i = 0; i < n; ++i) {
    long long x;
    cin >> x;
    pq.push(x);
  }
  if (n % 2 == 0) pq.push(0);
  long long ans = 0;
  while (pq.size() > 1) {
    long long a = pq.top();
    pq.pop();
    long long b = pq.top();
    pq.pop();
    long long c = pq.top();
    pq.pop();
    ans += a + b + c;
    pq.push(a + b + c);
  }
  cout << ans;
}
