#include <bits/stdc++.h>
using namespace std;
const int SIZ = int(2e5) + 2007;
int N;
priority_queue<long long, vector<long long>, greater<long long> > pq;
int main() {
  scanf("%d", &N);
  int c;
  for (int i = 1; i <= N; i++) {
    scanf("%d", &c);
    pq.push(c);
  }
  if ((N & 1) == 0) N++, pq.push(0);
  long long ans = 0;
  for (int i = N; i > 1; i -= 2) {
    long long n = 0;
    n += pq.top();
    pq.pop();
    n += pq.top();
    pq.pop();
    n += pq.top();
    pq.pop();
    ans += n;
    pq.push(n);
  }
  printf("%lld\n", ans);
}
