#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
template <class T>
int getbit(T x, int pos) {
  return (x >> (pos - 1)) & 1;
}
template <class T>
void turn_on(T &x, int pos) {
  x = x | ((T)1 << (pos - 1));
}
template <class T>
void turn_off(T &x, int pos) {
  x = x & ~((T)1 << (pos - 1));
}
template <class T>
T sqr(T a) {
  return a * a;
}
int n, a[200002];
priority_queue<long long, vector<long long>, greater<long long> > pq;
long long solve() {
  if (n == 1) return 0;
  if (n == 2) return a[1] + a[2];
  for (int i = 1; i <= n; ++i) pq.push(a[i]);
  long long res = 0;
  if (n % 2 == 0) {
    long long __x1 = pq.top();
    pq.pop();
    long long x2 = pq.top();
    pq.pop();
    pq.push(__x1 + x2);
    res = __x1 + x2;
  }
  while (pq.size() > 1) {
    long long __x1 = pq.top();
    pq.pop();
    long long x2 = pq.top();
    pq.pop();
    long long x3 = pq.top();
    pq.pop();
    pq.push(__x1 + x2 + x3);
    res += __x1 + x2 + x3;
  }
  return res;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  cout << solve();
}
