#include <bits/stdc++.h>
using namespace std;
const int N = 200100;
const long long MOD = 998244353;
const double EBS = 1e-7;
int dX[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dY[] = {1, -1, 0, 0, 1, -1, -1, 1};
int n, x;
int main() {
  priority_queue<long long, vector<long long>, greater<long long> > pq;
  long long ans = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &x), pq.push(x);
  if (n == 1) return puts("0");
  if (n % 2 == 0) pq.push(0);
  while ((pq.size()) != 1) {
    int cnt = 3;
    long long am = 0;
    while (cnt--) am += pq.top(), pq.pop();
    ans += am;
    pq.push(am);
  }
  cout << ans;
  return 0;
}
