#include <bits/stdc++.h>
using namespace std;
const long long N = 3e5 + 10;
long long n, a[N], ans;
priority_queue<long long> PQ;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    PQ.push(-a[i]);
  }
  if (n % 2 == 0) PQ.push(0);
  while (PQ.size() > 1) {
    long long cnt = 0;
    cnt += -PQ.top();
    PQ.pop();
    cnt += -PQ.top();
    PQ.pop();
    cnt += -PQ.top();
    PQ.pop();
    ans += cnt;
    PQ.push(-cnt);
  }
  cout << ans;
  return 0;
}
