#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, s = 0, j, i, d;
  cin >> n;
  long long a[n];
  for (i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  i = 0, j = n, s = 0;
  while (i < (n / 2)) {
    d = abs(i + 1 - j);
    s = s + (a[i] + a[j - 1]) * d;
    i++;
    j--;
  }
  cout << s << "\n";
  return 0;
}
