#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFF = 0x3f3f3f3f3f3f3f3fll;
const int MAX = 2e5 + 10;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
template <typename T>
inline T abs(T a) {
  return a > 0 ? a : -a;
}
template <class T>
inline void read(T& num) {
  bool start = false, neg = false;
  char c;
  num = 0;
  while ((c = getchar()) != EOF) {
    if (c == '-')
      start = neg = true;
    else if (c >= '0' && c <= '9') {
      start = true;
      num = num * 10 + c - '0';
    } else if (start)
      break;
  }
  if (neg) num = -num;
}
inline long long powMM(long long a, long long b, long long M) {
  long long ret = 1;
  a %= M;
  while (b) {
    if (b & 1) ret = ret * a % M;
    b >>= 1;
    a = a * a % M;
  }
  return ret;
}
void open() { freopen("out.txt", "w", stdout); }
int n, ge, st;
long long a[MAX], an;
priority_queue<long long> re;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]);
  sort(a + 1, a + 1 + n);
  st = 1;
  if (n % 2 == 0) {
    an = a[1] + a[2];
    a[2] += a[1];
    st = 2;
  }
  for (int i = st; i <= n; i++) re.push(-a[i]);
  while (re.size() > 1) {
    long long tem = re.top();
    re.pop();
    long long tem2 = re.top();
    re.pop();
    long long tem3 = re.top();
    re.pop();
    an -= tem + tem2 + tem3;
    re.push(tem + tem2 + tem3);
  }
  printf("%I64d\n", an);
}
