#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  priority_queue<long long, vector<long long>, greater<long long>> q;
  if (n % 2 == 0) q.push(0);
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    q.push(x);
  }
  long long ans = 0;
  while (q.size() > 1) {
    long long cur = 0;
    for (int i = 0; i < 3; ++i) {
      cur += q.top();
      q.pop();
    }
    q.push(cur);
    ans += cur;
  }
  cout << ans << '\n';
}
