#include <bits/stdc++.h>
using namespace std;
inline void read1(int &num) {
  char in;
  bool IsN = false;
  in = getchar();
  while (in != '-' && (in < '0' || in > '9')) in = getchar();
  if (in == '-') {
    IsN = true;
    num = 0;
  } else
    num = in - '0';
  while (in = getchar(), in >= '0' && in <= '9') {
    num *= 10, num += in - '0';
  }
  if (IsN) num = -num;
}
inline void read2(int &a, int &b) {
  read1(a);
  read1(b);
}
inline void read3(int &a, int &b, int &c) {
  read1(a);
  read1(b);
  read1(c);
}
inline void read1(long long &num) {
  char in;
  bool IsN = false;
  in = getchar();
  while (in != '-' && (in < '0' || in > '9')) in = getchar();
  if (in == '-') {
    IsN = true;
    num = 0;
  } else
    num = in - '0';
  while (in = getchar(), in >= '0' && in <= '9') {
    num *= 10, num += in - '0';
  }
  if (IsN) num = -num;
}
inline void read2(long long &a, long long &b) {
  read1(a);
  read1(b);
}
inline void read3(long long &a, long long &b, long long &c) {
  read1(a);
  read1(b);
  read1(c);
}
inline void read1(double &num) {
  char in;
  double Dec = 0.1;
  bool IsN = false, IsD = false;
  in = getchar();
  while (in != '-' && in != '.' && (in < '0' || in > '9')) in = getchar();
  if (in == '-') {
    IsN = true;
    num = 0;
  } else if (in == '.') {
    IsD = true;
    num = 0;
  } else
    num = in - '0';
  if (!IsD) {
    while (in = getchar(), in >= '0' && in <= '9') {
      num *= 10;
      num += in - '0';
    }
  }
  if (in != '.') {
    if (IsN) num = -num;
    return;
  } else {
    while (in = getchar(), in >= '0' && in <= '9') {
      num += Dec * (in - '0');
      Dec *= 0.1;
    }
  }
  if (IsN) num = -num;
}
inline void read2(double &a, double &b) {
  read1(a);
  read1(b);
}
inline void read3(double &a, double &b, double &c) {
  read1(a);
  read1(b);
  read1(c);
}
int len;
priority_queue<long long, vector<long long>, greater<long long> > q;
int main() {
  scanf("%d", &len);
  int num;
  for (int i = 0; i < len; i++) {
    scanf("%lld", &num);
    q.push(num);
  }
  if ((len & 1) == 0) q.push(0);
  long long ans = 0;
  while (!q.empty()) {
    long long a = q.top();
    q.pop();
    if (q.empty()) {
      break;
    }
    long long b = q.top();
    q.pop();
    long long c = q.top();
    q.pop();
    a += b + c;
    ans += a;
    q.push(a);
  }
  printf("%lld\n", ans);
  return 0;
}
