///*    ***Bismillahir Rahmanir Rahim***   */
#include<bits/stdc++.h>
using namespace std;
typedef		long long       ll;
typedef         long double      dl;
typedef     unsigned long long  ull;
#define		pb              push_back
#define		PB              pop_back
#define		nn              "\n"
#define     O_O             ios_base::sync_with_stdio(false); cin.tie(NULL)
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define		ss              ' '
#define	       MEM(a,b)         memset(a,(b),sizeof(a))
#define	       CLR(p)           memset(p,0,sizeof(p))
#define rep(i,b) for(ll i=0;i<(b);i++)
#define rep1(i,b) for(int i=1;i<=(b);i++)
//#define rep(s,e)         for(i=s;i<e;i+=1)
//#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep2(i,a,b,c) for(int i=(a);i!=(b);i+=(c))
#define         arrsize(a)      (sizeof(a)/sizeof(a[0]))
//#define       arrsize(a)      (sizeof(a)/sizeof(*a))
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
#define		pi              acos(-1.0)
#define	       ff               first
#define	       sc              second
#define     print(v)        for(ll i:v) cout<<i<<ss
typedef        pair <int, int>   pii;
typedef       pair <ll, ll>      pll;
typedef      vector< pair <ll, ll> >      vpll;
typedef		vector<ll>      vll;
typedef		map<string,ll>      msl;
typedef		map<ll,ll>      mll;
#define yes cout << "YES\n"
#define no cout<<"NO\n"
bool comp(pair<ll,ll> a,pair<ll,ll> b)
{
    if(a.first != b.first) return a.first > b.first;
    else
    return a.second > b.second;
}
//ll minelementindex = min_element(v.begin(),v.end()) - v.begin();
//ll minelement = *min_element(v.begin(), v.end());
//ll maxelementindex = max_element(v.begin(),v.end()) - v.begin();
//ll maxelement = *max_element(v.begin(), v.end());
//memset(ar,-1,sizeof(ar));
//#define sort(x) sort(x.begin(), x.end())
//sort(a,a+n,greater<ll>())
//for (auto it = mp.begin(); it != mp.end(); ++it){}
// string x(w.size(),'1');
#define MAX 1000005
#define precision(a) fixed << setprecision(a)

#define mod 1000000007
ll ar[MAX];

// Function to calculate sum of absolute difference
// of all pairs in array
// arr[]  --> array of elements
ll sumPairs(ll arr[],ll n)
{
    // final result
    ll sum = 0;
    for (ll i=n-1; i>=0; i--)
        sum += i*arr[i] - (n-1-i)*arr[i];
    return sum;
}

// Driver program to run the case



int main()
{
 //O_O ;
 ll n;cin>>n;
 for(ll i=0;i<n;i++) cin>>ar[i];
 sort(ar,ar+n);

     cout << sumPairs(ar, n);


    return 0;
}








//https://codeforces.com/contest/1371/problem/D korte hbe
//https://codeforces.com/contest/1256/problem/B implementation pari nai
/*****************  ALHAMDULILLAH  *****************/


#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <string>
#include <list>
#include <cassert>
#include <numeric>
#include <cstdint>
#include <queue>
#include <deque>
 
using ll = long long;
using ld = long double;
using namespace std;
using Graph = vector<vector<int>>; 

// typedef pair<int,int> P;
#define teisu 1000000007
#define MAX_WIDTH 60
#define MAX_HEIGHT 60
#define INF 1e9

// int N;
// string S;
// map<int,int> cnt;
// map<char,vector<int>> keep_index;
// ll X,Y,A,B;
// ll ans = 0;
// ll dfs(ll strength,ll keikenti){
//     if(strength >= Y) return 0;

//     ans = max(ans,keikenti);
//     cout << strength << endl;
//     // cout << ans << endl;

//     dfs(strength*A,keikenti+1);

//     dfs(strength+B,keikenti+1);

//     return 0;
// }


ll N;
vector<ll> A;
int main(){
    cin >> N;
    for(int i=0;i<N;i++) {
        int input;
        cin >> input;
        A.push_back(input);
    }

    sort(A.begin(),A.end(),greater<ll>());
    ll ans = 0;
    for(int i=0;i<N;i++){
        ans += (A[i]*(N-1-i)) - (A[i]*i);
    }
    cout << ans << endl;

    return 0;
}                            