#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n ;
    cin >> n;
    vector<ll> v(n);
    for(ll i=0; i<n; i++)
        cin >> v[i];
    sort(v.rbegin(),v.rend());
    ll suff[n+10];
    suff[n-1] = v[n-1];
    for(ll i=n-2; i>=0; i--)
    {
        suff[i] = suff[i+1] + v[i];
    }

    ll res = 0;
    for(ll i=0; i<n-1; i++)
    {
        res += v[i]*(n-i-1) - suff[i+1] ;
    }
    cout << res << endl;
}

#include<bits/stdc++.h>
#define ll long long int
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpii vector< pii >
#define vpll vector< pll >
#define mpii map<int,int>
#define mpll map<ll,ll>
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define s(v) v.size()
#define test ll t;cin>>t;while(t--)
#define vec vector<ll>
#define read0(v,n) for(int i=0;i<n;i++)cin>>v[i];
#define read1(v,n) for(int i=1;i<=n;i++)cin>>v[i];
#define trav(a,x) for (auto& a: x)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define cut(x) {cout<<x;return 0;}
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORB(i,a,b) for(int i=a;i>=b;i--)

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define f first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define nl '\n'
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
#define oset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
ll gcd(ll a, ll b)
{
	if (b==0)return a;
	return gcd(b, a % b);
}
ll lcm(ll a,ll b)
{
    return (a*b)/gcd(a,b);
}
ll bpow(ll a, ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%MOD;
		b/=2;
		a=(a*a)%MOD;
	}
	return ans;
}
bool octal(ll n)
{
    while(n>0)
    {
        ll p=n%8;
        if(p==7)return 1;
        n/=8;
    }
    return 0;
}
bool decimal(ll n)
{
    while(n>0)
    {
        ll p=n%10;
        if(p==7)return 1;
        n/=10;
    }
    return 0;
}
ll dp[200006];
int main()
{

	fast
	int n;
	cin>>n;
	vec v(n);read0(v,n);
	sort(all(v));
	ll sum=0;
	vec temp;
	FOR(i,1,s(v)-1)
	{
	    temp.pb(v[i]-v[i-1]);
	}
	ll m=n-1;
	dp[0]=temp[0];
	sum=dp[0];
	FOR(i,1,m-1)
	{
	    dp[i]=dp[i-1]+temp[i];
	    sum+=dp[i];
	}
	ll prev=0;
	ll k=sum;
	FOR(i,1,m-1)
	{
	   // cout<<sum<<' '<<prev<<nl;
	    prev+=(m-i+1)*temp[i-1];
	    sum+=k-prev;
	}
	cut(sum)


}
