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