#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
bool Max(T1& a, T2 b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T1, typename T2>
bool Min(T1& a, T2 b) {
  return a > b ? a = b, 1 : 0;
}
const int N = 100021, inf = 1e9;
void solve() {
  int n, v;
  cin >> n;
  priority_queue<long long, vector<long long>, greater<long long>> q;
  if (n % 2 == 0) q.push(0);
  while (n--) {
    cin >> v;
    q.push(v);
  }
  long long ans = 0;
  while (q.size() > 1) {
    long long s = 0;
    for (int it = 0; it < (3); ++it) {
      s += q.top();
      q.pop();
    }
    ans += s;
    q.push(s);
  }
  cout << ans << '\n';
}
void init() {}
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.setf(ios::fixed);
  cout.precision(20);
  init();
  int TC = 1;
  for (int TI = 1; TI <= (TC); ++TI) {
    solve();
  }
  return 0;
}
