#include <bits/stdc++.h>
using namespace std;
int n, a;
long long tot;
multiset<long long> ms;
void rem2() {
  long long x = *(ms.begin());
  ms.erase(ms.begin());
  x += *(ms.begin());
  ms.erase(ms.begin());
  tot += x;
  ms.insert(x);
}
void rem3() {
  long long x = *(ms.begin());
  ms.erase(ms.begin());
  x += *(ms.begin());
  ms.erase(ms.begin());
  x += *(ms.begin());
  ms.erase(ms.begin());
  tot += x;
  ms.insert(x);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a);
    ms.insert(a);
  }
  if (ms.size() % 2 == 0) rem2();
  while (ms.size() > 1) {
    rem3();
  }
  printf("%lld\n", tot);
  return 0;
}
