#include <bits/stdc++.h>
using namespace std;
priority_queue<long long, vector<long long>, greater<long long> > pq;
int n;
long long solve() {
  long long sum = 0;
  if (n % 2 == 0) pq.push(0);
  long long a, b, c;
  while (pq.size() > 1) {
    a = pq.top();
    pq.pop();
    b = pq.top();
    pq.pop();
    c = pq.top();
    pq.pop();
    sum += a + b + c;
    pq.push(a + b + c);
  }
  return sum;
}
int main() {
  cin >> n;
  int val;
  for (int i = 0; i < n; i++) {
    scanf("%d", &val);
    pq.push((long long)val);
  }
  cout << solve() << endl;
  return 0;
}
