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

int main(){
    int N;
    cin >> N;
    long long S=0,ans=0;
    vector<long long> A(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
        S+=A[i];
    }
    sort(A.begin(),A.end());
    for(int i=0;i<N;i++){
        ans+=S-(N-i)*A[i];
        S-=A[i];
    }
    cout << ans << endl;
}
#include <bits/stdc++.h>
#include <numeric>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i, n) for (int i = (int)(n) - 1 ; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); i++)
#define ALL(v) (v).begin(), (v).end()
#define MIN(v) *min_element((v).begin(), (v).end())
#define MAX(v) *max_element((v).begin(), (v).end())
#define PF(p) (p).first
#define PS(p) (p).second
#define MF(p) (p)->first
#define MS(p) (p)->second
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define VL vector<long long>
#define VVL vector<vector<long long>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define VC vector<char>
#define VVC vector<vector<char>>
using namespace std;
using ll = long long;
const ll MOD = 1000000007LL;
//const ll MOD = 998244353LL;
int pmod(int x){int y=x%(int)MOD;return (y>=0)?y:y+(int)MOD;}
ll pmod(ll x){ll y=x%MOD;return (y>=0LL)?y:y+MOD;}
bool in(ll x, ll a, ll b){return (a<=x)&&(x<b);}
template<class T>bool chmin(T& a, T b){if(a>b){a=b;return true;}else return false;}
template<class T>bool chmax(T& a, T b){if(a<b){a=b;return true;}else return false;}

int main(){
    ll N;
    cin>>N;
    VL A(N);
    REP(i,N)cin>>A[i];
    sort(ALL(A));
    ll sum = 0;
    for(ll i=0LL;i<N;++i){
        sum += (2LL*i-N+1LL) * A[i];
    }
    cout << sum;
    return 0;
}