#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  scanf("%d", &N);
  priority_queue<long long, vector<long long>, greater<long long> > q;
  for (int i = 0; i < N; i++) {
    int x;
    scanf("%d", &x);
    q.push(x);
  }
  if (N % 2 == 0) q.push(0);
  long long res = 0;
  while (q.size() > 1) {
    long long x = q.top();
    q.pop();
    x += q.top();
    q.pop();
    x += q.top();
    q.pop();
    res += x;
    q.push(x);
  }
  printf("%lld\n", res);
  return 0;
}
