#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

void solve() {
    int n;
    cin >> n;

    vector<ll> A(n);
    vector<ll> S(n);

    for (int i = 0; i < n; i++) {
        cin >> A[i];
    }

    sort(A.begin(), A.end());

    S[0] = A[0];
    for (int i = 1; i < n; i++) {
        S[i] = A[i] + S[i-1];
    }
   
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        ans += (S[n-1] - S[i]) - A[i] * (n - i - 1);
    }

    cout << ans << endl;

}

int main() {

    solve();

    return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define d long double

#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define dscf(n) scanf("%Lf",&n)
#define pri(n) printf("%d ",(int)n)
#define lpri(n) printf("%lld ",n)
#define dpri(n) printf("%Lf ",n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define dprin(n) printf("%Lf\n",n)

#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i,ini,n) for(ll i=ini;i<(int)n;i++)
#define all(x) x.begin(),x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define bitcount(n) __builtin_popcount(n)
#define tc   int tt; scf(tt); while(tt--)
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define PI 3.14159265358979323846264

const ll M =1e9+7;
const int N = 1e6+7;



int main()
{
    ll n;
    lscf(n);

    ll a[n+1];

    rep(i,1,n+1)
    lscf(a[i]);

    sort(a+1,a+n+1);

    ll sum=a[1];

    ll ans=0;

    rep(i,2,n+1)
    {
        ans+=((i-1)*a[i]-sum);
        sum+=a[i];
    }

    lpri(ans);
return 0;
}