#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  while (scanf("%d", &n) == 1) {
    vector<long long> a;
    for (int i = 0; i < n; ++i) {
      long long tmp;
      scanf("%lld", &tmp);
      a.push_back(-tmp);
    }
    if (n == 1) {
      printf("0\n");
      continue;
    }
    make_heap(a.begin(), a.end());
    long long ans = 0;
    if (n % 2 == 0) {
      pop_heap(a.begin(), a.end());
      long long x = a.back();
      a.pop_back();
      pop_heap(a.begin(), a.end());
      a.back() += x, ans -= a.back();
      push_heap(a.begin(), a.end());
    }
    while (a.size() > 1) {
      pop_heap(a.begin(), a.end());
      long long x1 = a.back();
      a.pop_back();
      pop_heap(a.begin(), a.end());
      long long x2 = a.back();
      a.pop_back();
      pop_heap(a.begin(), a.end());
      a.back() += x1 + x2, ans -= a.back();
      push_heap(a.begin(), a.end());
    }
    printf("%lld\n", ans);
  }
  return 0;
}
