#include <bits/stdc++.h> //Header Files

#define ll long long int
#define mod 1000000007
#define endl "\n"

using namespace std;

template <class T>
void out(int t, T ans)
{
    cout << "Case #" << t << ": " << ans << endl;
}

template <class T>
void out(int t, T ans[])
{
    cout << "Case #" << t << ": ";
    for (T val : ans)
        cout << val << " ";
    cout << endl;
}

template <class T>
void out(int t, vector<T> &ans)
{
    cout << "Case #" << t << ": ";
    for (T val : ans)
        cout << val << " ";
    cout << endl;
}

void runTest(int o)
{
    // Start coding here ...
    int n;
    cin >> n;

    ll a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];

    sort(a, a + n, greater<ll>());

    ll pre[n];
    pre[n - 1] = a[n - 1];
    for (int i = n - 2; i >= 0; i--)
        pre[i] = pre[i + 1] + a[i];

    ll sum = 0;
    for (int i = 0; i < n - 1; i++)
    {
        sum += abs(pre[i + 1] - (a[i] * (n - i - 1)));
    }

    cout << sum << endl;
}

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int t = 1;
    // cin >> t;

    for (int i = 0; i < t; i++)
        runTest(i + 1);

    return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  ll n; cin >> n;
  vector<ll> v(n);
  for (int i = 0; i < n; i++)
    cin >> v[i];
  ll ans=0;
  sort(v.begin(), v.end());
  for (ll i = 0; i < n; i++) {
    ans += (2ll*i - n + 1ll) * v[i];
  }
  cout << ans;
  return 0;
}
