#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define ll long long
#define pp pair<ll, ll> 
#define lb lower_bound
#define ub upper_bound
#define mk make_pair
#define pb push_back
#define llp(i, x, n) for (ll i = x; i < n; i++)
#define fr first
#define ss second
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define ull unsigned long long ll
#define mod 1000000007
using namespace std;
int main()
{
	fast;
    ll n;
    cin>>n;
    ll a[n];
    llp(i,0,n)
    cin>>a[i];
    sort(a,a+n);
    ll b[n];
    b[n-1]=a[n-1];
    for(int i=n-2;i>=0;i--)
    {
    	b[i]=a[i]+b[i+1];
    }
    ll sum=0;
    
    for(ll i=0;i<n-1;i++)
    {
    	sum+=b[i+1]-(n-i-1)*a[i];
    }
    cout<<sum<<endl;
}
#include <algorithm>
#include <iostream>
#include <vector>

int main() {
  size_t n_num;
  std::cin >> n_num;

  std::vector<int64_t> nums(n_num);
  for (auto &ele : nums) {
    std::cin >> ele;
  }

  std::sort(nums.begin(), nums.end());

  int64_t ans = 0;
  int64_t delta = 0;
  for (size_t i = 0; i < n_num; i++) {
    delta += nums[i] - nums[0];
  }
  ans += delta;
  for (size_t i = 1; i < n_num; i++) {
    delta -= (nums[i] - nums[i - 1]) * (n_num - i);
    ans += delta;
  }
  std::cout << ans << std::endl;
}
