#include <bits/stdc++.h>
using namespace std;
const int64_t MOD = 1e9 + 7;
const int64_t N = 1e6 + 5;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  priority_queue<int64_t> pq;
  int64_t ans = 0;
  int64_t n;
  cin >> n;
  int64_t x;
  for (int64_t i = 0; i < n; i++) {
    cin >> x;
    pq.push(-x);
  }
  if (n % 2 == 0) pq.push(0);
  while (pq.size() > 1) {
    int64_t balls = pq.top();
    pq.pop();
    balls += pq.top();
    pq.pop();
    if (!pq.empty()) {
      balls += pq.top();
      pq.pop();
    }
    ans += (-balls);
    pq.push(balls);
  }
  cout << ans;
  return 0;
}
