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

void DBG() { cerr << endl; }
template <class Head, class... Tail>
void DBG(Head H, Tail... T) { cerr << ' ' << H; DBG(T...); }
#define dbg(...) cerr << "(" << (#__VA_ARGS__) << "):", DBG(__VA_ARGS__)

using ll = long long;
using ld = long double;

#define INF 0x3f3f3f3f
#define sqr(a) (a) * (a)
#define siz(a) int(a.size())
#define ints(a...) int a; read(a)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define trav(i, v) for (const auto i : v)
#define Fill(a, b) memset(a, b, sizeof(a))
#define rep(i, b, n) for (auto i = b; i < n; i++)
#define per(i, b, n) for (auto i = b; i >= n; i--)
#define unify(a) sort(all(a)), a.resize(unique(all(a)) - a.begin())

template <class T> using vec = vector<T>;
template <class... Args> inline void read(Args&... args) { ((cin >> args), ...); }
template <class... Args> inline void show(Args... args) { ((cout << args << " "), ...); }
template <class T1, class T2> inline bool ckmin(T1 &a, T2 b) { return a > b ? a = b, 1 : 0; }
template <class T1, class T2> inline bool ckmax(T1 &a, T2 b) { return a < b ? a = b, 1 : 0; }
template <class T> inline void operator>> (istream& in, vector<T>& v) { rep(i, 0, siz(v)) in >> v[i]; }
template <class T> inline void operator<< (ostream& out, const vector<T>& v) { rep(i, 0, siz(v)) out << v[i] << " \n"[i + 1 == siz(v)]; }

const int MOD = 1e9 + 7;
const ld PI = acos(-1);

void solve() {
    ints(n);
    vec<ll> a(n); read(a);
    sort(all(a));
    vec<ll> suf(n + 1);
    per(i, n - 1, 0)
        suf[i] = suf[i + 1] + a[i];
    ll res = 0;
    rep(i, 0, n - 1)
        res += abs((n - 1 - i) * a[i] - suf[i + 1]);
    cout << res;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
    // setw(), setfill()
    int _ = 1;
    // cin >> _;
    rep(i, 1, _ + 1) {
        // printf("Case %d: ", i);
        // Solution solve;
        solve();
    }
    return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORC(i,a,b,c) for(ll i=(a);i<(b);i+=(c))
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define ff first
#define ss second
#define dd long double
#define all(x) x.begin(),x.end()

bool decToOctal(int n)
{

    // array to store octal number
    int octalNum[100];

    // counter for octal number array
    int i = 0;
    while (n != 0) {

        // storing remainder in octal array
        octalNum[i] = n % 8;
        n = n / 8;
        i++;
    }

    // printing octal number array in reverse order
    for (int j = i - 1; j >= 0; j--){
        if(octalNum[j]==7){
            return false;
        }
    }
    return true;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    vector<ll> arr(n+1);
    arr[0]=-1e18;
    REP(i,n){
        cin>>arr[i+1];
    }
    sort(all(arr));
    vector<ll> pref(n+1,0);
    for(ll i=1;i<=n;i++){
        pref[i]=pref[i-1]+arr[i];
    }
    ll ans=0;
    for(ll i=1;i<=n;i++){
        ll x=(i-1)*arr[i];
        ll prex=pref[i-1];
        ll temp=abs(x-prex);
        ans+=temp;
    }
    cout<<ans<<endl;

}
