#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
struct disjoint_sets {
  vi parent, rank;
  disjoint_sets(int n) : parent(n), rank(n) {
    for (int i = 0; i < n; ++i) parent[i] = i;
  }
  int find(int x) {
    if (parent[x] != x) parent[x] = find(parent[x]);
    return parent[x];
  }
  void merge(int x, int y) {
    x = find(x), y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y])
      parent[x] = y;
    else if (rank[x] > rank[y])
      parent[y] = x;
    else {
      parent[y] = x;
      ++rank[x];
    }
  }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  multiset<ll> vals;
  for (int i = 0; i < n; ++i) {
    ll a;
    cin >> a;
    vals.insert(a);
  }
  ll ans = 0;
  while (vals.size() > 1) {
    if (vals.size() & 1) {
      auto it = vals.begin();
      ll a = *it++;
      ll b = *it++;
      ll c = *it++;
      vals.erase(vals.begin(), it);
      ans += a + b + c;
      vals.insert(a + b + c);
    } else {
      vals.insert(0L);
      continue;
    }
  }
  cout << ans << endl;
  return 0;
}
