#include <bits/stdc++.h>
inline void in(int &MAGNUS) { scanf("%d", &MAGNUS); }
inline void out(int MAGNUS) { printf("%d\n", MAGNUS); }
inline void in(int &MAGNUS, int &CLAR) { scanf("%d%d", &MAGNUS, &CLAR); }
inline void out(int MAGNUS, int CLAR) { printf("%d %d\n", MAGNUS, CLAR); }
inline void inl(long long &LIV) { scanf("%lld", &LIV); }
inline void inl(long long &LIV, long long &MART) {
  scanf("%lld%lld", &LIV, &MART);
}
inline void outl(long long LIV) { printf("%lld\n", LIV); }
inline void outl(long long LIV, long long MART) {
  printf("%lld %lld\n", LIV, MART);
}
using namespace std;
int main() {
  int N;
  in(N);
  priority_queue<long long, vector<long long>, greater<long long> > q;
  for (int i = 1; i <= N; i++) {
    long long x;
    inl(x);
    q.push(x);
  }
  long long ans = 0;
  while (q.size() > 1) {
    if (q.size() % 2 == 0) {
      q.push(0LL);
    } else {
      long long cur = 0;
      for (int i = 1; i <= 3; i++) {
        cur += q.top();
        q.pop();
      }
      ans += cur;
      q.push(cur);
    }
  }
  outl(ans);
  return 0;
}
