#include <bits/stdc++.h>
using namespace std;
set<long long> S;
map<long long, int> H;
const int maxn = 2e5 + 100;
int a[maxn], n;
long long x, y, z, ans;
void Insert(long long x) {
  if (H[x] == 0) S.insert(x);
  H[x]++;
}
void Erase(long long x) {
  H[x]--;
  if (H[x] == 0) S.erase(x);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) Insert(a[i]);
  int sz = n;
  if ((n & 1) == 0) {
    x = *S.begin();
    Erase(x);
    y = *S.begin();
    Erase(y);
    ans = x + y;
    Insert(x + y);
    sz--;
  }
  while (sz > 1) {
    x = *S.begin();
    Erase(x);
    y = *S.begin();
    Erase(y);
    z = *S.begin();
    Erase(z);
    ans += x + y + z;
    sz -= 2;
    Insert(x + y + z);
  }
  cout << ans << endl;
}
