#include <bits/stdc++.h>
using namespace std;
int N;
multiset<signed long long> M;
void solve() {
  int i, j, k, l, r, x, y;
  string s;
  cin >> N;
  for (i = 0; i < (N); i++) {
    cin >> x;
    M.insert(x);
  }
  signed long long ret = 1LL << 60;
  for (i = 0; i < (2); i++) {
    multiset<signed long long> M2 = M;
    signed long long tot = 0;
    if (i == 1 && M2.size() >= 2) {
      signed long long a = *M2.begin();
      M2.erase(M2.begin());
      a += *M2.begin();
      M2.erase(M2.begin());
      M2.insert(a);
      tot += a;
    }
    while (M2.size() > 2) {
      signed long long a = *M2.begin();
      M2.erase(M2.begin());
      a += *M2.begin();
      M2.erase(M2.begin());
      a += *M2.begin();
      M2.erase(M2.begin());
      tot += a;
      M2.insert(a);
    }
    if (M2.size() == 2) {
      tot += *M2.begin();
      M2.erase(M2.begin());
      tot += *M2.begin();
    }
    ret = min(ret, tot);
  }
  cout << ret << endl;
}
int main(int argc, char** argv) {
  string s;
  int i;
  if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);
  for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s += '\n';
  for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);
  cout.tie(0);
  solve();
  return 0;
}
