#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
bool cmp(int a,int b)
{
    return a>b;
}
int main()
{
    int n;
    scanf("%d",&n);
    ll a[200100];
    for(int i=1;i<=n;i++)
        scanf("%lld",&a[i]);
    sort(a+1,a+n+1,cmp);
    ll sum[200100];
    sum[1]=a[1];
    for(int i=2;i<=n;i++)
        sum[i]=sum[i-1]+a[i];
    ll ans=0;
    for(int i=1;i<n;i++)
        ans+=sum[n-i]-(sum[n]-sum[i]);
    printf("%lld",ans);
    return 0;
}
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
using namespace std;
using ll = long long;

ll Solve(int n, vector<ll> a)
{
  sort(a.begin(), a.end());
  ll sum = 0;
  for (ll i = n - 1; 0 <= i; --i)
  {
    sum += (i * a[i]) - (n - 1 - i) * a[i];
  }
  return sum;
}

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,0,n-1) cin >> a[i];
  cout << Solve(n, a) << endl;
  return 0;
}
