#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll INF = 1LL << 60;
const int MOD = (int)1e9 + 7;

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));

    ll ans = 0;
    int l = 0, r = n - 1;
    while (r - l >= 1)
    {
        ans += (a[r] - a[l]) * (n - 1);
        n -= 2;
        r--;
        l++;
    }

    cout << ans << '\n';
    return 0;
}

#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#ifdef ENABLE_DEBUG
#include <debug.h>
#else
#define DEBUG(...) do {} while (0)
#endif

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ull = unsigned long long;
using lll = __int128;
using ulll = unsigned __int128;

template<typename T, size_t N> using ar = array<T, N>;

template<typename T, typename Cmp = less<T>>
using iset = tree<T, null_type, Cmp, rb_tree_tag,
		  tree_order_statistics_node_update, allocator<T>>;

#define REPSI(name, start, stop, step) for (ll name = start; name < (ll)stop; name += step)
#define REPS(name, start, stop) REPSI(name, start, stop, 1)
#define REP(name, stop) REPS(name, 0, stop)

#define RREPSI(name, start, stop, step) for (ll name = stop-1; name >= (ll)start; name -= step)
#define RREPS(name, start, stop) RREPSI(name, start, stop, 1)
#define RREP(name, stop) RREPS(name, 0, stop)

#define cin fastIO
#define cout fastIO

struct FastIO {
  static const int IBUF_SZ = 2e8, OBUF_SZ = 2e8;
  char IBUF[IBUF_SZ], OBUF[OBUF_SZ];
  int IBUF_I = 0, OBUF_I = 0;

  FastIO() { fread(IBUF, 1, sizeof(IBUF), stdin); }
  ~FastIO() { OBUF[OBUF_I++] = 0; fputs(OBUF, stdout); }
  
  FastIO &operator>>(char &c) { c = IBUF[IBUF_I++]; return *this; }
  FastIO &operator<<(char c) { OBUF[OBUF_I++] = c; return *this; }

  template<typename Int> FastIO &operator>>(Int &x) {
    x = 0;
    bool neg=false;
    while (IBUF[IBUF_I] < '0' || IBUF[IBUF_I] > '9')
      if (IBUF[++IBUF_I] == '-') neg=true;
    while (IBUF[IBUF_I] >= '0' && IBUF[IBUF_I] <= '9')
      x = 10*x + IBUF[IBUF_I++]-'0';
    if (neg) x = -x;
    return *this;
  }
  template<typename Int> FastIO &operator<<(Int x) {
    static char BUF[40];
    if (x < 0) OBUF[OBUF_I++] = '-', x = -x;
    int i = 40;
    do { BUF[--i] = x%10 + '0'; } while (x /= 10);
    while (i < 40) OBUF[OBUF_I++] = BUF[i++];
    return *this;
  }

  template<typename T> FastIO &operator>>(vector<T> &vec) {
    REP(i, vec.size()) (*this) >> vec[i];
    return *this;
  }
};
FastIO fastIO;

template<typename T> void cins(T &first) { cin >> first; }
template<typename T, typename... Ts> void cins(T &first, T &second, Ts&... rest) {
  cin >> first;
  cins(second, rest...);
}

#define GET(type, ...) type __VA_ARGS__; cins(__VA_ARGS__)
#define GETI(...) GET(int, __VA_ARGS__)
#define GETLL(...) GET(ll, __VA_ARGS__)
#define GETS(...) GET(string, __VA_ARGS__)
#define GETD(...) GET(double, __VA_ARGS__)
#define GETC(...) GET(char, __VA_ARGS__)

template<typename T> istream &operator>>(istream &is, vector<T> &a) { for (T &v : a) is >> v; return is; }
template<typename T, size_t N> istream &operator>>(istream &is, ar<T, N> &a) {
  REP(i, N) is >> a[i];
  return is;
}

int main() {
  GETLL(n);
  vector<ll> a(n); cin >> a;

  sort(a.begin(), a.end());

  ll ans = 0;
  ll cur = 0;

  REP(i, n) cur += a[i]-a[0];
  ans += cur;

  REPS(i, 1, n) {
    ll smaller = i-1;
    ll larger = n-i-1;

    ll diff = a[i]-a[i-1];
    
    cur += diff*smaller;
    cur -= diff*larger;

    ans += cur;
  }

  cout << ans/2 << '\n';
}
