#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
priority_queue<long long, vector<long long>, greater<long long> > qu;
int main() {
  int n;
  scanf("%d", &n);
  while (n--) {
    long long now;
    scanf("%lld", &now);
    qu.push(now);
  }
  if (qu.size() % 2 == 0) qu.push(0);
  long long ans = 0, a, b, c;
  while (qu.size() > 1) {
    a = qu.top();
    qu.pop();
    b = qu.top();
    qu.pop();
    c = qu.top();
    qu.pop();
    ans += a + b + c;
    qu.push(a + b + c);
  }
  printf("%lld", ans);
  return 0;
}
