#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define all(x) (x).begin(),(x).end()
ll power(ll x , ll n,ll mod){
    if(n == 0) return 1ll;
    ll cur = power(x, n >> 1,mod);
    if(n & 1) return (cur % mod * cur % mod  * x) % mod ;
    return (cur % mod * cur % mod) % mod ;
}
const int maxx = 200005;
const int mod = 1000000007;
long a[maxx];
void solve()
{
    long n ; cin >> n;
    vector<ll> pre(n + 5),suf(n + 5);
    for(int i = 1; i <= n ; ++i) cin >> a[i];
    sort(a + 1 , a + 1 + n);
    for(int i = 1; i <= n ; ++i){
        pre[i] = pre[i - 1] + a[i];
    }
    for(int i = n ; i >= 1; --i){
        suf[i] = suf[i + 1] + a[i];
    }
    ll ans = 0;
    for(int i = 1; i <= n ; ++i){
        ans += abs((i - 1) * a[i] - pre[i - 1]) + abs((n - i) * a[i] - suf[i + 1]);
    }
    ans /= 2;
    cout << ans << '\n';
}
signed main()
{

    //freopen("t.inp","r",stdin);freopen("t.out","w",stdout);
    ios_base::sync_with_stdio(false);cin.tie(nullptr);
    solve();
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define agewari(a, b) ((ll)a + ((ll)b - 1)) / b
const int MOD = 1000000007;
const long long INF = 1LL << 60;

int main()
{
    ll n;
    cin>>n;
    vector<ll> A(n);
    rep(i,n)cin>>A[i];
    sort(A.begin(),A.end());

    ll ans=0;
    rep(i,n){
        ans+=A[i]*i;
        ans-=A[i]*(n-1-i);
    }

    cout<<ans<<endl;
}