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

void Main()
{
    int n;
    cin >> n;
    vector<long> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    vector<long> sa(n+1);
    for (int i = 0; i < n; i++)
    {
        sa[i+1] = sa[i] + a[i];
    }
    long ans = 0;
    for (int i = 0; i < n; i++)
    {
        auto nm = lower_bound(a.begin(), a.end(), a[i]) - a.begin();
        ans += a[i]*nm - sa[nm];
        ans += (sa[n] - sa[nm]) - a[i]*(n-nm);
    }
    ans /= 2;
    cout << ans << endl;
}

int main(int argc, char **argv)
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    Main();
    return 0;
}

#include <iostream>
#include <iomanip>
#include <assert.h>
#include <vector>
#include <string>
#include <cstring>
#include <sstream>

#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef std::pair<long long, long long> Pll;
typedef std::vector<int> vi;
typedef std::vector<long long> vl;
typedef std::vector<std::string> vs;
typedef std::vector<std::pair<long long, long long>> vpll;
typedef std::vector<std::vector<ll>> vvl;
template<class T> using V = std::vector<T>;
template<class T> using VV = std::vector<std::vector<T>>;

const long double PI = (acos(-1));
const long long MOD = 1000000007;

static const int MAX_INT = std::numeric_limits<int>::max(); // 2147483647 = 2^31-1
static const ll  MAX_LL  = std::numeric_limits<long long>::max();
static const int INF     = (1 << 29);   // cf) INT_MAX   = 2147483647 = 2^31-1
static const ll  INFLL   = (1ll << 61); // cf) LLONG_MAX = 9223372036854775807 = 2^63 - 1

#define rep(i,n) REP(i,0,n)
#define REP(i,x,n) for(ll i=(ll)(x);i<(ll)(n);++i)
#define rrep(i,n) RREP(i,0,n)
#define RREP(i,x,n) for(ll i=(ll)(n)-1ll;i>=(ll)(x);--i)
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
#define SUM(x) accumulate(ALL(x), 0ll)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

// change min/max
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

void Main() {
    ll a, b, c, d; cin >> a >> b >> c >> d;

    ll cnt = b - c;
    cout << cnt << endl;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout << std::fixed << std::setprecision(15);
    Main();

    double tmp;
    cin >> tmp;

    return 0;
}
