#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  multiset<long long> ms;
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    ms.insert(x);
  }
  if (!(n & 1)) ms.insert(0);
  long long ans = 0;
  while (((long long)ms.size()) != 1) {
    long long sm = 0;
    for (long long i = 0; i < 3; i++) {
      sm += *ms.begin();
      ms.erase(ms.begin());
    }
    ans += sm;
    ms.insert(sm);
  }
  cout << ans << endl;
}
