#include <bits/stdc++.h>
using namespace std;
string itosm(long long x) {
  if (x == 0) return "0";
  string ans = "";
  while (x > 0) {
    ans += ((x % 10) + '0');
    x /= 10;
  }
  reverse(ans.begin(), ans.end());
  return ans;
}
long long stoim(string str) {
  long long ans = 0;
  long long k = 1;
  for (int i = str.length() - 1; i >= 0; i--) {
    ans += (str[i] - '0') * k;
    k *= 10;
  }
  return ans;
}
const long long infll = 1e18 + 3;
const int inf = 1009000999;
const double eps = 1e-7;
const int maxn = 1e6 + 77;
const int baseint = 1000200013;
const long long basell = 1e18 + 3;
const long double PI = acos(-1.0);
const long long mod = 1e9 + 7;
void solve() {
  int n;
  cin >> n;
  long long a;
  multiset<long long> s;
  for (int i = 0; i < n; i++) {
    cin >> a;
    s.insert(a);
  }
  if (!(n & 1)) s.insert(0);
  long long ans = 0;
  multiset<long long>::iterator it, it1;
  int sz = s.size();
  while (s.size() > 1) {
    if (s.size() >= 3) {
      long long sum = 0;
      it = s.begin();
      a = *it;
      sum += a;
      s.erase(it);
      it = s.begin();
      a = *it;
      sum += a;
      s.erase(it);
      it = s.begin();
      a = *it;
      sum += a;
      s.erase(it);
      ans += sum;
      s.insert(sum);
    } else {
      long long sum = 0;
      it = s.begin();
      a = *it;
      sum += a;
      s.erase(it);
      it = s.begin();
      a = *it;
      sum += a;
      s.erase(it);
      ans += sum;
      s.insert(sum);
    }
    sz = s.size();
  }
  cout << ans;
}
int main() {
  srand(time(0));
  ios_base::sync_with_stdio(0);
  ;
  solve();
  return 0;
}
