#include <bits/stdc++.h>
using namespace std;
const int maxn = 200044;
int Con[maxn];
int n;
long long sum = 0;
long long solve(int cnt) {
  priority_queue<long long, vector<long long>, greater<long long> > q;
  for (int i = 0; i < (n); ++i) q.push(Con[i]);
  for (int i = 0; i < (cnt); ++i) q.push(0);
  long long ans = 0;
  while (q.size() > 1) {
    long long sum = 0;
    for (int i = 0; i < 3 && q.size(); ++i) {
      long long cur = q.top();
      q.pop();
      ans += cur, sum += cur;
    }
    q.push(sum);
  }
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < (n); ++i) scanf("%d", &Con[i]);
  long long ans = solve(n % 2 ^ 1);
  cout << ans << endl;
}
