#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  priority_queue<long long, vector<long long>, greater<long long>> pq;
  for (long long i = 0; i < n; i++) {
    long long first;
    cin >> first;
    pq.push(first);
  }
  if (n % 2 == 0) pq.push(0);
  long long ans = 0;
  while (pq.size() > 2) {
    long long first = pq.top();
    pq.pop();
    long long second = pq.top();
    pq.pop();
    long long third = pq.top();
    pq.pop();
    ans += first + second + third;
    pq.push(first + second + third);
  }
  cout << ans;
}
