#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int n; cin >> n;
    vector<ll> v(n);
    ll vall = 0;
    REP(i,n) {
        cin >> v[i];
        vall += v[i];
    }
    sort(RALL(v));
    ll ans = 0;
    REP(i,n-1) {
        ll x = v[i] * (n-i-1);
        vall -= v[i];
        ans += x - vall;
    }

    cout << ans << '\n';


    return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#pragma region DEBUG
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef
tree<
  pair<int,int>,
  null_type,
  less<pair<int,int>>,
  rb_tree_tag,
  tree_order_statistics_node_update>
ordered_set;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#pragma endregion DEBUG
#define MOD 1000000007
#define MAX 500005
#define endl "\n"
vector <lli> fact(MAX,1);
vector <lli> invfact(MAX,1);
bool sev1(lli n){
    while(n > 0){
        if(n%10 == 7)
            return true;
        n /=10;
    }
    return false;
}
bool sev2(lli n){
    while(n > 0){
        if(n%8 == 7)
            return true;
        n /=8;
    }
    return false;
}
void solve(){
    lli n;
    cin>>n;
    vector <lli> arr(n);
    for(lli i = 0; i<n; i++){
        cin>>arr[i];        
    }
    sort(arr.begin(),arr.end());
    lli add = n-1, sub = 0;
    lli ans = 0;
    for(lli i = n-1; i>=0; i--){
        ans += arr[i]*add;
        ans -= arr[i]*sub;
        add--;
        sub++;
    }
    cout<<ans<<endl;
}
int main(){
    /* freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout); */
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   /*  for(lli i = 1; i<MAX-5; i++){
        fact[i] = i*fact[i-1]%MOD;
        invfact[i] = binpow(fact[i],MOD-2);
    } */
    lli t;
    t = 1;
   // cin>>t;
    while(t--)
        solve();
}