#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 9;
const double PI = 4.0 * atan(1.0);
ll powmod(ll a, ll b, const ll MOD) {
  ll res = 1;
  a %= MOD;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % MOD;
    a = a * a % MOD;
  }
  return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll modInverse(ll n, const ll p) { return powmod(n, p - 2, p); }
ll f[200005];
ll kCn(ll k, ll n) {
  return (f[n] * modInverse((f[n - k] * f[k]) % MOD, MOD)) % MOD;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  ll n;
  cin >> n;
  ll ans = 0;
  vector<ll> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  for (ll i = 0; i < n / 2; ++i) {
    ans += (n - 1 - 2 * i) * (a[i] + a[n - i - 1]);
  }
  cout << ans;
  return 0;
}
