#include <bits/stdc++.h>
using namespace std;
long long n, i, rs, j;
vector<long long> ball;
vector<long long>::iterator pos;
int main() {
  scanf("%lld", &n);
  for (i = 0; i < n; i++) scanf("%lld", &j), ball.push_back(j);
  sort(ball.begin(), ball.end());
  rs = 0;
  i = 0;
  if (n % 2 == 0) {
    j = ball[0] + ball[1];
    pos = lower_bound(ball.begin() + 2, ball.end(), j);
    ball.insert(pos, j);
    rs += j;
    i = 2;
  }
  for (; i < n - 1; i += 3) {
    j = ball[i] + ball[i + 1] + ball[i + 2];
    pos = lower_bound(ball.begin() + i + 3, ball.end(), j);
    ball.insert(pos, j);
    rs += j;
    n++;
  }
  printf("%lld", rs);
  return 0;
}
